简体   繁体   English

WSO2 XSLT介体无法解析xpath

[英]WSO2 XSLT Mediator not resolving xpath

hopefully someone can point out the blindingly obvious to me - I want to perform a few simple translations on a soap payload before I send to a backend service - crucially, I need access to all the soap-headers delivered in the original payload. 希望有人能指出对我来说是盲目的显而易见的-我想在发送到后端服务之前对soap有效负载执行一些简单的转换-至关重要的是,我需要访问原始有效负载中提供的所有soap标头。 My naive(?) thinking was to simply set the source attribute for the <xslt> mediator to "/" as Im aware by default it will start from the first child of the <body> , and I really need access to the headers. 我天真的(?)想法是将<xslt>介体的source属性简单地设置为“ /”,因为Im默认情况下会从<body>的第一个孩子开始,而且我确实需要访问标头。 WSO2 returns a "The evaluation of the XPath expression / did not result in an OMNode" error. WSO2返回“对XPath表达式的求值/未导致OMNode”错误。

Are there one or more WSO2/xpath interworking quirks that Ive missed in the literature? 我在文献中错过了一个或多个WSO2 / xpath互通性古怪吗? Any pointers gratefully recieved, thanks 感谢所有指针,谢谢

As Tishan mentioned you can use $header synapse xpath variable to access soap headers in message context. 如Tishan所述,您可以使用$header synapse xpath变量在消息上下文中访问soap头。 But it's bit tricky when it comes to xslt mediator. 但这对于xslt中介器来说有点棘手。 You cannot directly access message context values inside xslt stylesheet. 您不能直接访问xslt样式表中的消息上下文值。 But it is possible to pass these values as parameters and use in transformation. 但是可以将这些值作为参数传递并用于转换。 Let's see how we can achieve this. 让我们看看如何实现这一目标。

Below is how account.xslt file looks like. 以下是account.xslt文件的外观。 Please note that there are two parameters called PARAM_SSN and PARAM_ACCT_NO used to assign value for <ssn></ssn> and <accountNumber></accountNumber> 请注意,有两个参数称为PARAM_SSNPARAM_ACCT_NO用于为<ssn></ssn><accountNumber></accountNumber>分配值

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="PARAM_SSN"></xsl:param>
    <xsl:param name="PARAM_ACCT_NO"></xsl:param>
    <xsl:template match="/">
        <account xmlns="http://services.samples">
            <ssn>
                <xsl:value-of select="$PARAM_SSN"></xsl:value-of>
            </ssn>
            <accountNumber>
                <xsl:value-of select="$PARAM_ACCT_NO"></xsl:value-of>
            </accountNumber>
            <accountHolder>
                <xsl:value-of select="//name"></xsl:value-of>
            </accountHolder>
        </account>
    </xsl:template>
</xsl:stylesheet>

Above file saved in registry of WSO2 ESB under /_system/governance/transform/account.xslt 上面的文件保存在WSO2 ESB注册表中的/_system/governance/transform/account.xslt

Next is sample proxy which do the transformation with account.xslt 接下来是示例代理,它使用account.xslt进行转换

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="TransformExample"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <xslt key="gov:/transform/account.xslt">
            <property name="PARAM_SSN" expression="$header/seccode"/>
            <property name="PARAM_ACCT_NO" expression="$trp:acctNo"/>
         </xslt>
         <log level="custom">
            <property name="Transformed Payload" expression="$body"/>
         </log>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>

Here you could see that inside <xslt> mediator, I am passing values for two parameters define in xslt by accessing message context. 在这里您可以看到,在<xslt>介体内部,我正在通过访问消息上下文传递xslt中定义的两个参数的值。 Value for PARAM_SSN taken from soap header and value for PARAM_ACCT_NO taken from transport header. 对值PARAM_SSN从肥皂头和值采取PARAM_ACCT_NO从传送头部取出。 This proxy service called by soapUI with below payload. soapUI调用的代理服务具有以下有效负载。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
    <seccode>987654321</seccode>
   </soapenv:Header>
   <soapenv:Body>
    <request>
        <name>Indika Sampath</name>
    </request>
   </soapenv:Body>
</soapenv:Envelope>

Also I am sending acctNo as transport header along with request. 我也将acctNo作为传输头与请求一起发送。 Once this hit the proxy, you could see transformed output log as below in console. 一旦点击代理,您将在控制台中看到如下所示的转换后的输出日志。

[2016-01-09 07:19:02,146]  INFO - LogMediator Transformed Payload = <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <account xmlns="http://services.samples"><ssn>987654321</ssn><accountNumber>123456789</accountNumber><accountHolder>Indika Sampath</accountHolder></account>
   </soapenv:Body>

Hope this would resolve your problem. 希望这能解决您的问题。

Cheers! 干杯!

You can access SOAP headers using Synapse Xpath Variable $header in your source xpath (Ex:$header/wsa:To). 您可以在源xpath中使用Synapse Xpath变量 $ header访问SOAP标头(例如:$ header / wsa:To)。
Hope this helps!! 希望这可以帮助!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM