Announcement Announcement Module
No announcement yet.
Rest Webservice using Spring Integration HTTP inbound gateway Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rest Webservice using Spring Integration HTTP inbound gateway


    I am trying to expose a rest webservice using HTTP inbound gateway. I am not able to access the "retailer" path variable in the service activator.

    I am using Spring 3.0.6 and Spring integration 2.0.5 RELEASE.

    Please help, I tried googling but I am not able to find any suitable sample which will give me this pathvariable access.

    I have created following things.
    1. Inbound Channel
    2. Outbound Channel
    3. Inbound Gateway
    4. Service Activator

    Following is the configuration I have created.


    <web-app xmlns:xsi="" xmlns="" xmlns:web="" xsi:schemaLocation="" version="2.5">
    	<bean name="auditLogGateway" class=""></bean>
    	<!-- findAll Log -->
    	<int:channel id="findAllLogsInboundChannel" />
    	<int-http:inbound-gateway request-channel="findAllLogsInboundChannel" name="/findLogs/{retailer}/{product}"  mapped-request-headers="Accept-Charset:utf-8" supported-methods="GET" reply-channel="findAllLogsTransformedChannel"/>
    	<int:service-activator expression="@auditLogGateway.fetchAllLogs(#pathVariables.retailer)" id="findLogs" input-channel="findAllLogsInboundChannel" output-channel="findAllLogsOutboundChannel" >
    	<int:channel id="findAllLogsOutboundChannel"></int:channel>
    	<int:object-to-json-transformer input-channel="findAllLogsOutboundChannel" output-channel="findAllLogsTransformedChannel"></int:object-to-json-transformer>
    	<int:channel id="findAllLogsTransformedChannel"></int:channel>
    	public Message<List> fetchAllLogs(String retailer){
    		Message<List> retMessage = new GenericMessage<List>(new ArrayList());
    		return retMessage;

  • #2
    The support for path variables in a Spring Integration HTTP *inbound* adapter is actually new in version 2.1 (which is approaching RC1 very soon). The outbound adapters supported *setting* path vars in 2.0.x, but to grab values from the inbound URI, you will need to use 2.1.

    Here's what you can do in 2.1:

    1. use "path" instead of "name" as an attribute on the adapter and rely on the same path var syntax that you have already.
    2. add a "payload-expression" attribute OR 1 or more <header/> subelements with "expression" attributes themselves
    3. within the expressions, grab any path var values as such:

    Hope that helps.


    • #3
      Thanks Mark,

      This helped a lot. I am trying the same example with 2.1, I will come back with some good news.


      Amit Solankurkar


      • #4
        Hi Mark,

        Thanks a lot!!

        I have changed the libraries to 2.1.0.M3 and it is working. I am setting the pathVariables in the header and getting them from header in service activator.

        Following is the configuration changed, posting for other's use.


        	<bean name="controller" class=""></bean>
        	<int:channel id="inCh"></int:channel>
        	<int:channel id="outCh"></int:channel>
        	<int-http:inbound-gateway request-channel="inCh" reply-channel="outCh" name="/findlogs/{retailer}/{product}" path="/findlogs/{retailer}/{product}" mapped-request-headers="accept-charset:utf-8">
        		<int-http:header name="retailer" expression="#pathVariables.retailer"/>
        	<int:service-activator input-channel="inCh" output-channel="outCh" ref="controller" method="process">
        In service activator retailer value can be taken from the header.

        One small help, not on priority,

        how to pass this param as a payload expression. I tried changing the payload-expression of the inbound gateway in many ways but not successful.


        • #5
          Are you saying you tried payload-expression="#pathVariables.retailer"?

          That should work, but maybe you need to ensure that the request-payload-type is configured.


          • #6
            Hi Mark,

            I tried payload-expression="#pathVariables.retailer" and it is working fine, as I have a input message type if String.

            public String process(<Message<String> retailer){
            System.out.println(retailer); -- This is printing the retailer value correctly.

            but if I want to use multiple pathvariables then I am planning to use a custom request payload to which I can assign the values. Is there any way to do it?

            Thanks again for the prompt response.