从信封中获取文本

Get Text from Envelope

我想从信封中获取文本,以便我可以将其用作 REST_URL_POSTFIX。

我正在向 JMS 队列发送纯文本消息,并且以下 WSO2-ESB 代理服务用作 JMS 队列的 receiver/listener。我尝试了以下表达式,但它们不起作用:

$正文

$body/text

$body/text()

The SOAP 1.1 or 1.2 body element. For example, the expression $body/getQuote refers to the first getQuote element in a SOAP body, regardless of whether the message is SOAP-11 or SOAP-12.

//Envelope//Body//text

//Envelope//Body//text()

信息-(发送

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>

@代理服务:

<?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>
                            

文本节点属于特定命名空间“http://ws.apache.org/commons/ns/payload”:

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

您可以使用 $body 变量[1] 获取正文。 /text() 正在尝试访问不存在的正文文本元素。

<log level="custom">
      <property name="Body" expression="$body" />
</log>

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