@Test public void testEndpointUriResolver() { HttpMessageSender messageSender = new HttpMessageSender(); String requestUrl = "http://localhost:8088/test"; String responseBody = "<TestResponse><Message>Hello World!</Message></TestResponse>"; messageSender.setReplyMessageHandler(replyMessageHandler); messageSender.setRequestMethod(HttpMethod.GET); messageSender.setRequestUrl(requestUrl); Message<?> requestMessage = MessageBuilder.withPayload("<TestRequest><Message>Hello World!</Message></TestRequest>") .build(); EndpointUriResolver endpointUriResolver = EasyMock.createMock(EndpointUriResolver.class); messageSender.setEndpointUriResolver(endpointUriResolver); messageSender.setRestTemplate(restTemplate); reset(restTemplate, replyMessageHandler, endpointUriResolver); restTemplate.setErrorHandler(anyObject(ResponseErrorHandler.class)); expectLastCall().once(); expect(endpointUriResolver.resolveEndpointUri(requestMessage, "http://localhost:8088/test")) .andReturn("http://localhost:8081/new") .once(); expect( restTemplate.exchange( eq("http://localhost:8081/new"), eq(HttpMethod.GET), anyObject(HttpEntity.class), eq(String.class))) .andReturn(new ResponseEntity<String>(responseBody, HttpStatus.OK)) .once(); replyMessageHandler.onReplyMessage(anyObject(Message.class)); expectLastCall().once(); replay(restTemplate, replyMessageHandler, endpointUriResolver); messageSender.send(requestMessage); verify(restTemplate, replyMessageHandler, endpointUriResolver); }
/** * @see com.consol.citrus.message.MessageSender#send(org.springframework.integration.Message) * @throws CitrusRuntimeException */ public void send(Message<?> message) { String endpointUri; if (endpointUriResolver != null) { endpointUri = endpointUriResolver.resolveEndpointUri(message, getRequestUrl()); } else { endpointUri = getRequestUrl(); } log.info("Sending HTTP message to: '" + endpointUri + "'"); if (log.isDebugEnabled()) { log.debug("Message to be sent:\n" + message.getPayload().toString()); } HttpMethod method = requestMethod; if (message.getHeaders().containsKey(CitrusHttpMessageHeaders.HTTP_REQUEST_METHOD)) { method = HttpMethod.valueOf( (String) message.getHeaders().get(CitrusHttpMessageHeaders.HTTP_REQUEST_METHOD)); } HttpEntity<?> requestEntity = generateRequest(message, method); restTemplate.setErrorHandler(new InternalResponseErrorHandler(message)); ResponseEntity<?> response = restTemplate.exchange(endpointUri, method, requestEntity, String.class); log.info("HTTP message was successfully sent to endpoint: '" + endpointUri + "'"); informReplyMessageHandler( buildResponseMessage( response.getHeaders(), response.getBody() != null ? response.getBody() : "", response.getStatusCode()), message); }