2011-12-16 11 views
2

いくつかの投稿データをmule 3.1.2の別のサーバに送信する必要があります。ここに私のミュール設定ファイルがあります:Mule 3.1.2のProxy HTTP POSTフォームデータ

<?xml version="1.0" encoding="UTF-8"?> 
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" 
xmlns:rmi="http://www.mulesoft.org/schema/mule/rmi" xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio" 
xmlns:vm="http://www.mulesoft.org/schema/mule/vm" 
xsi:schemaLocation=" 
     http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.1/mule-http.xsd 
     http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/3.1/mule-scripting.xsd 
     http://www.mulesoft.org/schema/mule/rmi http://www.mulesoft.org/schema/mule/rmi/3.1/mule-rmi.xsd 
     http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd 
     http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/3.1/mule-stdio.xsd 
     http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.1/mule-vm.xsd"> 

    <flow name="cxfFlow"> 
     <!-- Accept a http request from the specific address --> 
     <http:inbound-endpoint address="http://localhost:5678/httpHello"> 
      <byte-array-to-string-transformer/> 
      <http:body-to-parameter-map-transformer/> 
     </http:inbound-endpoint> 

     <!-- This component is just set to show the message accecpted from the request --> 
     <scripting:component> 
      <scripting:script engine="groovy"> 
       def msg = "message: $message;\npayload:$payload;\n result:$result".toString() 
       println msg 
       println "init param:$payload" 
       return payload 
      </scripting:script> 
     </scripting:component> 

     <!-- This component is set to parse the parameter passed by the request --> 
     <scripting:component> 
      <scripting:script engine="groovy"> 
        def paramstr = "" 
        for(param in payload){ 
         paramstr = paramstr + "&amp;" + param.key+ "=" + param.value 
        } 
       println "querystr:$paramstr" 
       return paramstr.substring(1) 
      </scripting:script> 
     </scripting:component> 

     <choice> 
      <when expression="payload.size()>0" evaluator="groovy"> 
       <http:outbound-endpoint address="http://localhost:8080/webproj/index.jsp" method="POST" contentType="text/http"> 
       </http:outbound-endpoint> 
      </when> 
      <otherwise> 
       <scripting:component> 
        <scripting:script engine="groovy"> 
         println payload 
         return "no parameter is given!" 
        </scripting:script> 
       </scripting:component> 
      </otherwise> 
     </choice> 
    </flow> 
</mule> 

私はhttp://localhost:5678/httpHelloへの投稿要求を行い、いくつかのパラメータを送信します。 http://localhost:8080/webproj/index.jspページでは、受信したパラメータを調べますが、パラメータは空です。 index.jspページの最初に送信されたパラメータを受け取って、mule-configファイルを変更する方法を教えてください。どうもありがとう!

答えて

0

application/x-www-form-urlencodedがであると仮定すると、ここでは必要なことを行う設定が行われます(つまり、ペイロードを記録してプレゼンスに基づいて別の応答を選択するパラメータ:of

<flow name="webFormFlow"> 
    <!-- Accept a http request from the specific address --> 
    <http:inbound-endpoint address="http://localhost:5678/httpHello"> 
     <http:body-to-parameter-map-transformer /> 
    </http:inbound-endpoint> 

    <!-- This logger is just set to show the message accepted from the request --> 
    <logger level="INFO" message="#[payload]" /> 

    <choice> 
     <when expression="payload.size() &gt; 0" evaluator="groovy"> 
      <http:outbound-endpoint address="http://localhost:8080/webproj/index.jsp" 
       method="POST" contentType="application/x-www-form-urlencoded" /> 
     </when> 
     <otherwise> 
      <message-properties-transformer> 
       <add-message-property key="Content-Type" value="text/plain" /> 
      </message-properties-transformer> 
      <expression-transformer> 
       <return-argument expression="no parameter is given!" 
        evaluator="string" /> 
      </expression-transformer> 
     </otherwise> 
    </choice> 
</flow> 
+0

私は、クエリメソッドではなくPOSTメソッドでパラメータを送信したいのですが?私はパラメータがURLに表示されないようにします。 –

+0

これは簡単です:アウトバウンドURIから#[header:queryString]を削除し、paramstrを構築するスクリプトコンポーネント全体を削除します。 MuleはマップペイロードをエンティティとしてJSPにPOSTします。 –

+0

ペイロードはどのように入手できますか?私はパラメータマップをチェックしました、それは空です。 –