Announcement Announcement Module
Collapse
No announcement yet.
si-http:outbound-gateway gives HttpMessageNotWritableException for Integer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


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

      Cheers,

      Alph

      Comment


      • #4
        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.

        Comment

        Working...
        X