所以我正在使用旧版本的 Mule (3.3.1) 和 Jersey (1.6) - 对两者来说都很新并且无法升级 - 并且有一个与 "null in FormParam with “charset=UTF-8” in Jersey 2.0" 类似的问题在该 HTML 表单中,@POST
编辑的数据始终为 null
,但使用 curl (强制使用非 UTF-8 字符集)没有什么区别,我的 @FormParam
仍然是 null
。
<flow name="repo" doc:name="Repository application">
<inbound-endpoint ref="RepositoryInternalEndpoint">
<not-filter>
<wildcard-filter pattern="/favicon.ico"/>
</not-filter>
</inbound-endpoint>
<!-- All seems fine at this point -->
<!--<custom-interceptor class="TestInterceptor"/>-->
<!-- Inside the RepositoryService class, @FormParam args are null -->
<jersey:resources doc:name="Repository Service Component">
<component>
<spring-object bean="repositoryService"/>
</component>
</jersey:resources>
</flow>
Jersey 似乎只是在吃我的请求主体。鉴于如果我插入 TestInterceptor
(在上面的注释中),它只是输出消息属性,包括消息正文和 @FromParam
,那么所有预期的数据都在那里。有没有办法阻止 Jersey 这样做或提前获取数据?
预期的@FormParam
参数都是String
这样......
@POST
@Path("/my/url")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public Response myMethod(@FormParam("o_serviceId") String serviceId){}
curl使用的命令是
curl -X POST -H "content-type: application/x-www-form-urlencoded" -d "o_serviceId=12345y" localhost:8889/my/url
最佳答案
我相信您被这个长期存在的问题所困扰:https://www.mulesoft.org/jira/browse/MULE-5687
当比较 HTTP 和 Jetty 连接器之间的 Mule 消息负载时,我注意到它实际上是后者的 application/x-www-form-urlencoded
请求的空字符串,而它包含实际的前者的主体。
事实上,如果我在 jersey:resources
之前添加此内容,一切都会正常工作:
<set-payload
value="#[org.mule.util.StringUtils.join(message.inboundProperties['request.parameters'].entrySet(),'&')]" />
这基本上根据请求参数重建消息有效负载。这是一个快速但肮脏的修复:它没有正确地重新编码参数,并且假设 Map.Entry.toString()
始终返回 key=value
。但通过适当的映射到 URL 编码字符串
转换很容易改进...
关于java - 我如何让我的消息体偷偷溜过 Jersey,也许使用 Mule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31003859/