WSO2代理服务“InSequence”错误地发送请求而不是API的响应

时间:2015-02-03 10:18:48

标签: wso2 wso2esb synapse wso2-am

我在以下代理的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>$1</ack:productName>
                        <ack:productSize>$2</ack:productSize>
                        <ack:productColour>$3</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服务(在Application Server上),但是,在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

1 个答案:

答案 0 :(得分:1)

您的代理收到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请求,可以指定属性格式=&#34; soap11&#34;在您的端点def(ackServiceEpr)中或在发送之前在inSequence中添加一个属性:

<property name="messageType" value="text/xml" scope="axis2"/>

在这种情况下,您可能需要设置SOAPAction,使用header mediator。如果你想设置一个空白的:

<header name="Action" value="&quot;&quot;"/>

如果你的ack服务需要普通的xml,请使用application / xml