use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class DefaultSplitterTests method correlationIdCopiedFromMessageId.
@Test
public void correlationIdCopiedFromMessageId() {
Message<String> message = MessageBuilder.withPayload("test").build();
DirectChannel inputChannel = new DirectChannel();
QueueChannel outputChannel = new QueueChannel(1);
DefaultMessageSplitter splitter = new DefaultMessageSplitter();
splitter.setOutputChannel(outputChannel);
EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, splitter);
endpoint.start();
assertTrue(inputChannel.send(message));
Message<?> reply = outputChannel.receive(0);
assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class HttpRequestHandlingControllerTests method requestReplyWithCustomReplyKey.
@Test
public void requestReplyWithCustomReplyKey() throws Exception {
DirectChannel requestChannel = new DirectChannel();
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return requestMessage.getPayload().toString().toUpperCase();
}
};
requestChannel.subscribe(handler);
HttpRequestHandlingController controller = new HttpRequestHandlingController(true);
controller.setBeanFactory(mock(BeanFactory.class));
controller.setRequestChannel(requestChannel);
controller.setViewName("foo");
controller.setReplyKey("myReply");
controller.afterPropertiesSet();
controller.start();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContent("howdy".getBytes());
// request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
// Instead do:
request.addHeader("Content-Type", "text/plain");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName());
assertEquals(1, modelAndView.getModel().size());
assertNull(modelAndView.getModel().get("reply"));
Object reply = modelAndView.getModel().get("myReply");
assertEquals("HOWDY", reply);
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class HttpRequestHandlingControllerTests method requestReplyViewExpressionView.
@Test
public void requestReplyViewExpressionView() throws Exception {
final View view = mock(View.class);
DirectChannel requestChannel = new DirectChannel();
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Message<String> handleRequestMessage(Message<?> requestMessage) {
return MessageBuilder.withPayload("foo").setHeader("bar", view).build();
}
};
requestChannel.subscribe(handler);
HttpRequestHandlingController controller = new HttpRequestHandlingController(true);
controller.setBeanFactory(mock(BeanFactory.class));
controller.setRequestChannel(requestChannel);
Expression viewExpression = new SpelExpressionParser().parseExpression("headers['bar']");
controller.setViewExpression(viewExpression);
controller.afterPropertiesSet();
controller.start();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContent("hello".getBytes());
request.setContentType("text/plain");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);
assertSame(view, modelAndView.getView());
assertEquals(1, modelAndView.getModel().size());
Object reply = modelAndView.getModel().get("reply");
assertNotNull(reply);
assertEquals("foo", reply);
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class HttpRequestHandlingControllerTests method requestReply.
@Test
public void requestReply() throws Exception {
DirectChannel requestChannel = new DirectChannel();
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return requestMessage.getPayload().toString().toUpperCase();
}
};
requestChannel.subscribe(handler);
HttpRequestHandlingController controller = new HttpRequestHandlingController(true);
controller.setBeanFactory(mock(BeanFactory.class));
controller.setRequestChannel(requestChannel);
controller.setViewName("foo");
controller.afterPropertiesSet();
controller.start();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
// request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
// Instead do:
request.addHeader("Content-Type", "text/plain");
// For Spring 3.0.7.RELEASE the Content must be set,
request.setContent("hello".getBytes());
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName());
assertEquals(1, modelAndView.getModel().size());
Object reply = modelAndView.getModel().get("reply");
assertNotNull(reply);
assertEquals("HELLO", reply);
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class HttpRequestHandlingControllerTests method requestReplyWithFullMessageInModel.
@Test
public void requestReplyWithFullMessageInModel() throws Exception {
DirectChannel requestChannel = new DirectChannel();
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
return requestMessage.getPayload().toString().toUpperCase();
}
};
requestChannel.subscribe(handler);
HttpRequestHandlingController controller = new HttpRequestHandlingController(true);
controller.setBeanFactory(mock(BeanFactory.class));
controller.setRequestChannel(requestChannel);
controller.setViewName("foo");
controller.setExtractReplyPayload(false);
controller.afterPropertiesSet();
controller.start();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
request.setContent("abc".getBytes());
// request.setContentType("text/plain"); //Works in Spring 3.1.2.RELEASE but NOT in 3.0.7.RELEASE
// Instead do:
request.addHeader("Content-Type", "text/plain");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(request, response);
assertEquals("foo", modelAndView.getViewName());
assertEquals(1, modelAndView.getModel().size());
Object reply = modelAndView.getModel().get("reply");
assertNotNull(reply);
assertTrue(reply instanceof Message<?>);
assertEquals("ABC", ((Message<?>) reply).getPayload());
}
Aggregations