2011-12-16 4 views
2

mule 3.1.2의 다른 서버로 일부 게시물 데이터를 보내야합니다. 내가 http://localhost:5678/httpHello에 POST 요청을하고, 일부 매개 변수를 보낼Mule 3.1.2의 프록시 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> 

: 여기 내 노새-config 파일입니다. http://localhost:8080/webproj/index.jsp 페이지에서받은 매개 변수를 검사하지만 매개 변수가 비어 있습니다. index.jsp 페이지의 처음에 전송 된 매개 변수를 수신하고 싶습니다. 내 뮬 구성 파일을 변경하는 방법은 무엇입니까? 고마워요!

답변

0

신청서/x-www-form-urlencoded 인바운드 및 아웃 바운드 HTTP 콘텐츠 유형이 있다고 가정하면 여기에 원하는대로 수행하는 구성이 있습니다 (예 : 페이로드 로깅 및 현재 상태에 따라 다른 응답 선택 매개 변수의) :

<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

페이로드를 어떻게 얻을 수 있습니까? 나는 매개 변수지도를 확인했다, 그것은 비어있다. –