1

所以我使用的是旧版本的 Mule ( 3.3.1 ) 和 Jersey ( 1.6 ) - 对两者都很新,无法升级 - 并且在 Jersey 中遇到与“charset=UTF-8”的 FormParam 中的“null”类似的问题2.0"中的 HTML 表单数据@POST总是被编辑,null但使用(强制非 UTF-8 字符集)没有区别,我@FormParam的 s 仍然是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>

似乎泽西岛只是在吃我的请求体。鉴于如果我插入TestInterceptor(在上面的注释中)它只输出消息属性,包括消息正文和@FromParams,那么所有预期的数据都在那里。有没有办法阻止泽西岛这样做或事先获取数据?

预期的@FormParam论点都是String这样......

@POST
@Path("/my/url")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public Response myMethod(@FormParam("o_serviceId") String serviceId){}

使用的命令是

curl -X POST -H "content-type: application/x-www-form-urlencoded" -d "o_serviceId=12345y" localhost:8889/my/url
4

1 回答 1

1

我相信你被这个长期存在的问题所困扰: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(),'&amp;')]" />

这基本上是根据请求参数重建消息有效负载。这是一个快速而肮脏的修复:它没有正确地重新编码参数并且它假定Map.Entry.toString()总是返回key=value. 但是通过适当的转换很容易改进Map to URL-encoded string......

于 2015-06-26T18:38:50.620 回答