Example usage for org.springframework.integration.http.inbound HttpRequestHandlingController setExtractReplyPayload

List of usage examples for org.springframework.integration.http.inbound HttpRequestHandlingController setExtractReplyPayload

Introduction

In this page you can find the example usage for org.springframework.integration.http.inbound HttpRequestHandlingController setExtractReplyPayload.

Prototype

public void setExtractReplyPayload(boolean extractReplyPayload) 

Source Link

Document

Specify whether only the reply Message's payload should be passed in the response.

Usage

From source file:org.springframework.integration.http.inbound.HttpRequestHandlingControllerTests.java

@Test
public void requestReplyWithFullMessageInModel() throws Exception {
    DirectChannel requestChannel = new DirectChannel();
    AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
        @Override//from   w  w w  .ja  va2s  . com
        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());
}