WSO2 ESB-在有效负载的标签内使用XML数据调用Web服务 [英] WSO2 ESB - Invoking Webservices with XML data within a tag of the payload

查看:61
本文介绍了WSO2 ESB-在有效负载的标签内使用XML数据调用Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过中间件调用外部Web服务,并且有效载荷中的一个标签包含嵌入式XML。以下是有效负载和序列片段的示例。我遇到以下问题。

I have a requirement to invoke an external webservice(s) via the Middleware, with one of the tags in my payload containing embedded XML. Sample payload and sequence snippet below. I encounter the following issues.

场景1 :(第24行)expression = get-property('PayloadXML')-发出send命令时,webservice方法

Scenario 1 : (line 24) expression="get-property('PayloadXML')" - Upon issuing a send command, the webservice method is not recognized.

方案2 :(第24行)expression = get-property('lPayload')-发出send命令后,webservice方法成功调用。但是,要使目标系统成功处理该消息,就需要处理CDATA元素(包装)。

Scenario 2 : (line 24) expression="get-property('lPayload')" - Upon issuing a send command, the webservice method is successfully invoked. However, for the target system to successfully process the message, it would need to handle the CDATA element(wrapping).

当尝试通过soapUI调用方案2时,该过程是成功的。根据我的研究(在WSO2中传递CDATA ),soapUI似乎在内部处理了CDATA元素,在转发消息之前。

When trying to invoke Scenario 2 via soapUI, the process is successful. From what I've researched (Passing CDATA in WSO2), soapUI seems to internally handle the CDATA element, before forwarding the message.

现在,我知道我设置方案2的方式并不理想(更多是hack),但是我不知道任何其他方式来实现这一目标。我已经阅读了许多博客/帖子,并尝试通过XSLT中介器来转换(开发)有效载荷,但没有成功。我还遇到了以下帖子 http://www.yenlo.com/en/how-to-preserve-a-cdata-in-xml-that-is-circulating-in- a-wso2-enterprise-service-bus / ,但是我似乎找不到所引用的补丁。

Now, I understand the way I'm setting scenario 2 is not ideal(more of a hack), but I'm unaware of any other ways to achieve this. I've read numerous blogs/posts and tried transforming(developing) the Payload via the XSLT mediator with no luck. I've also come across the following post http://www.yenlo.com/en/how-to-preserve-a-cdata-in-xml-that-is-circulating-in-a-wso2-enterprise-service-bus/ , but I can't seem to find the patch that is being referred to.

所以我的问题是如下:
1.我是否还有其他方法/机制可以满足自己的要求?
2. WSO2 ESB 4.9.0版本是否可以解决上述问题?

So my questions are as follows: 1. Are there any other ways/mechanisms for me to achieve my requirements? 2. Will the WSO2 ESB 4.9.0 release resolve the issues mentioned above?

样本有效载荷:

<sample><test>MyData</test></sample>

序列片段:

     <property xmlns:ns1="http://ws.wso2.org/dataservice"
               xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
               name="PayloadXML"
               expression="$body/data-services-event/content/ns1:return/ns1:return/ns1:PayLoadXML"/>
     <property xmlns:ns="http://org.apache.synapse/xsd"
               name="lPayload"
               expression="fn:concat(fn:concat('&lt;![CDATA[',get-property('PayloadXML')), ']]&gt;')"/>
     <payloadFactory media-type="xml">
        <format>
           <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                             xmlns:log="http://mynamespace">
              <soapenv:Header/>
              <soapenv:Body>
                 <log:publishMessage>
                    <Payload xmlns="">$1</Payload>
                 </log:publishMessage>
              </soapenv:Body>
           </soapenv:Envelope>
        </format>
        <args>
           <arg xmlns:ns2="http://org.apache.synapse/xsd"
                xmlns:ns="http://org.apache.synapse/xsd"
                evaluator="xml"
                expression="get-property('lPayload')"/>
        </args>
     </payloadFactory>


推荐答案

这是一个示例代理服务,用于接收XML数据并发回一条新的XML消息,并在CDATA部分中输入内容的一部分。

Here is a sample proxy service that receive XML data and send back a new XML message with a sub part of the input content in a CDATA section.

发送它:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <PayloadXML>
            <sample><test>MyData</test></sample>
        </PayloadXML>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

您收到:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
        <log:publishMessage xmlns:log="http://mynamespace">
            <Payload><![CDATA[<sample><test>MyData</test></sample>]]></Payload>
        </log:publishMessage>
    </soapenv:Body>
</soapenv:Envelope>

代理def:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestSOF" transports="http" statistics="disable" trace="disable" startOnLoad="true">
    <target>
        <inSequence>
            <!-- extract xml content from the input message -->
            <property name="xmlContent" expression="$body/PayloadXML/*[1]" type="OM"/>
            <!-- compose a new message -->
            <enrich>
                <source type="inline" clone="true">
                    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                        <soapenv:Header/>
                        <soapenv:Body>
                            <log:publishMessage xmlns:log="http://mynamespace">
                                <Payload xmlns=""/>
                            </log:publishMessage>
                        </soapenv:Body>
                    </soapenv:Envelope>
                </source>
                <target type="envelope"/>
            </enrich>
            <!-- create a CDATA section for 'Payload' node -->
            <script language="js">
                importPackage(Packages.org.apache.axiom.om);
                var payloadElmt = mc.getEnvelope().getBody().getFirstElement().getFirstElement();
                var omText = payloadElmt.getOMFactory().createOMText(payloadElmt, mc.getProperty("xmlContent"), OMNode.CDATA_SECTION_NODE);
                payloadElmt.addChild(omText)                    
            </script>
            <!-- send back this new message as a response for the caller -->
            <header name="To" action="remove"/>
            <property name="RESPONSE" value="true"/>
            <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
            <send/>
        </inSequence>
    </target>
    <description/>
</proxy>

这篇关于WSO2 ESB-在有效负载的标签内使用XML数据调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆