List of usage examples for org.apache.commons.lang.builder ToStringBuilder reflectionToString
public static String reflectionToString(Object object)
Forwards to ReflectionToStringBuilder
.
From source file:org.candlepin.client.DefaultCandlepinClientFacade.java
/** * Gets the safe result./*from w w w .jav a2 s . c o m*/ * * @param <T> the generic type * @param response the response * @return the safe result */ private <T> T getSafeResult(ClientResponse<T> response) { switch (response.getResponseStatus().getFamily()) { case CLIENT_ERROR: Map<String, String> msg = response.getEntity(new GenericType<Map<String, String>>() { }); L.warn("Operation failure. Status = {}. Response from server: {}", ToStringBuilder.reflectionToString(response.getResponseStatus()), Utils.toStr(msg)); throw new ClientException(response.getResponseStatus(), msg.get(Constants.ERR_DISPLAY_MSG)); default: return response.getEntity(); } }
From source file:org.cauldron.einstein.ri.core.model.message.simple.SimpleMessage.java
@Post public String toString() { return ToStringBuilder.reflectionToString(this); }
From source file:org.cleverbus.core.common.asynch.TraceHeaderProcessor.java
private void setFromTraceHeader(Exchange exchange, Source traceHeaderElmSource, boolean headerInBody) throws JAXBException { // unmarshal/*from w ww. j a v a 2 s . c o m*/ Unmarshaller unmarshaller = jaxb2.createUnmarshaller(); if (!headerInBody) { // if there is trace header in the body then error events are thrown because there are other elements // in the body unmarshaller.setEventHandler(validationEventHandler); } TraceHeader traceHeader = unmarshaller.unmarshal(traceHeaderElmSource, TraceHeader.class).getValue(); if (traceHeader == null) { if (isMandatoryHeader()) { throw new ValidationIntegrationException(InternalErrorEnum.E105, "there is no trace header"); } } else { // validate header content TraceIdentifier traceId = traceHeader.getTraceIdentifier(); if (traceId == null) { if (isMandatoryHeader()) { throw new ValidationIntegrationException(InternalErrorEnum.E105, "there is no trace identifier"); } } else { if (traceId.getApplicationID() == null) { throw new ValidationIntegrationException(InternalErrorEnum.E105, "there is no application ID"); } else if (traceId.getCorrelationID() == null) { throw new ValidationIntegrationException(InternalErrorEnum.E105, "there is no correlation ID"); } else if (traceId.getTimestamp() == null) { throw new ValidationIntegrationException(InternalErrorEnum.E105, "there is no timestamp ID"); } validateTraceIdentifier(traceId); exchange.getIn().setHeader(TRACE_HEADER, traceHeader); Log.debug("traceHeader saved to exchange: " + ToStringBuilder.reflectionToString(traceId)); } } }
From source file:org.cleverbus.core.common.asynch.TraceHeaderProcessor.java
/** * Checks that {@link TraceIdentifier} contains values which are valid. * * @param traceId the {@link TraceIdentifier} * @throws ValidationIntegrationException *///from w w w . j a v a 2 s . c o m private void validateTraceIdentifier(TraceIdentifier traceId) { Assert.notNull(traceId, "the traceId must not be null"); // if not defined some implementation, the validation is skipped if (validatorList == null || validatorList.isEmpty()) { Log.debug("no traceIdentifier validator found"); return; } for (TraceIdentifierValidator validator : validatorList) { if (validator.isValid(traceId)) { Log.debug("the trace identifier '{0}' is allowed", ToStringBuilder.reflectionToString(traceId)); return; } } // trace identifier values was not found in any list of possible values throw new ValidationIntegrationException(InternalErrorEnum.E120, "the trace identifier '" + ToStringBuilder.reflectionToString(traceId, ToStringStyle.SHORT_PREFIX_STYLE) + "' is not allowed"); }
From source file:org.cloudfoundry.workers.stocks.GoogleFinanceStockSymbolLookupClient.java
private StockSymbolLookup convertJsonNodeInToSymbolLookup(JsonNode jsonNode) throws Throwable { Number id = jsonNode.get("id").getValueAsLong(); Double changeWhileOpen = jsonNode.get("c").getValueAsDouble(); String ticker = jsonNode.get("t").getValueAsText(); String exchange = jsonNode.get("e").getValueAsText(); Double highPrice = jsonNode.get("hi").getValueAsDouble(); Double lowPrice = jsonNode.get("l").getValueAsDouble(); Double lastValueWhileOpen = jsonNode.get("l").getValueAsDouble(); StockSymbolLookup lookup = new StockSymbolLookup(id, changeWhileOpen, ticker, exchange, highPrice, lowPrice, lastValueWhileOpen);/*from w ww .ja va 2s.c o m*/ logger.info("service: retrieved stock information: " + ToStringBuilder.reflectionToString(lookup)); return lookup; }
From source file:org.cloudfoundry.workers.stocks.integration.client.Main.java
public static void main(String args[]) throws Throwable { AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(); annotationConfigApplicationContext.getEnvironment().setActiveProfiles(isCloudFoundry() ? "cloud" : "local"); annotationConfigApplicationContext.scan(ClientConfiguration.class.getPackage().getName()); annotationConfigApplicationContext.refresh(); StockClientGateway clientGateway = annotationConfigApplicationContext.getBean(StockClientGateway.class); Logger log = Logger.getLogger(Main.class.getName()); String symbol = "VMW"; StockSymbolLookup lookup = clientGateway.lookup(symbol); log.info("client: retrieved stock information: " + ToStringBuilder.reflectionToString(lookup)); }
From source file:org.cloudfoundry.workers.stocks.YahooPipesQuotesApiStockSymbolLookupClient.java
public static void main(String[] args) throws Throwable { RestTemplate restTemplate = new RestTemplate(); YahooPipesQuotesApiStockSymbolLookupClient apiStockSymbolLookupClient = new YahooPipesQuotesApiStockSymbolLookupClient( restTemplate);/* ww w .j a v a 2 s.c o m*/ StockSymbolLookup lookup = apiStockSymbolLookupClient.lookupSymbol("VMW"); System.out.println(ToStringBuilder.reflectionToString(lookup)); }
From source file:org.codice.ddf.endpoints.rest.RestEndpointTest.java
@Test public void testAddDocumentPositiveCase() throws IngestException, SourceUnavailableException, URISyntaxException { CatalogFramework framework = givenCatalogFramework(SAMPLE_ID); HttpHeaders headers = createHeaders(Collections.singletonList(MediaType.APPLICATION_JSON)); RESTEndpoint rest = new RESTEndpoint(framework, attachmentParser, attributeRegistry); addMatchingService(rest, Collections.singletonList(getSimpleTransformer())); UriInfo info = givenUriInfo(SAMPLE_ID); Response response = rest.addDocument(headers, info, mock(HttpServletRequest.class), mock(MultipartBody.class), null, new ByteArrayInputStream("".getBytes())); LOGGER.debug(ToStringBuilder.reflectionToString(response)); assertThat(response.getStatus(), equalTo(201)); assertThat(response.getMetadata(), notNullValue()); assertThat(response.getMetadata().get(Metacard.ID).get(0).toString(), equalTo(SAMPLE_ID)); }
From source file:org.codice.ddf.endpoints.rest.RestEndpointTest.java
@Test @SuppressWarnings({ "unchecked" }) public void testAddDocumentWithAttributeOverrides() throws IOException, CatalogTransformerException, IngestException, SourceUnavailableException, URISyntaxException, InvalidSyntaxException { CatalogFramework framework = givenCatalogFramework(SAMPLE_ID); AttributeDescriptor descriptor = new AttributeDescriptorImpl("custom.attribute", true, true, false, false, BasicTypes.STRING_TYPE);/*from www. j a v a2 s. c o m*/ HttpHeaders headers = createHeaders(Collections.singletonList(MediaType.APPLICATION_JSON)); BundleContext bundleContext = mock(BundleContext.class); Collection<ServiceReference<InputTransformer>> serviceReferences = new ArrayList<>(); ServiceReference serviceReference = mock(ServiceReference.class); InputTransformer inputTransformer = mock(InputTransformer.class); when(inputTransformer.transform(any())).thenReturn(new MetacardImpl()); when(bundleContext.getService(serviceReference)).thenReturn(inputTransformer); serviceReferences.add(serviceReference); when(bundleContext.getServiceReferences(InputTransformer.class, "(id=xml)")).thenReturn(serviceReferences); when(attributeRegistry.lookup("custom.attribute")).thenReturn(Optional.of(descriptor)); RESTEndpoint rest = new RESTEndpoint(framework, attachmentParser, attributeRegistry) { @Override BundleContext getBundleContext() { return bundleContext; } }; UuidGenerator uuidGenerator = mock(UuidGenerator.class); when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString()); rest.setUuidGenerator(uuidGenerator); addMatchingService(rest, Collections.singletonList(getSimpleTransformer())); UriInfo info = givenUriInfo(SAMPLE_ID); List<Attachment> attachments = new ArrayList<>(); ContentDisposition contentDisposition = new ContentDisposition( "form-data; name=parse.resource; filename=C:\\DDF\\metacard.txt"); Attachment attachment = new Attachment("parse.resource", new ByteArrayInputStream("Some Text".getBytes()), contentDisposition); attachments.add(attachment); ContentDisposition contentDisposition2 = new ContentDisposition("form-data; name=custom.attribute; "); Attachment attachment2 = new Attachment(descriptor.getName(), new ByteArrayInputStream("CustomValue".getBytes()), contentDisposition2); attachments.add(attachment2); MultipartBody multipartBody = new MultipartBody(attachments); Response response = rest.addDocument(headers, info, mock(HttpServletRequest.class), multipartBody, null, new ByteArrayInputStream("".getBytes())); LOGGER.debug(ToStringBuilder.reflectionToString(response)); assertThat(response.getStatus(), equalTo(201)); ArgumentCaptor<CreateStorageRequest> captor = new ArgumentCaptor<>(); verify(framework, times(1)).create(captor.capture()); assertThat(captor.getValue().getContentItems().get(0).getMetacard().getMetacardType() .getAttributeDescriptor(descriptor.getName()), equalTo(descriptor)); }
From source file:org.codice.ddf.endpoints.rest.RestEndpointTest.java
@Test @SuppressWarnings({ "unchecked" }) public void testAddDocumentWithMetadataPositiveCase() throws IOException, CatalogTransformerException, IngestException, SourceUnavailableException, URISyntaxException, InvalidSyntaxException { CatalogFramework framework = givenCatalogFramework(SAMPLE_ID); HttpHeaders headers = createHeaders(Collections.singletonList(MediaType.APPLICATION_JSON)); BundleContext bundleContext = mock(BundleContext.class); Collection<ServiceReference<InputTransformer>> serviceReferences = new ArrayList<>(); ServiceReference serviceReference = mock(ServiceReference.class); InputTransformer inputTransformer = mock(InputTransformer.class); when(inputTransformer.transform(any())).thenReturn(new MetacardImpl()); when(bundleContext.getService(serviceReference)).thenReturn(inputTransformer); serviceReferences.add(serviceReference); when(bundleContext.getServiceReferences(InputTransformer.class, "(id=xml)")).thenReturn(serviceReferences); RESTEndpoint rest = new RESTEndpoint(framework, attachmentParser, attributeRegistry) { @Override//from ww w .ja v a 2 s . co m BundleContext getBundleContext() { return bundleContext; } }; UuidGenerator uuidGenerator = mock(UuidGenerator.class); when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString()); rest.setUuidGenerator(uuidGenerator); when(attributeRegistry.lookup(Core.METADATA)) .thenReturn(Optional.of(new CoreAttributes().getAttributeDescriptor(Core.METADATA))); addMatchingService(rest, Collections.singletonList(getSimpleTransformer())); UriInfo info = givenUriInfo(SAMPLE_ID); List<Attachment> attachments = new ArrayList<>(); ContentDisposition contentDisposition = new ContentDisposition( "form-data; name=parse.resource; filename=C:\\DDF\\metacard.txt"); Attachment attachment = new Attachment("parse.resource", new ByteArrayInputStream("Some Text".getBytes()), contentDisposition); attachments.add(attachment); ContentDisposition contentDisposition1 = new ContentDisposition( "form-data; name=parse.metadata; filename=C:\\DDF\\metacard.xml"); Attachment attachment1 = new Attachment("parse.metadata", new ByteArrayInputStream("Some Text Again".getBytes()), contentDisposition1); attachments.add(attachment1); ContentDisposition contentDisposition2 = new ContentDisposition( "form-data; name=metadata; filename=C:\\DDF\\metacard.xml"); Attachment attachment2 = new Attachment("metadata", new ByteArrayInputStream("<meta>beta</meta>".getBytes()), contentDisposition2); attachments.add(attachment2); MultipartBody multipartBody = new MultipartBody(attachments); Response response = rest.addDocument(headers, info, mock(HttpServletRequest.class), multipartBody, null, new ByteArrayInputStream("".getBytes())); LOGGER.debug(ToStringBuilder.reflectionToString(response)); assertThat(response.getStatus(), equalTo(201)); assertThat(response.getMetadata(), notNullValue()); assertThat(response.getMetadata().get(Metacard.ID).get(0).toString(), equalTo(SAMPLE_ID)); }