HttpClient extends AbstractEndpoint implements Producer, ReplyConsumer { @Override public void send(Message message, TestContext context) { getEndpointConfiguration().getClientInterceptors() .stream() .filter(LoggingClientInterceptor.class::isInstance) .map(LoggingClientInterceptor.class::cast) .filter(interceptor -> !interceptor.hasMessageListeners()) .forEach(interceptor -> interceptor.setMessageListener(context.getMessageListeners())); HttpMessage httpMessage; if (message instanceof HttpMessage) { httpMessage = (HttpMessage) message; } else { httpMessage = new HttpMessage(message); } String correlationKeyName = getEndpointConfiguration().getCorrelator().getCorrelationKeyName(getName()); String correlationKey = getEndpointConfiguration().getCorrelator().getCorrelationKey(httpMessage); correlationManager.saveCorrelationKey(correlationKeyName, correlationKey, context); final String endpointUri = getEndpointUri(httpMessage); context.setVariable(MessageHeaders.MESSAGE_REPLY_TO + "_" + correlationKeyName, endpointUri); log.info("Sending HTTP message to: '" + endpointUri + "'"); if (log.isDebugEnabled()) { log.debug("Message to send:\n" + httpMessage.getPayload(String.class)); } HttpMethod method = getEndpointConfiguration().getRequestMethod(); if (httpMessage.getRequestMethod() != null) { method = httpMessage.getRequestMethod(); } HttpEntity<?> requestEntity = getEndpointConfiguration().getMessageConverter().convertOutbound(httpMessage, getEndpointConfiguration(), context); try { ResponseEntity<?> response; MediaType accept = Optional.ofNullable(httpMessage.getAccept()) .map(mediaType -> mediaType.split(",")) .map(mediaType -> { try { return MediaType.valueOf(mediaType[0]); } catch (InvalidMediaTypeException e) { log.warn(String.format("Failed to parse accept media type '%s' - using default media type '%s'", mediaType[0], MediaType.ALL_VALUE), e); return MediaType.ALL; } }) .orElse(MediaType.ALL); if (getEndpointConfiguration().getBinaryMediaTypes().stream().anyMatch(mediaType -> mediaType.includes(accept))) { response = getEndpointConfiguration().getRestTemplate().exchange(URI.create(endpointUri), method, requestEntity, byte[].class); } else { response = getEndpointConfiguration().getRestTemplate().exchange(URI.create(endpointUri), method, requestEntity, String.class); } log.info("HTTP message was sent to endpoint: '" + endpointUri + "'"); correlationManager.store(correlationKey, getEndpointConfiguration().getMessageConverter().convertInbound(response, getEndpointConfiguration(), context)); } catch (HttpErrorPropagatingException e) { log.info("Caught HTTP rest client exception: " + e.getMessage()); log.info("Propagating HTTP rest client exception according to error handling strategy"); Message responseMessage = getEndpointConfiguration().getMessageConverter().convertInbound( new ResponseEntity<>(e.getResponseBodyAsString(), e.getResponseHeaders(), e.getStatusCode()), getEndpointConfiguration(), context); correlationManager.store(correlationKey, responseMessage); } } HttpClient();  HttpClient(HttpEndpointConfiguration endpointConfiguration); @Override HttpEndpointConfiguration getEndpointConfiguration(); @Override void send(Message message, TestContext context); @Override Message receive(TestContext context); @Override Message receive(String selector, TestContext context); @Override Message receive(TestContext context, long timeout); @Override Message receive(String selector, TestContext context, long timeout); @Override Producer createProducer(); @Override SelectiveConsumer createConsumer(); void setCorrelationManager(CorrelationManager<Message> correlationManager);  }
@Test public void testErrorResponseExceptionStrategy() { HttpEndpointConfiguration endpointConfiguration = new HttpEndpointConfiguration(); HttpClient httpClient = new HttpClient(endpointConfiguration); String requestUrl = "http: endpointConfiguration.setRequestMethod(HttpMethod.POST); endpointConfiguration.setRequestUrl(requestUrl); endpointConfiguration.setErrorHandlingStrategy(ErrorHandlingStrategy.THROWS_EXCEPTION); Message requestMessage = new DefaultMessage(requestBody); endpointConfiguration.setRestTemplate(restTemplate); doThrow(new HttpClientErrorException(HttpStatus.FORBIDDEN)).when(restTemplate).exchange(eq(URI.create(requestUrl)), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)); try { httpClient.send(requestMessage, context); Assert.fail("Missing exception due to http error status code"); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getMessage(), "403 FORBIDDEN"); verify(restTemplate).setInterceptors(anyList()); } }