Announcement Announcement Module
No announcement yet.
URLs for Restful Webservices Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • URLs for Restful Webservices


    I have a REST service exposed using Spring Integration. I want to use same URL for GET and POST for calling different service methods using Service Activator.

    I am using Spring 3.1 and Spring Integration 2.1.0 RC1.

    But only 1 bean is getting initialized (Bean Name URL mapping Handler) as the gateway name is same. If I try to use different names then I need to change the URL mappings.

    Following is the configuration I am using. Please suggest.

    	<!-- GET Entity -->
    	<int:channel id="in"></int:channel>
    	<int:channel id="out"></int:channel>
    	<int-http:inbound-gateway request-channel="in" reply-channel="out" supported-methods="GET" name="/process/{entId}" id="id1" path="/process/{entId}"></int-http:inbound-gateway>
    	<int:service-activator input-channel="in" output-channel="out" expression="@service.getEntity(#requestParam.entId)"></int:service-activator>
    	<!-- DELETE Entity -->
    	<int:channel id="in2"></int:channel>
    	<int:channel id="out2"></int:channel>
    	<int-http:inbound-gateway request-channel="in2" reply-channel="out2" supported-methods="DELETE" name="/process/{entId}" id="id2" path="/process/{entId}"></int-http:inbound-gateway>
    	<int:service-activator input-channel="in2" output-channel="out2" expression="@service.delete(#requestParam.entId)"></int:service-activator>
    Log displayed when starting the servlet is

    INFO : org.springframework.web.servlet.handler.BeanNameUr lHandlerMapping - Mapped URL path [/process/{entId}] onto handler 'id2'
    INFO : org.springframework.web.servlet.handler.SimpleUrlH andlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.Resource HttpRequestHandler#0'
    Thanks in advance.

  • #2
    I think your config must be like this:
    HTML Code:
    <channel id="httpMethodRouter"/>
    <channel id="out"/>
    <http:inbound-gateway request-channel="httpMethodRouter" reply-channel="out" supported-methods="GET,DELETE"
    		  name="/process/{entId}" path="/process/{entId}" payload-expression="#pathVariables.entId"/>
    <router input-channel="httpMethodRouter" expression="headers.http_requestMethod">
    	<mapping value="GET" channel="in1"/>
    	<mapping value="DELETE" channel="in2"/>
    <channel id="in1"/>
    <service-activator input-channel="in1" output-channel="out" ref="service" method="getEntity"/>
    <channel id="in2"/>
    <service-activator input-channel="in2" output-channel="out"  ref="service" method="delete"/>
    1. You have only one entry-point with both suported http-methods. Or there may be more, as I understand on your CRUD sample.
    2. Now you don't need to copy/paste your gateway config. Principle DRY.
    3. Now there is some powerful component from pipelines & filters architecture - router. Look at him as a @Controller in the Spring MVC.
    4. And also you have only one output-channel.

    Perhaps someday we will implement some http-method-router as nested element for http inbound entry point...

    Nevertheless I don't like to have several components with the same name...

    if it isn't clear, please, write your questions.

    Good luck,
    Artem Bilan


    • #3
      Thanks a lot,

      it's magic. And even it will simplify our configuration.