Announcement Announcement Module
Collapse
No announcement yet.
Porting from 1.x to 2.x: Content-Type being set to application/x-www-form-urlencoded Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Porting from 1.x to 2.x: Content-Type being set to application/x-www-form-urlencoded

    Greetings. In the process of porting from 1.0.4 to latest and greatest, we have run into an issue where our binary payloads received from our clients (via HTTP) are being treated as form data. The HTTP engine our clients utilize do not sent a "Content-Type" header, but somehow, the Content-Type is being set to application/x-www-form-urlencoded and because of this, SI converts the payload as if it were a form. Specfically, ByteArrayHttpMessageConverter.readInternal() calls FileCopyUtils.copy(inputMessage.getBody(), bos).
    HttpInputMessage.getBody() has the following logic

    Code:
    	public InputStream getBody() throws IOException {
    		if (isFormPost(this.servletRequest)) {
    			return getBodyFromServletRequestParameters(this.servletRequest);
    		}
    		else {
    			return this.servletRequest.getInputStream();
    		}
    	}

    isFormPost(...) returns true and functionally, we want it to return false so we convert the raw input stream.

    Here is our configuration for our HttpRequestHandlingMessagingGateway

    Code:
         <beans:bean id="httpDeviceDataUploadInboundEndpoint" class="org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway">
            <beans:property name="messageConverters">
                <beans:list>
                    <beans:ref bean="byteArrayHttpMessageConverter"/>
                </beans:list>
            </beans:property>
            <beans:property name="supportedMethods">
                <beans:list>
                    <beans:value>POST</beans:value>
                </beans:list>
            </beans:property>
            <beans:property name="requestChannel" ref="httpDataUploadInboundChannel"></beans:property>
            <beans:property name="replyChannel" ref="httpDataUploadReplyChannel"></beans:property>
         </beans:bean>
    And our client simulator looks like this when sending the data:

    Code:
    URL theURL = new URL(url);
    URLConnection connection = theURL.openConnection();
    System.out.println(connection.getRequestProperties());  // returns {}
    connection.setDoOutput(true); 
    OutputStream output =  connection.getOutputStream();
    output.write(payload);
    return connection.getInputStream();
    Not sure how or when Content-Type is being set and it doesn't seem like URLConnection (on the client side) is defaulting to it.

    Am I missing something? Any help would be greatly appreciated.

    Thanks in advance.

  • #2
    I just ran a test through a tcpip monitor and the Sun URLConnection sets the header...

    Code:
    POST /http/receiveGateway HTTP/1.1
    User-Agent: Java/1.6.0_26
    Host: localhost:8080
    Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    Connection: keep-alive
    Content-type: application/x-www-form-urlencoded
    Content-Length: 5
    You need to set the content-type to override this default behavior...

    Code:
    connection.setRequestProperty("content-type", "application/octet-stream");

    Comment


    • #3
      Gary, my sincere apologies (as I wipe egg off my face), debug statements lead us down the wrong path. -Al

      Comment

      Working...
      X