Announcement Announcement Module
Collapse
No announcement yet.
Optional path parameters in http:inbound-gateway Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Optional path parameters in http:inbound-gateway

    Hello,

    I have created the following inbound-gateway

    <http:inbound-gateway
    id="theInboundGateway"
    request-channel="inboundChannel"
    reply-channel="outboundChannel"
    path="/email/{email}/number/{number}"
    supported-methods="GET" >
    <http:header name="email" expression="#pathVariables.email" />
    <http:header name="number" expression="#pathVariables.number" />
    </http:inbound-gateway>
    which lets users store e-mails and numbers in the application, eg, http:mysite.com/email/[email protected]/number/123

    When users forget the second parameter, they get an ugly HTTP 500 message stating that the pattern was not matched

    Pattern "/email/{email}/number/{number}" is not a match for "/email/[email protected]"

    Is there a way to make the parameters optional, like you can do with the @RequestParam annotation?

    @RequestParam(value="somvalue",required=false)
    Is it a good idea to deal with missing parameters and return Messages whose payload contains error messages, in the Gateway Handler class?

    Many thanks.

    Philroc

  • #2
    Hi!

    Philroc... Actually I suggest you study more about Request Mapping: http://static.springsource.org/sprin...requestmapping
    Spring MVC provides a strategy in the person of Controller, where you can map several methods under one context.
    From other side Spring Integration is component (endpoint) - oriented framework. So, you can map only one endpoint on one context (path).
    I suggest you to try to introduce another <http:inbound-gateway/> for 'path' /email/{email} and let us know how it works.

    Take care,
    Artem

    Comment


    • #3
      Hi Cleric,

      I am familiar with Request Mapping and Controllers as I have developed a few Spring MVC applications before.

      In MVC, you can specify whether @RequestParams are optional or not. In Integration, it appears that you can't.

      I have already tried duplicating my inbound-gateways, thus

      <bean id="inboundGatewayPath0" class="org.springframework.integration.http.inboun d.UriPathHandlerMapping" />

      <http:inbound-gateway
      id="theInboundGateway0"
      request-channel="inboundChannel"
      reply-channel="outboundChannel"
      path="/email/{email}/number/{number}/password/{password}"
      supported-methods="GET" >
      <http:header name="email" expression="#pathVariables.email" />
      <http:header name="number" expression="#pathVariables.number" />
      <http:header name="password" expression="#pathVariables.password" />
      </http:inbound-gateway>


      <bean id="inboundGatewayPath1" class="org.springframework.integration.http.inboun d.UriPathHandlerMapping" />

      <http:inbound-gateway
      id="theInboundGateway1"
      request-channel="inboundChannel"
      reply-channel="outboundChannel"
      path="/email/{email}/number/{number}"
      supported-methods="GET" >
      <http:header name="email" expression="#pathVariables.email" />
      <http:header name="number" expression="#pathVariables.number" />
      </http:inbound-gateway>

      but to no avail because Spring can't find the servlet named theInboundGateway which is declared in my web.xml file

      <servlet-class>org.springframework.web.context.support.Http RequestHandlerServlet</servlet-class>

      <init-param>
      <param-name>contextConfigLocation</param-name>

      </init-param>
      <load-on-startup>1</load-on-startup>
      </servlet>

      <servlet-mapping>
      <servlet-name>theInboundGateway</servlet-name>
      <url-pattern>/</url-pattern>
      </servlet-mapping>

      Here's the error message I get:

      2013-04-17 17:26:12.573:WARN:/HTTPInboundAdapter:unavailable
      org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'theInboundGateway' is defined

      Am I supposed to create several servlets, one for each inbound-gateway?

      Comment


      • #4
        <servlet-class>org.springframework.web.context.support.Http RequestHandlerServlet</servlet-class>
        No, you have to:
        1. configure DispatcherServlet
        2. Have only one UriPathHandlerMapping bean
        3. understand, that @RequestParams is about parameter from request
        4. understand, that @PathVariable is a part of request URI, not part of query.

        https://github.com/SpringSource/spri...ter/basic/http

        Comment

        Working...
        X