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

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

Introduction

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

Prototype

public void setReplyKey(String replyKey) 

Source Link

Document

Specify the key to be used when adding the reply Message or payload to the core map (will be payload only unless the value of HttpRequestHandlingController#setExtractReplyPayload(boolean) is <code>false</code>).

Usage

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

@Test
public void requestReplyWithCustomReplyKey() throws Exception {
    DirectChannel requestChannel = new DirectChannel();
    AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
        @Override/*from   w  ww  . jav  a2  s .  c om*/
        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);
}