Announcement Announcement Module
Collapse
No announcement yet.
Content Type is not getting set properly in http inbound Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Content Type is not getting set properly in http inbound

    Hi,
    The content type is set to default text/html even if i set it to (say application/vnd.ms-excel). Here is my config,
    Code:
    <int:chain input-channel="downloadChannel">
    		<int:service-activator ref="downloadService"
    			method="fetchDocument" />
    		<int:header-enricher>
    			<int:header name="Content-Type" expression="payload[mediaType]" />
    		</int:header-enricher>
    		<int:transformer expression="payload[document]" />
    	</int:chain>
    My media type is set in my service activator class and i'm returning a map object as follows,
    Code:
    String mediaType="application/vnd.ms-excel";
    payloadMap.put("mediaType",mediaType);
    payloadMap.put("document", bytes);
    return payloadMap;
    Please note that the mediaTye may change @ run time.It is based on the document i receive from the server.
    Am i missing something? I'm pretty much sure that the received file from the server is an excel and the content type in the response stillbeing set as text/html.
    Any pointers on this?
    TIA,
    Paary

  • #2
    Hello

    Have you tried this one:
    HTML Code:
    <int:header name="Content-Type" expression="payload[mediaType]" overwrite="true"/>
    ?

    Keep in mind: you may send "Content-Type" HttpHeader in the Request.
    And that is why I said you in your other thraed, that you should orientate to "Accept" Request Header.
    Your client (browser) may send this one to wait some specific content in the Response.

    Please, investigate it a bit more.

    Good luck,
    Artem Bilan

    Comment


    • #3
      Can you show us Http Inbound configuration?

      Comment


      • #4
        Oleg,
        Here is my inbound configuration,
        Code:
        <int-http:inbound-gateway request-channel="downloadChannel"
        name="/RetrieveDoc" supported-methods="GET" mapped-response-headers="Content-Type"/>

        Thanks,
        Paary

        Comment


        • #5
          Ok, are you saying that your 'content-type' header' is not propagated properly from this inbound gateway to the downstream component? Or is it about the response going back to the inbound gateway?

          Comment


          • #6
            Please try Artem's suggestion. By default, a header-enricher does not overwrite existing headers, and your inbound gateway is mapping all the standard HTTP headers itself (the default for 'mapped-request-headers'), so the original request's Content-Type header will be present.

            Hope that helps.
            -Mark

            Comment


            • #7
              Oleg,
              Yes, the content- type is not getting propagated properly.
              Thanks Mark and Artem. I will try that. I will use the Accept Request header.
              Note- my request comes from the browser.I'm digging out more to find the proper usage. Thanks for your help!

              Comment


              • #8
                Can you trace with wiretap on the request-channel of the inbound gateway what is the value of the 'content-type' header coming in? I think that is the root of your problem. Sure you can override/change it downstream, but that would be more like fixing the problem that actually originated elsewhere and should probably be fixed there.

                Comment


                • #9
                  do we need to code a custom loggin handler

                  Oleg,
                  I tried configuring the wiretap to the input channel.
                  Code:
                  <int:channel id="downloadChannel">
                  		<int:interceptors>
                  			<!-- <wire-tap channel="wiretapChannel" /> -->
                  			<int:wire-tap channel="wiretapChannel"/>
                  		</int:interceptors>
                  	</int:channel>
                  	<int:logging-channel-adapter id="wiretapChannel"
                  		level="INFO" log-full-message="true" />
                  but i'm not able to see the content type in the console.
                  Do we need to code a Custom Logging Handler for this?

                  Comment


                  • #10
                    Originally posted by oleg.zhurakousky View Post
                    Can you trace with wiretap on the request-channel of the inbound gateway what is the value of the 'content-type' header coming in? I think that is the root of your problem. Sure you can override/change it downstream, but that would be more like fixing the problem that actually originated elsewhere and should probably be fixed there.

                    Oleg - The use case we have is that a Servlet is exposed to the client ( from our SI platform). The client doesnt know what document they are going to receive. They submit the metadata that we need to use to go to a downstream application to get the document and understand what the MIME type is and set it\overwrite it on the HTTP Response.

                    So during inbound, the default Content Type that is being set on the HTTP Request is:
                    Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 (Captured using Tamper Data plugin on Firefox)

                    Using the header-mapper attribute, I know can see in the logs that the Content-Type is correctly being mapped which is a step in the right direction. Yet, on the response it still gets set to Content-Type=text/html (extracted from Tamper Data plugin on Mozilla)

                    An additional observation is that the Content Type modification for the response works fine with the message-converters attribute on the inbound gateway ( if we have only one MIME type to deal with on the return using the org.springframework.http.converter.ByteArrayHttpMe ssageConverter.)

                    We will continue our research. If you guys have any pointers, please let us know. Thank you.

                    Log snippet:

                    [DEBUG] [http-8080-2 01:53:07] (AbstractReplyProducingMessageHandler.java:sendRep lyMessage:157) handler 'ServiceActivator for [org.springframework.integration.handler.MethodInvo kingMessageProcessor@bc6007]' sending reply Message: [Payload={document=[B@143073a, mediaType=application/vnd.ms-excel}][Headers={errorChannel=org.springframework.integrat ion.core.MessagingTemplate$TemporaryReplyChannel@4 55aa8, replyChannel=org.springframework.integration.core. MessagingTemplate$TemporaryReplyChannel@455aa8, http_requestMethod=GET, timestamp=1337622787951, id=5281479b-57fc-473d-8222-130b4696c97c, http_requestUrl=http://localhost:8080/LiveLink/liveLinkFetch/RetrieveLLDoc?volID=5220142&nodeID=5220142}]
                    [DEBUG] [http-8080-2 01:53:07] (AbstractMessageHandler.java:handleMessage:72) org.springframework.integration.transformer.Messag eTransformingHandler#e771f3 received message: [Payload={document=[B@143073a, mediaType=application/vnd.ms-excel}][Headers={errorChannel=org.springframework.integrat ion.core.MessagingTemplate$TemporaryReplyChannel@4 55aa8, replyChannel=org.springframework.integration.core. MessagingTemplate$TemporaryReplyChannel@455aa8, http_requestMethod=GET, timestamp=1337622787951, id=5281479b-57fc-473d-8222-130b4696c97c, http_requestUrl=http://localhost:8080/LiveLink/liveLinkFetch/RetrieveLLDoc?volID=5220142&nodeID=5220142}]
                    [DEBUG] [http-8080-2 01:53:07] (AbstractReplyProducingMessageHandler.java:sendRep lyMessage:157) handler 'org.springframework.integration.transformer.Messa geTransformingHandler#e771f3' sending reply Message: [Payload={document=[B@143073a, mediaType=application/vnd.ms-excel}][Headers={errorChannel=org.springframework.integrat ion.core.MessagingTemplate$TemporaryReplyChannel@4 55aa8, replyChannel=org.springframework.integration.core. MessagingTemplate$TemporaryReplyChannel@455aa8, http_requestMethod=GET, Content-Type=application/vnd.ms-excel, timestamp=1337622787951, id=184389e0-8dba-43d9-93f5-a48cb9bcf14d, http_requestUrl=http://localhost:8080/LiveLink/liveLinkFetch/RetrieveLLDoc?volID=5220142&nodeID=5220142}]
                    [DEBUG] [http-8080-2 01:53:07] (AbstractMessageHandler.java:handleMessage:72) org.springframework.integration.transformer.Messag eTransformingHandler@12fc02 received message: [Payload={document=[B@143073a, mediaType=application/vnd.ms-excel}][Headers={errorChannel=org.springframework.integrat ion.core.MessagingTemplate$TemporaryReplyChannel@4 55aa8, replyChannel=org.springframework.integration.core. MessagingTemplate$TemporaryReplyChannel@455aa8, http_requestMethod=GET, Content-Type=application/vnd.ms-excel, timestamp=1337622787951, id=184389e0-8dba-43d9-93f5-a48cb9bcf14d, http_requestUrl=http://localhost:8080/LiveLink/liveLinkFetch/RetrieveLLDoc?volID=5220142&nodeID=5220142}]
                    [DEBUG] [http-8080-2 01:53:07] (AbstractReplyProducingMessageHandler.java:sendRep lyMessage:157) handler 'org.springframework.integration.transformer.Messa geTransformingHandler@12fc02' sending reply Message: [Payload=[B@143073a][Headers={errorChannel=org.springframework.integrat ion.core.MessagingTemplate$TemporaryReplyChannel@4 55aa8, replyChannel=org.springframework.integration.core. MessagingTemplate$TemporaryReplyChannel@455aa8, http_requestMethod=GET, Content-Type=application/vnd.ms-excel, timestamp=1337622787951, id=e4687839-2c82-4e94-aa1f-1f562d9f17ae, http_requestUrl=http://localhost:8080/LiveLink/liveLinkFetch/RetrieveLLDoc?volID=5220142&nodeID=5220142}]
                    [DEBUG] [http-8080-2 01:53:07] (AbstractMessageChannel.javaostSend:237) postSend (sent=true) on channel 'llDownloadChannel', message: [Payload={nodeID=[5220142], volID=[5220142]}][Headers={errorChannel=org.springframework.integrat ion.core.MessagingTemplate$TemporaryReplyChannel@4 55aa8, replyChannel=org.springframework.integration.core. MessagingTemplate$TemporaryReplyChannel@455aa8, http_requestMethod=GET, timestamp=1337622787951, id=1c7219cb-fad1-49c0-a367-042b1b5c6556, http_requestUrl=http://localhost:8080/LiveLink/liveLinkFetch/RetrieveLLDoc?volID=5220142&nodeID=5220142}]
                    [DEBUG] [http-8080-2 01:53:07] (DefaultHttpHeaderMapper.java:fromHeaders:273) outboundHeaderNames=[Content-Type]
                    [DEBUG] [http-8080-2 01:53:07] (DefaultHttpHeaderMapper.java:shouldMapHeader:374) headerName=[http_requestMethod] WILL NOT be mapped
                    [DEBUG] [http-8080-2 01:53:07] (DefaultHttpHeaderMapper.java:shouldMapHeader:353) headerName=[Content-Type] WILL be mapped, matched pattern=Content-Type
                    [DEBUG] [http-8080-2 01:53:07] (DefaultHttpHeaderMapper.java:fromHeaders:286) setting headerName=[Content-Type], value=application/vnd.ms-excel
                    [DEBUG] [http-8080-2 01:53:07] (DefaultHttpHeaderMapper.java:shouldMapHeader:374) headerName=[timestamp] WILL NOT be mapped
                    [DEBUG] [http-8080-2 01:53:07] (DefaultHttpHeaderMapper.java:shouldMapHeader:374) headerName=[id] WILL NOT be mapped
                    [DEBUG] [http-8080-2 01:53:07] (DefaultHttpHeaderMapper.java:shouldMapHeader:374) headerName=[http_requestUrl] WILL NOT be mapped
                    [DEBUG] [http-8080-2 01:53:07] (DispatcherServlet.java:doDispatch:824) Null ModelAndView returned to DispatcherServlet with name 'liveLinkFetchObj': assuming HandlerAdapter completed request handling
                    [DEBUG] [http-8080-2 01:53:07] (FrameworkServlet.javarocessRequest:674) Successfully completed request



                    Config File:

                    <int-http:inbound-gateway request-channel="llDownloadChannel"
                    name="/RetrieveLLDoc" supported-methods="GET" header-mapper="headerMapper" />

                    <bean id="headerMapper"
                    class="org.springframework.integration.http.suppor t.DefaultHttpHeaderMapper">
                    <property name="inboundHeaderNames" value="Content-Type" />
                    <property name="outboundHeaderNames" value="Content-Type" />
                    </bean>


                    <int:channel id="llDownloadChannel">
                    <!-- <int:interceptors> <int:wire-tap channel="wiretapChannel"/> </int:interceptors> -->
                    </int:channel>

                    <!-- handling multiple media types -->

                    <int:chain input-channel="llDownloadChannel">
                    <int:service-activator ref="llDownloadService"
                    method="fetchDocument" />
                    <int:header-enricher>
                    <!-- This will return the appropriate MIME Type based -->
                    <int:header name="Content-Type" expression="payload[mediaType]"
                    overwrite="true" />
                    </int:header-enricher>
                    <int:transformer expression="payload[document]" />
                    </int:chain>
                    <!-- <int:service-activator input-channel="llDownloadChannel" expression="@llDownloadService.fetchDocument(paylo ad)"
                    /> -->

                    <bean id="llDownloadService"
                    class="com.bac.gssil.liveLinkService.service.LLSer viceConnector">
                    </bean>

                    Comment


                    • #11
                      Strange! pdfs, images are rendered properly

                      One Strange behaviour is that, pdf's, images (jpg), .xml, .htm,.txt are working as expected for the same configuration. Only the microsoft files (word, excel, ppt) are not rendering properly.
                      Any insights on this?
                      also, from the logs(shared above) we could see the content type getting set as expected.

                      Comment


                      • #12
                        Paary,

                        And again I ask you: do you receive correct 'Content-Type' header in the browser? Is it what you've sended from server and does it equals that you're seeing in the logs?
                        Maybe you client OS can't render correctly microsoft files?

                        What is the issue about Spring Integration do you have right now?

                        Comment


                        • #13
                          Hi,
                          No Artem, the browser shows a different content type.( it still shows text/html)


                          Only from the logs, it is showing the content type we require is being set up.
                          Maybe you client OS can't render correctly microsoft files?
                          I just tried a sample servlet on my machine and it works perfectly by only setting the content type to the response. So i'm pretty sure that my machine supports Microsoft files thereby eliminating the question you raised.

                          Quick note- I'm using spring-integration-http-2.0.3.RELEASE.jar. Is this causing the problem?
                          Last edited by paary; May 23rd, 2012, 05:07 AM. Reason: added note

                          Comment


                          • #14
                            Hi,
                            I'm using spring-integration-http-2.0.3.RELEASE.jar
                            Maybe...
                            Try to use the latest one - 2.1.1.RELEASE

                            Comment


                            • #15
                              Originally posted by Cleric View Post
                              Hi,

                              Maybe...
                              Try to use the latest one - 2.1.1.RELEASE
                              On 2.1.1 now. Same behavior.




                              This is called on HttpRequestHandlingMessagingGateway.handleRequest

                              this.writeResponse(responseContent, response, request.getHeaders().getAccept());

                              The values that are passing @ runtime are:

                              responseContent - the byte[]

                              response - org.springframework.http.server.ServletServerHttpR esponse (contains byte[] and the header that is injected from a ServiceActivator we have (tried setting all possible values that can help render the document

                              return MessageBuilder.withPayload(document)
                              .setHeader("mediaType",mediaType)
                              .setHeader("Content-Type", mediaType)
                              .setHeader("Accept", mediaType)
                              .setHeader("accept", mediaType).build();


                              request.getHeaders().getAccept() - Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ( We cannot control this as the invocation to

                              our application is from a external client who will submit a HTTP GET request and these are the values that get sent on Accept


                              If we look at the writeResponse method for the code between ++++++, the possible values to be passed to converter.write method are only being picked from the acceptTypes list which is based on what was present on the HTTP Request Accept list. The Content Type that we have set on the Payload header/ServletServerHttpResponse is not part of the equation. Is this why we are not able to view the correct Content Type on when the response returns???

                              @SuppressWarnings({"unchecked", "rawtypes"})
                              private void writeResponse(Object content, ServletServerHttpResponse response, List<MediaType> acceptTypes) throws IOException {
                              if (CollectionUtils.isEmpty(acceptTypes)) {
                              acceptTypes = Collections.singletonList(MediaType.ALL);
                              }
                              for (HttpMessageConverter converter : this.getMessageConverters()) {

                              +++++++for (MediaType acceptType : acceptTypes) {
                              if (converter.canWrite(content.getClass(), acceptType)) {
                              converter.write(content, acceptType, response); +++++++

                              return;
                              }
                              }
                              }
                              throw new MessagingException("Could not convert reply: no suitable HttpMessageConverter found for type ["
                              + content.getClass().getName() + "] and accept types [" + acceptTypes + "]");
                              }

                              Comment

                              Working...
                              X