我使用的是wso2esb-4.8.1, 我希望在发送到端点和客户端之前更改我的请求和响应
所以我的要求是
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:env="http://eai.ttt.pp.hh" xmlns:open="http://www.oly.org/" xmlns:xsi="xsi">
<pr:authentication soapenv:her="http://schemas.xmlsoap.org/soap/her/next" soapenv:mustUnderstand="0" xmlns:pr="http://webservices.temp.com/ProxyService">
<pr:user>sec5</pr:user>
<pr:password>ss</pr:password>
</pr:authentication>
</soapenv:Header>
<soapenv:Body>
<open:clientRequest xmlns:open="http://www.oly.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:EaiEnvelope xmlns:env="http://eai.ttt.pp.hh">
<env:Language>en</env:Language>
<env:UserId>admc</env:UserId>
<env:Payload>
<ss:security xmlns:ss="http://eai.admc.kyt/security">
<ss:Request>
<ss:Operation_Name>securityrem</ss:Operation_Name>
<ss:customerID>
<ss:no>9875452</ss:no>
<ss:Service_Type>gsm</ss:Service_Type>
</ss:customerID>
<ss:customer>
<ss:isCredit>false</ss:isCredit>
<ss:Amount>100000</ss:Amount>
<ss:transaction_Id>4301298</ss:transaction_Id>
<ss:TransactionTypeID>228</ss:TransactionTypeID>
<!--<ss:DeductionPriorityCode>2</ss:DeductionPriorityCode>-->
</ss:customer>
</ss:Request>
</ss:security>
</env:Payload>
</env:EaiEnvelope>
</open:clientRequest>
</soapenv:Body>
</soapenv:Envelope>
我希望使用 xmlns:emp =&#34; http://uri.open.gen/com" 更改 ss:security 元素命名空间所以我的请求应该根据新的命名空间进行更改,请点击这个
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:env="http://eai.ttt.pp.hh" xmlns:open="http://www.oly.org/" xmlns:xsi="xsi">
<pr:authentication soapenv:her="http://schemas.xmlsoap.org/soap/her/next" soapenv:mustUnderstand="0" xmlns:pr="http://webservices.temp.com/ProxyService">
<pr:user>sec5</pr:user>
<pr:paempword>emp</pr:paempword>
</pr:authentication>
</soapenv:Header>
<soapenv:Body>
<open:clientRequest xmlns:open="http://www.oly.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:EaiEnvelope xmlns:env="http://eai.ttt.pp.hh">
<env:Language>en</env:Language>
<env:UserId>admc</env:UserId>
<env:Payload>
<emp:safety xmlns:emp="http://uri.open.gen/com">
<emp:Request>
<emp:Operation_Name>securityrem</emp:Operation_Name>
<emp:customerID>
<emp:no>9875452</emp:no>
<emp:Service_Type>gsm</emp:Service_Type>
</emp:customerID>
<emp:customer>
<emp:isCredit>false</emp:isCredit>
<emp:Amount>100000</emp:Amount>
<emp:transaction_Id>4301298</emp:transaction_Id>
<emp:TransactionTypeID>228</emp:TransactionTypeID>
<!--<emp:DeductionPriorityCode>2</emp:DeductionPriorityCode>-->
</emp:customer>
</emp:Request>
</emp:safety>
</env:Payload>
</env:EaiEnvelope>
</open:clientRequest>
</soapenv:Body>
</soapenv:Envelope>
所以我尝试过使用xquery但是无法做某人请为此做出回应 我试过这个xquery
<x xmlns="http://ws.apache.org/ns/synapse">
declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope";
declare namespace soap="http://schemas.xmlsoap.org/soap/envelope/";
declare namespace open="http://www.ffff.org/";
declare variable $emp as xs:string+:="http://uri.open.gen/com";
declare namespace env="http://eai.jj.mmm/Envelope";
declare variable $Request xs:string+ external;
declare variable $EaiEnvelope as document-node() external;
element{'open:clientRequest'}{
element{'*:EaiEnvelope'}{$EaiEnvelope//*:EaiEnvelope/*[not(local-name()='Payload')],
element{'*:Payload'}{
element{QName($emp,concat('emp',':','safety'))}
$Request//env:Payload/*[1]/*
}}
}
</x>
但未指定其给出异常令牌 提前致谢
答案 0 :(得分:0)
如果XSLT 2.0是您的选项(例如使用saxon XSLT处理器)。您可以将此样式表应用于您的输入:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ss="http://eai.admc.kyt/security"
xmlns:emp="http://uri.open.gen/com"
version="2.0">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ss:*">
<xsl:element name="emp:{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
<xsl:template match="@ss:*">
<xsl:attribute name="emp:{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
输入中http://eai.admc.kyt/security
命名空间中的每个属性和元素都将位于输出中的另一个命名空间中。
一个注释:它不会在评论中改变
答案 1 :(得分:0)
这是一个XQuery选项...
XML输入
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:env="http://eai.ttt.pp.hh" xmlns:open="http://www.oly.org/" xmlns:xsi="xsi">
<pr:authentication soapenv:her="http://schemas.xmlsoap.org/soap/her/next" soapenv:mustUnderstand="0" xmlns:pr="http://webservices.temp.com/ProxyService">
<pr:user>sec5</pr:user>
<pr:password>ss</pr:password>
</pr:authentication>
</soapenv:Header>
<soapenv:Body>
<open:clientRequest xmlns:open="http://www.oly.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:EaiEnvelope xmlns:env="http://eai.ttt.pp.hh">
<env:Language>en</env:Language>
<env:UserId>admc</env:UserId>
<env:Payload>
<ss:security xmlns:ss="http://eai.admc.kyt/security">
<ss:Request>
<ss:Operation_Name>securityrem</ss:Operation_Name>
<ss:customerID>
<ss:no>9875452</ss:no>
<ss:Service_Type>gsm</ss:Service_Type>
</ss:customerID>
<ss:customer>
<ss:isCredit>false</ss:isCredit>
<ss:Amount>100000</ss:Amount>
<ss:transaction_Id>4301298</ss:transaction_Id>
<ss:TransactionTypeID>228</ss:TransactionTypeID>
<!--<ss:DeductionPriorityCode>2</ss:DeductionPriorityCode>-->
</ss:customer>
</ss:Request>
</ss:security>
</env:Payload>
</env:EaiEnvelope>
</open:clientRequest>
</soapenv:Body>
</soapenv:Envelope>
<强>的XQuery 强>
declare namespace emp="http://uri.open.gen/com";
declare namespace pr="http://webservices.temp.com/ProxyService";
declare namespace soapenv="http://schemas.xmlsoap.org/soap/envelope/";
declare namespace open="http://www.oly.org/";
declare namespace env="http://eai.ttt.pp.hh";
declare function local:ident($node as node()) {
if ($node instance of element()) then
if (namespace-uri($node) = 'http://eai.admc.kyt/security') then
local:change-ss($node)
else
element {$node/name()} {$node/@*,
for $child in $node/node() return local:ident($child)}
else if ($node instance of attribute()) then
if (namespace-uri($node) = 'http://eai.admc.kyt/security') then
local:change-ss($node)
else
$node
else if ($node instance of comment()) then
local:change-ss($node)
else
$node
};
declare function local:change-ss($node as node()) {
if ($node instance of element()) then
element {xs:QName(concat('emp:',$node/local-name()))} {
for $node in $node/(@*|node())
return
local:ident($node)
}
else if ($node instance of attribute()) then
attribute {xs:QName(concat('emp:',$node/local-name()))} {$node}
else if ($node instance of comment()) then
comment {replace($node,'(</?)ss:','$1emp:')}
else
$node
};
local:ident(/*)
XML输出
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<pr:authentication xmlns:pr="http://webservices.temp.com/ProxyService"
soapenv:her="http://schemas.xmlsoap.org/soap/her/next"
soapenv:mustUnderstand="0">
<pr:user>sec5</pr:user>
<pr:password>ss</pr:password>
</pr:authentication>
</soapenv:Header>
<soapenv:Body>
<open:clientRequest xmlns:open="http://www.oly.org/">
<env:EaiEnvelope xmlns:env="http://eai.ttt.pp.hh">
<env:Language>en</env:Language>
<env:UserId>admc</env:UserId>
<env:Payload>
<emp:security xmlns:emp="http://uri.open.gen/com">
<emp:Request>
<emp:Operation_Name>securityrem</emp:Operation_Name>
<emp:customerID>
<emp:no>9875452</emp:no>
<emp:Service_Type>gsm</emp:Service_Type>
</emp:customerID>
<emp:customer>
<emp:isCredit>false</emp:isCredit>
<emp:Amount>100000</emp:Amount>
<emp:transaction_Id>4301298</emp:transaction_Id>
<emp:TransactionTypeID>228</emp:TransactionTypeID>
<!--<emp:DeductionPriorityCode>2</emp:DeductionPriorityCode>-->
</emp:customer>
</emp:Request>
</emp:security>
</env:Payload>
</env:EaiEnvelope>
</open:clientRequest>
</soapenv:Body>
</soapenv:Envelope>
可以组合2个XQuery函数使其更小,但我认为它更具可读性。