从信封中获取文本

时间:2015-08-17 10:51:56

标签: wso2 wso2esb

我想从以下Envelope获取文本,以便我可以将其用作REST_URL_POSTFIX。

我正在向JMS队列发送纯文本消息,然后将WSO2-ESB代理服务用作JMS队列的接收器/侦听器。我尝试过以下表达式,但它们不起作用:

$ body

  

$体/文本

     

$体/文本()

     

SOAP 1.1或1.2 body元素。例如,表达式   $ body / getQuote是指SOAP主体中的第一个getQuote元素,   无论消息是SOAP-11还是SOAP-12。

  

// //信封体//文本

     

// //信封体//文本()

信息 - (发送

LogMediator To: , MessageID: ID:sunnydyal-K55VM-44230-1439804805911-3:2:1:1:9, 
Direction: request, @@@@@ Message = , 
Envelope: 
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
    <axis2ns8:text xmlns:axis2ns8="http://ws.apache.org/commons/ns/payload">Test</axis2ns8:text>
</soapenv:Body>
</soapenv:Envelope>

@Proxy服务:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="JmsToRestProxy"
       transports="jms"
       statistics="enable"
       trace="enable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="OUT_ONLY" value="true"/>
         <property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
         <property name="SOAPAction" scope="default" action="remove"/>
         <header name="Action" scope="default" action="remove"/>
         <property name="REST_URL_POSTFIX"
                   expression="//Envelope//Body//text"
                   scope="axis2"
                   type="STRING"/>
         <switch source="$axis2:HTTP_METHOD">
            <case regex="GET">
               <property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
            </case>
            <case regex="POST">
               <property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
            </case>
            <default/>
         </switch>
         <log level="full">
            <property name="@@@@@ Message" expression="$body/text"/>
         </log>
         <send>
            <endpoint>
               <address uri="http://localhost:8080/Rest/rest" format="rest"/>
            </endpoint>
         </send>
      </inSequence>
   </target>
   <parameter name="transport.jms.ContentType">
      <rules>
         <jmsProperty>contentType</jmsProperty>
         <default>text/plain</default>
      </rules>
   </parameter>
   <description/>
</proxy>

2 个答案:

答案 0 :(得分:2)

文本节点属于特定的命名空间&#34; http://ws.apache.org/commons/ns/payload&#34; :

<log level="full">
    <property xmlns:syn="http://ws.apache.org/commons/ns/payload" name="@@@@@ Message" expression="$body/syn:text/text()"/>
</log>

答案 1 :(得分:0)

你可以使用$ body变量[1]来获取身体。 <log level="custom"> <property name="Body" expression="$body" /> </log> 正在尝试访问不存在的正文的文本元素。

new

[1] - https://docs.wso2.com/display/ESB481/Synapse+XPath+Variables#SynapseXPathVariables- $ body