Announcement Announcement Module
Collapse
No announcement yet.
Question regarding HTTP Response Header Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question regarding HTTP Response Header

    Hi,

    I have a spring integration piece sitting between front and a backend rest services to do the message transform, as defined as below:

    Code:
    <http:inbound-gateway id="request01"
                              request-channel="request01Channel"
                              reply-channel="replyChannel"
                              name="/front/search"
    			......
    />
    
    
    <http:outbound-gateway id="request02"
                               url="/back/search"
                               http-method="POST"
                               request-channel="request02Channel"
                               reply-channel="responseChannel"
    			......                           
    			/>
    <transformer input-channel="responseChannel"
                 output-channel="replyChannel">
         	........
    </transformer>
    So, the content-length will be different for sure between the response from the backend services and the transformed message. What is the best way to handle this? I was thinking the spring integration would automatically update the content-length by itself. But it's not happening.

    I could make it work using a Chain in between channels to filter out the content-length header, or I can add the header mapper in the http-outbound-gateway to include only the needed header to return to the front. But what is the right way to manipulate the header?

    Thanks,

    Jeffrey

  • #2
    Have you try header filter? If I am not mistaken all you need is to make it look like a new request. Header filter will filter out un-needed headers

    Comment


    • #3
      Yes, I'm using the header filter to remove the "content-length" right now. But is it possible to update the content-length value instead of remove it?

      Thanks,

      Jeffrey

      Comment


      • #4
        I suppose this could be done with a custom header mapper, but doesn't it seem more appropriate for SI to calculate a new Content-Length based on the response generated after transformation? After all, it doesn't seem like the header is "unneeded" but rather that it is stale after all the processing that has happened to the message body after the Content-Length was originally calculated.

        Comment


        • #5
          Guys,
          Sorry, but somehow we didn't follow up on this one. This is a bug and was questioned once again here: http://forum.springsource.org/showth...7-Http-Support
          It will be fixed shortly and wil be available in 2.1 (hopefully next month)

          Comment


          • #6
            Still not working with Spring 3.1.M2 / SI 2.0.5

            Hi,

            I have encoutered the problem described above. I have followed your advice, and as described in INT-2006 upgraded to 3.1.0.M2.

            This however did not fix my problem - so I have assembled a super-simple app to confirm, exactly from your snippet.

            My test-context.xml:
            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            
            <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
                xmlns:int-http="http://www.springframework.org/schema/integration/http"
                xsi:schemaLocation="http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http-2.0.xsd
                            http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
                            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
            
            
                <int:service-activator input-channel="receiveChannel" output-channel="replyChannel" expression="payload + ' from the other side'" />
            
                <int:channel id="receiveChannel" />
                <int:channel id="replyChannel" />
            
                <int-http:inbound-gateway name="/test"
                    reply-channel="replyChannel" request-channel="receiveChannel"
                    supported-methods="POST" />
            
            </beans>
            wired to dispather servlet in web.xml like below:
            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
            
            <web-app id="WebApp">
            	<display-name>test-war</display-name>
            	
            	<servlet>
            		<servlet-name>test</servlet-name>
            		<display-name>TestServlet</display-name>
            		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            		<init-param>
            			<param-name>contextConfigLocation</param-name>
            			<param-value>/WEB-INF/spring-config/test-context.xml</param-value>
            		</init-param>
            		<load-on-startup>2</load-on-startup>
            	</servlet>
            
            	<servlet-mapping id="test-mapping">
            		<servlet-name>test</servlet-name>
            		<url-pattern>/test/*</url-pattern>
            	</servlet-mapping>
            
            </web-app>
            Still no luck - the content lenght is taken from request. If I send post with "1234567890" this is exactly what is receive back - ' from the other side' is truncated. Tested with "Poster" plugin for Firefox.

            Can you please confirm if closing INT-2006 was a little bit too quick, or i have screwed something up (cannot see it, there is literally nothing in the config that can be screwed up).

            Cheers,
            Chris

            Comment


            • #7
              Can you please validate the class-path and make sure you have no lingering 3.0 dependencies. I just tried it again and it works. Another reason why I am so sure is because of the code change in StringHttpMessageConverter which is responsible to calculate the content length. It used to (v3.0) check if Charset header was set and if it wasn't it would not calculate the content-length where now if Charset is not set it defaults to a Default charset so content-length is *always* calculated.

              Comment


              • #8
                Confirmed - it works with 3.1.0.M2

                Sorry for the commotion - my default. The project was managed as Maven web project, but debugged under Eclipse, and m2e is sometimes not really updating dependencies.
                I hate the m2e dance - even if it says it is 3.1.0.M2 - it was not.

                I tried clean jetty:run-war - and it worked. Once again thanks.

                One question though: why the http request headers are propagated to the response message ? I could understand that a transformer, or some other component in the middle of the message processing flow does copy the headers. But for service activator, or any other component terminating the message flow, I would say that the response message is a brand new message, that basically is connected to the original request only by the fact it menstions its ID in some header.
                This is my understanding ... but correct me if I am wrong. Cause if we do copy the headers, we could end up having http headers from request on a response message coming from some external system via, say, JMS, and it does not really make sense for me.

                Thanks,
                KT

                Comment


                • #9
                  Well you are looking at it from the request/response standpoint sort of like a non-void method invocation, but you must understand one of the core principal of Messaging and that is "Message always flows in one direction". So in the case of the Gateway the response you get is actually a Message that was sent downstream to the channel identified as a reply-channel (in service-activator it would have been an output-channel). We must keep headers since some of them (e.g., replyChannel, correlationId etc.) might be important to some downstream component. We can't just remove them. However if the state of the Message must be modified there is a MessageFilter and ContentFilter patterns that come to play
                  So look at Filter - http://static.springsource.org/sprin...single/#filter and HeaderFilter - http://static.springsource.org/sprin...#header-filter which you can use to filter out headers you don't need.
                  Hope that explains

                  Comment

                  Working...
                  X