Results 1 to 10 of 17

Thread: HttpRequestHandlingMessagingGateway Support for Multiple HTTP Methods/Same Endpoint

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    138

    Default HttpRequestHandlingMessagingGateway Support for Multiple HTTP Methods/Same Endpoint

    I have two different messaging configurations that are both kicked off by HttpRequestHandlingMessagingGateway via http:inbound-gateway. Both of them use the same value for the name of the gateway endpoint URL. However, one supports GET while the other supports PUT.

    I am running an integration test using RestTemplate as my client. When I make a restTemplate.getForObject call, I get a 405 Method Not Allowed error. If I change just one of the endpoints to be anything different, then it works.

    I was curious if HttpRequestHandlingMessagingGateway had been tested for this case or if I am doing something wrong.

    Any insight is appreciated.

    Thanks.

  2. #2
    Join Date
    Aug 2007
    Posts
    138

    Default

    Forgot to mention the two http:inbound-gateway configurations:

    Code:
    <http:inbound-gateway id="getInboundGateway"
                              request-channel="getRequestChannel"
                              reply-channel="getReplyChannel"
                              name="/{text}/categories"
                              supported-methods="GET"
                              message-converters="messageConverterList"/>
    and

    Code:
    <http:inbound-gateway id="putInboundGateway"
                              request-channel="putRequestChannel"
                              reply-channel="putReplyChannel"
                              name="/{text}/categories"
                              supported-methods="PUT"
                              message-converters="messageConverterList"
                              request-payload-type="com.myapp.UpdateRequest"/>
    Incidentally, I also tried setting supported-methods for both to "GET,PUT," but then I got

    Code:
    java.lang.ClassCastException: org.springframework.util.LinkedMultiValueMap cannot be cast to com.myapp.UpdateRequest
    Thanks.

  3. #3
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Actually, this issue has already been addressed. See - https://jira.springsource.org/browse/INT-1677
    If you try the latest snapshot you can now use 'path' attribute to specify the path and its variables (e.g., path="/gateway/fname/{f}/lname/{l}) and the 'id' has been re-factored to be xsd:string so it is just a name that would be used for mapping. So now you can simply have two different gateways with different names.

  4. #4
    Join Date
    Apr 2005
    Posts
    112

    Default

    What namespace configuration should we use to avail of the new feature. http://www.springframework.org/schema/integration/http http://www.springframework.org/schem...n-http-2.0.xsd or http://www.springframework.org/schema/integration/http http://www.springframework.org/schem...n-http-2.1.xsd.

    2.1 is complaining that it is not found. The new "path" element of http inbound gatewat does not exist in 2.0 xsd version

  5. #5
    Join Date
    Apr 2005
    Posts
    112

    Default

    Quote Originally Posted by oleg.zhurakousky View Post
    Actually, this issue has already been addressed. See - https://jira.springsource.org/browse/INT-1677
    If you try the latest snapshot you can now use 'path' attribute to specify the path and its variables (e.g., path="/gateway/fname/{f}/lname/{l}) and the 'id' has been re-factored to be xsd:string so it is just a name that would be used for mapping. So now you can simply have two different gateways with different names.
    Is the above configuration really working. The following is my configuration and I keep getting no mapping found error and the response errors out with HTTP status 404 Not Found. I am having hard time getting this to work. I would really appreciate if someone could throw some light into what might be the root cause.

    SI application Context snippet.

    Code:
    <int-http:inbound-gateway id="inboundCustomerRestfulPhotoRequestGateway"		
    		supported-methods="GET, POST" 
    		request-channel="customerRestfulPhotoRequest"
    		reply-channel="customerRestfulPhotoResponse"		
    		mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"		
    		view-name="/photo" 		
    		path="/services/cis/fname/{fname}/lname/{lname}/dln/{dln}/dob/{dob}/photo"
    		reply-timeout="50000" >
    		
    		<int-http:header name="fname" expression="#pathVariables.fname"/>
    		<int-http:header name="lname" expression="#pathVariables.lname"/>
    		<int-http:header name="dln" expression="#pathVariables.dln"/>
    		<int-http:header name="dob" expression="#pathVariables.dob"/>
    		
    	</int-http:inbound-gateway>
    
    
           <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    		<property name="order" value="1" />	
    		<property name="defaultContentType" value="application/xml"/>	
    		<property name="ignoreAcceptHeader" value="true" />
    		<property name="favorParameter" value="true"/>  
    		<property name="mediaTypes">
    			<map>
    				<entry key="json" value="application/json" />
    				<entry key="xml" value="application/xml" />				
    			</map>
    		</property>
    		<property name="defaultViews">
    			<list>
    				<bean
    					class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
    				<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
    					<constructor-arg ref="marshaller"/>					
    				</bean>				
    			</list>
    		</property>				
    	</bean>
    Server Log Snippet:

    Code:
    2011-11-14 17:29:40,987 DEBUG [org.springframework.security.access.vote.AffirmativeBased] - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@14bbd50, returned: 1
    2011-11-14 17:29:41,050 DEBUG [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] - Authorization successful
    2011-11-14 17:29:41,050 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'org.springframework.integration.internalMessagingAnnotationPostProcessor'
    2011-11-14 17:29:41,050 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'org.springframework.integration.config.IdGeneratorConfigurer#0'
    2011-11-14 17:29:41,050 DEBUG [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] - RunAsManager did not change Authentication object
    2011-11-14 17:29:41,050 DEBUG [org.springframework.security.web.FilterChainProxy] - /services/cis/fname/Rahul/lname/Bose/dln/1234567/dob/2011-10-11/photo reached end of additional filter chain; proceeding with original chain
    2011-11-14 17:29:41,097 DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'Destiny Customer Information Search Restful Web Service' processing POST request for [/cis-ws/services/cis/fname/Rahul/lname/Bose/dln/1234567/dob/2011-10-11/photo]
    2011-11-14 17:29:41,097 WARN [org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI [/cis-ws/services/cis/fname/Rahul/lname/Bose/dln/1234567/dob/2011-10-11/photo] in DispatcherServlet with name 'Destiny Customer Information Search Restful Web Service'
    2011-11-14 17:29:41,097 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] - The HttpSession is currently null, and the HttpSessionSecurityContextRepository is prohibited from creating an HttpSession (because the allowSessionCreation property is false) - SecurityContext thus not stored for next request
    2011-11-14 17:29:41,097 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Successfully completed request
    Thanks,
    Vigil

  6. #6
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    Vigil,

    Try just adding this one bean to your config:
    Code:
    <bean class="org.springframework.integration.http.inbound.UriPathHandlerMapping"/>
    That's the handler mapping implementation that is aware of inbound Spring Integration adapter's with "path" attributes.

  7. #7
    Join Date
    Apr 2005
    Posts
    112

    Default

    Thanks Mark. I added UriPathHandlerMapping to the SI application context. But still I get the same result. The below log snippet says that No mapping found for the request with URI /cis-ws/services/cis/fname/Rahul/lname/Bose/dln/1234567/dob/2011-10-11/photo. The first part of the URI is the context path which I do not want to map. For all other mappings, I have the URL mapped to /service/cis/..... Did I miss any other configuration?

    Code:
     WARN [org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI [/cis-ws/services/cis/fname/Rahul/lname/Bose/dln/1234567/dob/2011-10-11/photo] in DispatcherServlet with name 'Destiny Customer Information Search Restful Web Service'
    Regards,
    Vigil

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •