2015-06-23 24 views
1

所以我用騾子的舊版本(3.3.1 )和澤西島(1.6) - 非常新的進入和無法升級 - 並且與"null in FormParam with 「charset=UTF-8」 in Jersey 2.0"有類似的問題,因爲HTML表單數據爲@POST ed始終爲null,但使用(強制使用非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> 

好像澤西島正在吃我的請求身體。鑑於如果我插入TestInterceptor(在上面的註釋中),它僅僅輸出包括消息正文和@FromParam的消息屬性,所有預期的數據都在那裏。有沒有辦法阻止澤西島做到這一點或事先獲得數據?

預期@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 
+1

用@ FormParam註解的方法的預期'Content-Type'是什麼?你使用了什麼'curl'命令? –

+0

這兩個都添加到問題。 –

+1

謝謝。一切看起來很好,所以它看起來像一個錯誤。您是否可以將您的應用程序部署在更近期的Mule上以查看它是否已解決問題? –

回答

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轉換很容易改進...

+0

這聽起來很正確,本週晚些時候我會試一試。 –

+0

它的工作原理。非常好,謝謝。雖然沒有把它轉化爲參數。 –