如果你在Mule ESB的应用中,需要传输JSON格式的字符串,而你直接在url的参数中写入,则会报如下错误:
Root Exception stack trace:
java.net.URISyntaxException: Illegal character in query at index 46: http://localhost:8088/spring/user/1/info?data={"name":"daihui","id":1,"sex":"M"}
at java.net.URI$Parser.fail(URI.java:2809)
at java.net.URI$Parser.checkChars(URI.java:2982)
at java.net.URI$Parser.parseHierarchical(URI.java:3072)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
即使是encode后传入也是不行,这个时候可以用HTTP的POST方法来提交和处理这种需求:
<set-property propertyName="Content-Type" value="application/x-www-form-urlencoded" doc:name="Set Content-Type property"/>
<http:outbound-endpoint method="POST" encoding="UTF-8" host="localhost" port="8088" path="spring/user/#[payload['id']]/info" doc:name="Invoke REST service"/>
传进的payload是map对象。
而如果你是直接从页面传过来的则可以直接使用message的http.query.params属性值,如下:
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" path="sayHi" responseTransformer-refs="ObjectToString" doc:name="HTTP Endpoint"/>
<set-payload value="#[message.inboundProperties['http.query.params']]" />