简体   繁体   中英

WSO2 ESB - sending unwanted empty JSON payload when passing through tier from backend

I am very new to WSO2 development so this could be an easy fix for someone!

I'm creating a demo API to familiarise myself more with WSO2 development. I'm currently stuck with passing a payload in ESB from a back-end (mocked using Wiremock) to another endpoint. I can see in the ESB logs that the payload is coming into ESB but it leaves as 0 or what I presume as empty.

Is there anything extra I should add? I'm just placing a send mediator within a switch statement (checking for HTTP status eg 200). I've played around with a payloadFactory but it does the same.

ESB log:

TID: [0] [ESB] [2018-03-28 15:56:48,652] DEBUG {org.apache.synapse.transport.http.wire} -  >> "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,652] DEBUG {org.apache.synapse.transport.http.wire} -  >> "{"result": 1}" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,699] DEBUG {org.apache.synapse.transport.http.wire} -  << "HTTP/1.1 200 OK[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,700] DEBUG {org.apache.synapse.transport.http.wire} -  << "CorrelationId: 685454f5-e5f6-4837-b0b0-1e9e53798ea9[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,700] DEBUG {org.apache.synapse.transport.http.wire} -  << "Content-Type: application/json[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,700] DEBUG {org.apache.synapse.transport.http.wire} -  << "Date: Wed, 28 Mar 2018 14:56:48 GMT[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,700] DEBUG {org.apache.synapse.transport.http.wire} -  << "Server: WSO2-PassThrough-HTTP[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,700] DEBUG {org.apache.synapse.transport.http.wire} -  << "Transfer-Encoding: chunked[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,700] DEBUG {org.apache.synapse.transport.http.wire} -  << "Connection: Keep-Alive[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,700] DEBUG {org.apache.synapse.transport.http.wire} -  << "[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,701] DEBUG {org.apache.synapse.transport.http.wire} -  << "0[\r][\n]" {org.apache.synapse.transport.http.wire}
TID: [0] [ESB] [2018-03-28 15:56:48,701] DEBUG {org.apache.synapse.transport.http.wire} -  << "[\r][\n]" {org.apache.synapse.transport.http.wire}

JSON Payload sent from wiremock to ESB:

{"result": 1}

I played around with using a payloadFactory but I got the same result regardless. I'll include the payloadFactory code I used if it helps:

<payloadFactory media-type="json">
<format>{"amount": $1}</format>
<args>
<arg evaluator="json" expression="$.result"/>
</args>
</payloadFactory>
<property name="messageType" value="application/json" scope="axis2"/>
<property name="contentType" value="application/json" scope="axis2"/>

Any help to solving this or things to try will be much appreciated!

尝试使用<arg evaluator="Xml" expression="//*[local-name()='result']"/>而不是<arg evaluator="json" expression="$.result"/>

I solved this in the end. Turned out to be a conflict between message builders in my axis2.xml properties so the message was never getting built correctly. Thanks for the suggestions anyway!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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