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