【问题标题】:Get Text from Envelope从信封中获取文本
【发布时间】:2015-08-18 03:30:21
【问题描述】:

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

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

$身体

$正文/文本

$body/text()

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

//信封//正文//文字

//信封//正文//text()

INFO - (发送

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>
                            

【问题讨论】:

    标签: wso2 wso2esb


    【解决方案1】:

    文本节点属于特定命名空间“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>
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多