WSO2 代理服务 "InSequence" 错误地发送请求而不是 API 的响应
WSO2 Proxy Service "InSequence" incorrectly sending a request instead of a response for API
我在以下代理的 In Sequnce 中遇到问题:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="AckServiceAPIProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="json-xml" value="text/xml" scope="axis2" type="STRING"/>
<log level="full" category="DEBUG" separator="____:____"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="name"
expression="//productSearch/productName/text()"
scope="default"
type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="size"
expression="//productSearch/productSize/text()"
scope="default"
type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="colour"
expression="//productSearch/productColour/text()"
scope="default"
type="STRING"/>
<payloadFactory media-type="xml">
<format>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ack="http://ack.pepkor.org">
<soap:Header/>
<soap:Body>
<ack:productSearch>
<ack:productName></ack:productName>
<ack:productSize></ack:productSize>
<ack:productColour></ack:productColour>
</ack:productSearch>
</soap:Body>
</soap:Envelope>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd"
expression="$ctx:name"
evaluator="xml"/>
<arg xmlns:ns="http://org.apache.synapse/xsd"
expression="$ctx:size"
evaluator="xml"/>
<arg xmlns:ns="http://org.apache.synapse/xsd"
expression="$ctx:colour"
evaluator="xml"/>
</args>
</payloadFactory>
<log level="full" category="DEBUG" separator="____:____"/>
<send>
<endpoint key="conf:/ackServiceEpr"/>
</send>
</inSequence>
<outSequence>
<log level="full" category="DEBUG" separator="____:____"/>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<log level="full" category="DEBUG" separator="____:____"/>
<send/>
</outSequence>
<faultSequence/>
</target>
<description/>
</proxy>
REST 请求:
{ "productSearch":
{ "productName": "nike_shirts" ,
"productSize": "7",
"productColour": "red"
}
}
让我分解日志:
TID: [0] [ESB] [2015-02-03 11:56:14,994] DEBUG {org.apache.synapse.commons.json.JsonStreamBuilder} - #processDocument. Built JSON payload from JSON stream. MessageID: urn:uuid:0d62c4ad-01b5-4eb5-ae7e-3b3aee762fbf {org.apache.synapse.commons.json.JsonStreamBuilder}
...
#mediate. Transformed payload format>>>
<pfPadding>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ack="http://ack.pepkor.org"><soap:Header></soap:Header><soap:Body><ack:productSearch><ack:productName>nike_shirts</ack:productName><ack:productSize>7</ack:productSize><ack:productColour>red</ack:productColour></ack:productSearch></soap:Body></soap:Envelope></pfPadding>
因此,我希望将上述消息发送到 Ack 服务(在应用程序服务器上),但是,在 SEND 调解器内部,它再次转换原始请求负载 (REST),并将其发送到服务:
<productSearch><productName>nike_shirts</productName><productSize>7</productSize><productColour>red</productColour></productSearch>
由于没有命名空间,服务调用失败,并返回错误。
发送中介完整日志:
Start : Send mediator {org.apache.synapse.mediators.builtin.SendMediator}
TID: [0] [ESB] [2015-02-03 12:08:34,896] DEBUG {org.apache.synapse.endpoints.EndpointContext} - Checking if endpoint : AnonymousEndpoint currently at state ACTIVE can be used now? {org.apache.synapse.endpoints.EndpointContext}
TID: [0] [ESB] [2015-02-03 12:08:34,896] DEBUG {org.apache.synapse.endpoints.AddressEndpoint} - Sending message through endpoint : null resolving to address = https://localhost:9444/services/ProductSearchACKService.ProductSearchACKServiceHttpsSoap12Endpoint/ {org.apache.synapse.endpoints.AddressEndpoint}
TID: [0] [ESB] [2015-02-03 12:08:34,896] DEBUG {org.apache.synapse.endpoints.AddressEndpoint} - SOAPAction: null {org.apache.synapse.endpoints.AddressEndpoint}
TID: [0] [ESB] [2015-02-03 12:08:34,897] DEBUG {org.apache.synapse.endpoints.AddressEndpoint} - WSA-Action: null {org.apache.synapse.endpoints.AddressEndpoint}
TID: [0] [ESB] [2015-02-03 12:08:34,897] DEBUG {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient} - Sending [add = false] [sec = false] [rm = false] [mtom = false] [swa = false] [format = null] [force soap11=false] [force soap12=false] [pox=false] [get=false] [encoding=null] [to=https://localhost:9444/services/ProductSearchACKService.ProductSearchACKServiceHttpsSoap12Endpoint/] {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient}
TID: [0] [ESB] [2015-02-03 12:08:34,898] DEBUG {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient} - Message [Original Request Message ID : urn:uuid:a451c7d8-b5a9-4474-8bd3-af9a25b65933] [New Cloned Request Message ID : urn:uuid:b0540f15-2094-4c3e-9184-fdc2df2fd491] {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient}
TID: [0] [ESB] [2015-02-03 12:08:34,898] DEBUG {org.apache.synapse.core.axis2.SynapseCallbackReceiver} - Callback added. Total callbacks waiting for : 1 {org.apache.synapse.core.axis2.SynapseCallbackReceiver}
TID: [0] [ESB] [2015-02-03 12:08:34,900] DEBUG {org.apache.synapse.commons.json.JsonUtil} - #transformElement. Transformed OMElement. Result: <productSearch><productName>nike_shirts</productName><productSize>7</productSize><productColour>red</productColour></productSearch> {org.apache.synapse.commons.json.JsonUtil}
TID: [0] [ESB] [2015-02-03 12:08:34,901] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #XmlReaderDelegate. Setting XMLStreamReader: com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,902] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSearch, new=productSearch {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,903] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productName, new=productName {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,903] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productName, new=productName {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,904] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSize, new=productSize {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,904] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSize, new=productSize {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,904] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productColour, new=productColour {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,905] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productColour, new=productColour {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,905] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSearch, new=productSearch {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,905] DEBUG {org.apache.synapse.commons.json.JsonStreamFormatter} - #writeTo. Wrote JSON payload to output stream. MessageID: urn:uuid:b0540f15-2094-4c3e-9184-fdc2df2fd491 {org.apache.synapse.commons.json.JsonStreamFormatter}
TID: [0] [ESB] [2015-02-03 12:08:34,906] DEBUG {org.apache.synapse.mediators.builtin.SendMediator} - End : Send mediator
.
您的代理收到一个 JSON 请求并且您没有为输出指定任何内容,因此 ESB 向您的 ack 服务发送一个 JSON 请求(参见日志跟踪 #writeTo. Wrote JSON payload to output stream. MessageID: urn:uuid:b0540f15-2094-4c3e-9184-fdc2df2fd491 {org.apache.synapse.commons.json.JsonStreamFormatter}
)
如果你想发送一个 SOAP 请求,你可以在你的端点 def (ackServiceEpr) 中指定属性 format="soap11" 或者在你的 inSequence 中添加一个 属性,然后发送:
<property name="messageType" value="text/xml" scope="axis2"/>
在这种情况下,也许您需要设置 SOAPAction,请使用 header 调解器。如果你想设置一个空白:
<header name="Action" value=""""/>
如果您的 ack 服务需要纯 xml,请使用 application/xml
我在以下代理的 In Sequnce 中遇到问题:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="AckServiceAPIProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="json-xml" value="text/xml" scope="axis2" type="STRING"/>
<log level="full" category="DEBUG" separator="____:____"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="name"
expression="//productSearch/productName/text()"
scope="default"
type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="size"
expression="//productSearch/productSize/text()"
scope="default"
type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="colour"
expression="//productSearch/productColour/text()"
scope="default"
type="STRING"/>
<payloadFactory media-type="xml">
<format>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ack="http://ack.pepkor.org">
<soap:Header/>
<soap:Body>
<ack:productSearch>
<ack:productName></ack:productName>
<ack:productSize></ack:productSize>
<ack:productColour></ack:productColour>
</ack:productSearch>
</soap:Body>
</soap:Envelope>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd"
expression="$ctx:name"
evaluator="xml"/>
<arg xmlns:ns="http://org.apache.synapse/xsd"
expression="$ctx:size"
evaluator="xml"/>
<arg xmlns:ns="http://org.apache.synapse/xsd"
expression="$ctx:colour"
evaluator="xml"/>
</args>
</payloadFactory>
<log level="full" category="DEBUG" separator="____:____"/>
<send>
<endpoint key="conf:/ackServiceEpr"/>
</send>
</inSequence>
<outSequence>
<log level="full" category="DEBUG" separator="____:____"/>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<log level="full" category="DEBUG" separator="____:____"/>
<send/>
</outSequence>
<faultSequence/>
</target>
<description/>
</proxy>
REST 请求:
{ "productSearch":
{ "productName": "nike_shirts" ,
"productSize": "7",
"productColour": "red"
}
}
让我分解日志:
TID: [0] [ESB] [2015-02-03 11:56:14,994] DEBUG {org.apache.synapse.commons.json.JsonStreamBuilder} - #processDocument. Built JSON payload from JSON stream. MessageID: urn:uuid:0d62c4ad-01b5-4eb5-ae7e-3b3aee762fbf {org.apache.synapse.commons.json.JsonStreamBuilder}
...
#mediate. Transformed payload format>>>
<pfPadding>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ack="http://ack.pepkor.org"><soap:Header></soap:Header><soap:Body><ack:productSearch><ack:productName>nike_shirts</ack:productName><ack:productSize>7</ack:productSize><ack:productColour>red</ack:productColour></ack:productSearch></soap:Body></soap:Envelope></pfPadding>
因此,我希望将上述消息发送到 Ack 服务(在应用程序服务器上),但是,在 SEND 调解器内部,它再次转换原始请求负载 (REST),并将其发送到服务:
<productSearch><productName>nike_shirts</productName><productSize>7</productSize><productColour>red</productColour></productSearch>
由于没有命名空间,服务调用失败,并返回错误。
发送中介完整日志:
Start : Send mediator {org.apache.synapse.mediators.builtin.SendMediator}
TID: [0] [ESB] [2015-02-03 12:08:34,896] DEBUG {org.apache.synapse.endpoints.EndpointContext} - Checking if endpoint : AnonymousEndpoint currently at state ACTIVE can be used now? {org.apache.synapse.endpoints.EndpointContext}
TID: [0] [ESB] [2015-02-03 12:08:34,896] DEBUG {org.apache.synapse.endpoints.AddressEndpoint} - Sending message through endpoint : null resolving to address = https://localhost:9444/services/ProductSearchACKService.ProductSearchACKServiceHttpsSoap12Endpoint/ {org.apache.synapse.endpoints.AddressEndpoint}
TID: [0] [ESB] [2015-02-03 12:08:34,896] DEBUG {org.apache.synapse.endpoints.AddressEndpoint} - SOAPAction: null {org.apache.synapse.endpoints.AddressEndpoint}
TID: [0] [ESB] [2015-02-03 12:08:34,897] DEBUG {org.apache.synapse.endpoints.AddressEndpoint} - WSA-Action: null {org.apache.synapse.endpoints.AddressEndpoint}
TID: [0] [ESB] [2015-02-03 12:08:34,897] DEBUG {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient} - Sending [add = false] [sec = false] [rm = false] [mtom = false] [swa = false] [format = null] [force soap11=false] [force soap12=false] [pox=false] [get=false] [encoding=null] [to=https://localhost:9444/services/ProductSearchACKService.ProductSearchACKServiceHttpsSoap12Endpoint/] {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient}
TID: [0] [ESB] [2015-02-03 12:08:34,898] DEBUG {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient} - Message [Original Request Message ID : urn:uuid:a451c7d8-b5a9-4474-8bd3-af9a25b65933] [New Cloned Request Message ID : urn:uuid:b0540f15-2094-4c3e-9184-fdc2df2fd491] {org.apache.synapse.core.axis2.Axis2FlexibleMEPClient}
TID: [0] [ESB] [2015-02-03 12:08:34,898] DEBUG {org.apache.synapse.core.axis2.SynapseCallbackReceiver} - Callback added. Total callbacks waiting for : 1 {org.apache.synapse.core.axis2.SynapseCallbackReceiver}
TID: [0] [ESB] [2015-02-03 12:08:34,900] DEBUG {org.apache.synapse.commons.json.JsonUtil} - #transformElement. Transformed OMElement. Result: <productSearch><productName>nike_shirts</productName><productSize>7</productSize><productColour>red</productColour></productSearch> {org.apache.synapse.commons.json.JsonUtil}
TID: [0] [ESB] [2015-02-03 12:08:34,901] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #XmlReaderDelegate. Setting XMLStreamReader: com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,902] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSearch, new=productSearch {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,903] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productName, new=productName {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,903] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productName, new=productName {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,904] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSize, new=productSize {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,904] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSize, new=productSize {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,904] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productColour, new=productColour {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,905] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productColour, new=productColour {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,905] DEBUG {org.apache.synapse.commons.json.XmlReaderDelegate} - #getLocalName. old=productSearch, new=productSearch {org.apache.synapse.commons.json.XmlReaderDelegate}
TID: [0] [ESB] [2015-02-03 12:08:34,905] DEBUG {org.apache.synapse.commons.json.JsonStreamFormatter} - #writeTo. Wrote JSON payload to output stream. MessageID: urn:uuid:b0540f15-2094-4c3e-9184-fdc2df2fd491 {org.apache.synapse.commons.json.JsonStreamFormatter}
TID: [0] [ESB] [2015-02-03 12:08:34,906] DEBUG {org.apache.synapse.mediators.builtin.SendMediator} - End : Send mediator
.
您的代理收到一个 JSON 请求并且您没有为输出指定任何内容,因此 ESB 向您的 ack 服务发送一个 JSON 请求(参见日志跟踪 #writeTo. Wrote JSON payload to output stream. MessageID: urn:uuid:b0540f15-2094-4c3e-9184-fdc2df2fd491 {org.apache.synapse.commons.json.JsonStreamFormatter}
)
如果你想发送一个 SOAP 请求,你可以在你的端点 def (ackServiceEpr) 中指定属性 format="soap11" 或者在你的 inSequence 中添加一个 属性,然后发送:
<property name="messageType" value="text/xml" scope="axis2"/>
在这种情况下,也许您需要设置 SOAPAction,请使用 header 调解器。如果你想设置一个空白:
<header name="Action" value=""""/>
如果您的 ack 服务需要纯 xml,请使用 application/xml