title: Spring Integration and Spring MVC: @Controller vs inbound-gateway with service-activator
body: <p>I want to find the best way to manage an inbound request with <strong>Spring Integration HTTP</strong> and <strong>Spring MVC</strong>.</p>
  
  <p>I have an <code>&lt;int-http:inbound-gateway&gt;</code> configured as follows:</p>
  
  <pre><code>&lt;!-- CHANNEL --&gt;
  &lt;int:channel id="requestChannel"&gt;
      &lt;int:dispatcher task-executor="executor"/&gt;
  &lt;/int:channel&gt;
  &lt;int:channel id="outputChannel" /&gt;
  
  &lt;!-- INBOUND GATEWAY --&gt;
  &lt;int-http:inbound-gateway id="gateway" request-channel="requestChannel"
                path="/service/**" 
                supported-methods="POST"
                reply-channel="outputChannel"
                header-mapper="headerMapper"&gt;
  &lt;/int-http:inbound-gateway&gt;
  
  &lt;!-- SERVICE ACTIVATOR --&gt;
  &lt;int:service-activator id="channelServiceActivator"
      ref="channelService"
      input-channel="requestChannel"
      output-channel="outputChannel"
      method="manage"/&gt;
  
  &lt;bean id="channelService"
      class="test.spring.data.rest.xml.channel.ChannelService"/&gt;
  </code></pre>
  
  <p>With this integration, every HTTP call made on the path URI: <code>/service/**</code> is handled in the <em>"<code>manage()</code>"</em> method of the <code>ChannelService</code> class.</p>
  
  <p>This is the <code>ChannelService</code> class:</p>
  
  <pre><code>public class ChannelService {
  
      public void manage(Message&lt;?&gt; message){
  
          // how to get the HttpServletRequest request here ???
      }
  
  }
  </code></pre>
  
  <p>It works: the <em>"manage()"</em> method is correctly executed and the message contains the right payload. 
  But there is a little issue: <strong>I don't have any reference to the HttpServletRequest received in input in that ServiceChannel</strong>.</p>
  
  <p>If I use a <code>@Controller</code> of Spring MVC, I can handle every request with the relative <code>@RequestMapping</code>.
  If I want to read the payload contained in the request, I have to read it from the inputStream of the HttpServletRequest. Anywhere, I have no chance to get the message passed in the channel:</p>
  
  <pre><code>@Controller
  @RequestMapping(value="/service")
  public class ServiceController {
  
      @RequestMapping(value="/**")
      public handle(HttpServletRequest request) throws Exception{
  
          // how to get the Message&lt;?&gt; message passed on the channel here ???
  
      }
  
  }
  </code></pre>
  
  <p><strong>If I use both</strong> (<code>@Controller</code> and <code>inbound-gateway</code>), <strong>the @Controller mapping wins over the inbound-gateway</strong>: there is no chance to handle a servlet path URI with an <code>inbound-gateway</code> if there is
  a <code>@Controller</code> that maps the same path URI.</p>
  
  <p>So, I want to understand if there is some way to have a <code>Message&lt;?&gt; message</code> in the @Controller, or the HttpServletRequest in the ServiceActivator, or another way to manage this scenario.</p>
  
  <p>Thanks in advance.</p>