您可以使用Header Mediator为 SOAP Header 指定您自己的 XML。从 ESB 4.5.0 开始支持此功能。
只需在<header>
.
您可以使用源视图或用户界面来定义代理。如果您在 Eclipse 上试用,它可能不支持这个新特性。我必须检查一下。
但是您可以只使用独立的 ESB 产品定义一个代理。
这是我刚刚使用 WSO2 ESB 4.6.0 测试的示例代理。
<proxy name="Test"
transports="https http"
startOnLoad="true"
trace="disable">
<target>
<inSequence>
<header>
<p1:Header xmlns:p1="http://www.XYZ.com/XSD">
<p1:Version>1.5</p1:Version>
<p1:Code>XYZ</p1:Code>
<p1:Type>ABC</p1:Type>
<p1:Ver>1.1/1.2</p1:Ver>
<p1:Org>DIS</p1:Org>
</p1:Header>
</header>
<send>
<endpoint>
<address uri="http://localhost:8899/services/SimpleStockQuoteService?wsdl"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<header>
<p2:Header xmlns:p2="http://www.ABC.com/XSD">
<p2:Hello>World</p2:Hello>
</p2:Header>
</header>
<send/>
</outSequence>
</target>
<publishWSDL uri="http://localhost:8899/services/SimpleStockQuoteService?wsdl"/>
</proxy>
以下是如何从 WSO2 ESB 发送请求并返回响应
要求:
POST /services/SimpleStockQuoteService?wsdl HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml; charset=UTF-8
SOAPAction: "urn:getQuote"
userAgent: Synapse-PT-HttpComponents-NIO
Transfer-Encoding: chunked
Host: 127.0.0.1:8899
Connection: Keep-Alive
2f3
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://services.samples/xsd" xmlns:ser="http://services.samples">
<soapenv:Header><p1:Header xmlns:p1="http://www.XYZ.com/XSD">
<p1:Version>1.5</p1:Version>
<p1:Code>XYZ</p1:Code>
<p1:Type>ABC</p1:Type>
<p1:Ver>1.1/1.2</p1:Ver>
<p1:Org>DIS</p1:Org>
</p1:Header></soapenv:Header>
<soapenv:Body>
<ser:getQuote>
<!--Optional:-->
<ser:request>
<!--Optional:-->
<xsd:symbol>WSO2</xsd:symbol>
</ser:request>
</ser:getQuote>
</soapenv:Body>
</soapenv:Envelope>
0
回复:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<p2:Header xmlns:p2="http://www.ABC.com/XSD">
<p2:Hello>World</p2:Hello>
</p2:Header>
</soapenv:Header>
<soapenv:Body>
<ns:getQuoteResponse xmlns:ns="http://services.samples">
<ns:return xsi:type="ax21:GetQuoteResponse" xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ax21:change>4.14429919417878</ax21:change>
<ax21:earnings>13.29119739059685</ax21:earnings>
<ax21:high>-84.84231581484899</ax21:high>
<ax21:last>85.60273864169663</ax21:last>
<ax21:lastTradeTimestamp>Sun Jul 28 00:31:19 IST 2013</ax21:lastTradeTimestamp>
<ax21:low>88.1046394678485</ax21:low>
<ax21:marketCap>-6540210.216549877</ax21:marketCap>
<ax21:name>WSO2 Company</ax21:name>
<ax21:open>89.52770935798549</ax21:open>
<ax21:peRatio>24.07637499909879</ax21:peRatio>
<ax21:percentageChange>-5.198506483420408</ax21:percentageChange>
<ax21:prevClose>-79.72095845982282</ax21:prevClose>
<ax21:symbol>WSO2</ax21:symbol>
<ax21:volume>9801</ax21:volume>
</ns:return>
</ns:getQuoteResponse>
</soapenv:Body>
</soapenv:Envelope>
注意<header>
标签中的值。
我希望这有帮助。
谢谢!