Results 1 to 4 of 4

Thread: si-http:outbound-gateway gives HttpMessageNotWritableException for Integer

  1. #1
    Join Date
    Mar 2006
    Posts
    119

    Default si-http:outbound-gateway gives HttpMessageNotWritableException for Integer

    I am building a very simple spike for http:outbound-gateway.

    My app is configured as follows:

    Code:
    <si:gateway id="httpGateway" service-interface="bob.Gateway" default-reply-channel="httpGatewayReply" default-request-channel="httpGatewayRequest"/>
    
    <si:channel id="httpGatewayReply"/>
    <si:channel id="httpGatewayRequest"/>
    
    <si-http:outbound-gateway
                url="http://localhost:8080/Grails/test/index"
                request-channel="httpGatewayRequest"
                http-method="POST"
                request-timeout="2000"
                reply-channel="httpGatewayReply"
                expected-response-type="java.lang.String"
                auto-startup="true"
                charset="UTF-8"
                />
    The interface is:

    Code:
    package bob
    
    public interface Gateway {
      String calculateShippingCost(Map s)
    }
    The test app is:

    Code:
    package bob
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class SIHttpTest {
      public static void main(String[] args) {
        def config = new ClassPathXmlApplicationContext("spring-config.xml");
    
        def gateway = (Gateway)config.getBean('httpGateway')
        println "Calling Gateway stuff..."
        println gateway.calculateShippingCost([fromLoc: "Brisbane", toLoc: 'Darwin', nItems: 1])
        println "Done."
      }
    }
    When I run this I get the following (excerpted) stack trace:

    Code:
    org.springframework.integration.MessageHandlingException: HTTP request execution failed for URI [http://localhost:8080/Grails/test/index]
    	at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:243)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:98)
    ...
    Caused by: org.springframework.http.converter.HttpMessageNotWritableException: Could not write request: no suitable HttpMessageConverter found for request type [java.lang.Integer]
    	at org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:292)
    ...
    Exception in thread "main" org.springframework.integration.MessageHandlingException: HTTP request execution failed for URI [http://localhost:8080/Grails/test/index]
    	at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:243)
    ...
    Caused by: org.springframework.http.converter.HttpMessageNotWritableException: Could not write request: no suitable HttpMessageConverter found for request type [java.lang.Integer]
    	at org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:292)
    	at
    ...
    All is OK if I alter to test app to remove the integer map entry, thus:

    Code:
        println gateway.calculateShippingCost([fromLoc: "Brisbane", toLoc: 'Darwin'])
    It's also OK if I treat nItems as a string:

    Code:
        println gateway.calculateShippingCost([fromLoc: "Brisbane", toLoc: 'Darwin', nItems: '1'])
    This is surprising to me.

    Do I need to create a converter for Integer?

    Thoughts/guidance/suggestions gratefully accepted.

    Cheers,

    Alph

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

    Default

    Thank you
    I was able to reproduce and it does seem strange to me that it could not convert it automatically. Let me look closer, i'll reply shortly.

  3. #3
    Join Date
    Mar 2006
    Posts
    119

    Default

    Sorry to nag Oleg, but did you find anything in your investigations? Is there a workaround?

    Cheers,

    Alph

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

    Default

    Yeah, the default HttpMessageConvereters do not handle integers. One of the engineers of that functionality (in RestTemplate) is on vacation, so I have to wait till he gets back to get the answer. Part of the issue i think is because there is no way to submit Integer from the form. It will always come as a String. So i would suggest to do that (wrap int to string as you did before). Let me know.

Posting Permissions

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