WSO2。如何转换XML中的SOAP消息并将其发送到服务?

时间:2014-10-16 16:09:02

标签: wso2 wso2esb mediator

美好的一天!

我最近开始学习WSO ESB

我的服务接收请求并以XML格式响应,例如:

<!--The query in my service -->
POST / HTTP/1.1
Content-Type: text/xml; charset=utf-8
Content-Length: 109     
<req>
  <Value>How are you?</Value>
</req>

<!--The response from the service -->
HTTP/1.1 200 OK
Content-Length: 120
Content-Type: text/xml; charset=utf-8    
<res>
<Value>Very good!!!</Value>
</res>

我需要通过代理服务从客户端转换SOAP请求到SOAP客户端中的XML

代理服务中的SOAP请求和响应示例

<!--The request from the client to proxy service-->
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <Question xmlns="http://MyTestService">
       <Value>How are you?</Value>
    </Question>
  </soap:Body>
</soap:Envelope>

<!--Answer the service proxy to the client-->
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <QuestionResponse xmlns="http://CyberPlatService">
      <Fun1Result>Very good!!!</Fun1Result>
    </QuestionResponse>
  </s:Body>
</s:Envelope>

这是我的代理服务

<proxy xmlns="http://ws.apache.org/ns/synapse" name="CyberPlatProxy" transports="https http" 
       startOnLoad="true" trace="disable">
  <target>
    <inSequence>
      <payloadFactory media-type="xml">
        <format>
          <req>
            <Value>$1</Value>
          </req>
        </format>
        <args>
          <arg  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
          expression="//Question/Value"/>
        </args>
      </payloadFactory>
      <property name="messageType" value="text/xml" scope="axis2" type="STRING"/>
      <property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"/>
      <log level="custom"/>
      <send>
        <endpoint>
          <http method="post" uri-template="http://localhost:2009/"/>
        </endpoint>
      </send>
    </inSequence>
    <outSequence>
      <payloadFactory media-type="xml" description="res">
        <format>
          <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
            <s:Body>
              <GetStaysResponse xmlns="http://CyberPlatService">
                <GetStaysResult>$1</GetStaysResult>
              </GetStaysResponse>
            </s:Body>
          </s:Envelope>
        </format>
        <args>
          <arg expression="//Value"/>
        </args>
      </payloadFactory>
      <property name="messageType" value="application/soap+xml" scope="axis2" type="STRING"/>
      <send/>
    </outSequence>
    <faultSequence/>
  </target>
</proxy>

什么都没发生,我做错了什么?

1 个答案:

答案 0 :(得分:3)

&#34;问题&#34;节点属于http://MyTestService命名空间,因此,您的xpath //Question/Value无法正常工作,您应该更改:

<arg  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" expression="//Question/Value"/>

到:

<arg  xmlns:test="http://MyTestService" expression="//test:Question/test:Value/text()"/>