AriSan
AriSan

Reputation: 390

WSO2 payload factory appending additional field with JSON request

I am creating a JSON payload in WSO2 ESB. But recently I have noticed while hitting the endpoint, it is adding some extra field at the start and end of the message body. Thus the JSON structure is getting changed and as result failing to generate actual result. The extra field can not be seen from normal logs but if you enable http wire log, you can notice these fields. I am pasting the code below and also the wire logs.

    <payloadFactory media-type="json">
                        <format>
                                        {
        "ExtReference": "$8",
        "MemberSubType":{
            "MemberSubTypeId":"20",
            "Name":"DD"},
        "Region": "",        
        "PersonalDetails": {
            "FirstName": "$9",
            "LastName": "sample",
            "MiddleName": "",
            "DateOfBirth": "",
            "GenderType": "",
            "SalutationType":"",
            "MemberStatus":""
        },
        "Address": [{
            "AddressLine1": "$1",
            "AddressLine2": "$2",
            "HouseName": "",
            "HouseNumber": "",
            "Street": "",
            "Locality": "",
            "City": "$3",
            "County": "",
            "Zip": "$15",
            "CountryId": "NZ",
            "PostBox": "",
            "PostBoxNumber": ""
        }],
        "ContactDetails": [{
            "Email": "$5",
            "Phone": "$10",
            "MobilePhone": "$7",
            "Fax": "$6",
            "ContactDetailsType": ""
        }],
        "ExtensionData": [{
            "PropertyName":"", 
            "PropertyValue":""
            }]
}
                                    </format>
                        <args>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:addr1/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:addr2/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:city/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:country/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:email/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:fax/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:mobile/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:nSInternalID/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:name/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:phone/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:salesRep/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:state/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:territory/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:url/text()"/>
                           <arg evaluator="xml"
                                expression="//cus:addParentCustToJADERequest/cus:parentCustData/cus:zip/text()"/>
                        </args>
                     </payloadFactory>
                     <property name="messageType"
                               value="application/json"
                               scope="axis2"
                               type="STRING"/>
                     <log separator=", ****JSON_Request****">
                        <property name="toJSON" expression="json-eval($.)"/>
                     </log>
                     <call>
                        <endpoint>
                           <http method="post" uri-template="http://localhost:8281/scholasticapi/member"/>
                           <property name="Authorization"
                                     value="78ca6121-763c-41c6-8dfe-d73e761b9989;https://uat.snipp.ie/scholasticapi/member;Fri Jul 24 2015 15:03:02 GMT+0530 (India Standard Time);idiuOEsgiVQU2cJj2p2nawCEHGtyN1cIWzpHP+NlJm4="
                                     scope="transport"/>
                           <property name="Content-Type" value="application/json" scope="transport"/>
                        </endpoint>
                     </call>

while it is hitting the endpoint I logged the request enabling the wire.

[2015-07-30 19:15:23,854] DEBUG - wire << "[\r][\n]"
[2015-07-30 19:15:23,855] DEBUG - wire << "44d[\r][\n]"
[2015-07-30 19:15:23,855] DEBUG - wire << "{[\n]"
[2015-07-30 19:15:23,856] DEBUG - wire << "        "ExtReference": "4545",[\n]"
[2015-07-30 19:15:23,856] DEBUG - wire << "        "MemberSubType":{[\n]"
[2015-07-30 19:15:23,856] DEBUG - wire << "[0x9][0x9][0x9]"MemberSubTypeId":"20",[\n]"
[2015-07-30 19:15:23,861] DEBUG - wire << "[0x9][0x9][0x9]"Name":"DD"},[\n]"
[2015-07-30 19:15:23,861] DEBUG - wire << "        "Region": "",        [\n]"
[2015-07-30 19:15:23,862] DEBUG - wire << "        "PersonalDetails": {[\n]"
[2015-07-30 19:15:23,862] DEBUG - wire << "            "FirstName": "arisan",[\n]"
[2015-07-30 19:15:23,862] DEBUG - wire << "            "LastName": "sample",[\n]"
[2015-07-30 19:15:23,863] DEBUG - wire << "            "MiddleName": "",[\n]"
[2015-07-30 19:15:23,863] DEBUG - wire << "            "DateOfBirth": "",[\n]"
[2015-07-30 19:15:23,863] DEBUG - wire << "            "GenderType": "",[\n]"
[2015-07-30 19:15:23,863] DEBUG - wire << "            "SalutationType":"",[\n]"
[2015-07-30 19:15:23,864] DEBUG - wire << "            "MemberStatus":""[\n]"
[2015-07-30 19:15:23,864] DEBUG - wire << "        },[\n]"
[2015-07-30 19:15:23,864] DEBUG - wire << "        "Address": [{[\n]"
[2015-07-30 19:15:23,865] DEBUG - wire << "            "AddressLine1": "vfhd",[\n]"
[2015-07-30 19:15:23,865] DEBUG - wire << "            "AddressLine2": "jdfvbgkjfds",[\n]"
[2015-07-30 19:15:23,865] DEBUG - wire << "            "HouseName": "",[\n]"
[2015-07-30 19:15:23,865] DEBUG - wire << "            "HouseNumber": "",[\n]"
[2015-07-30 19:15:23,866] DEBUG - wire << "            "Street": "",[\n]"
[2015-07-30 19:15:23,866] DEBUG - wire << "            "Locality": "",[\n]"
[2015-07-30 19:15:23,866] DEBUG - wire << "            "City": "kolkata",[\n]"
[2015-07-30 19:15:23,866] DEBUG - wire << "            "County": "",[\n]"
[2015-07-30 19:15:23,867] DEBUG - wire << "            "Zip": "43543",[\n]"
[2015-07-30 19:15:23,867] DEBUG - wire << "            "CountryId": "NZ",[\n]"
[2015-07-30 19:15:23,867] DEBUG - wire << "            "PostBox": "",[\n]"
[2015-07-30 19:15:23,867] DEBUG - wire << "            "PostBoxNumber": ""[\n]"
[2015-07-30 19:15:23,868] DEBUG - wire << "        }],[\n]"
[2015-07-30 19:15:23,868] DEBUG - wire << "        "ContactDetails": [{[\n]"
[2015-07-30 19:15:23,868] DEBUG - wire << "            "Email": "[email protected]",[\n]"
[2015-07-30 19:15:23,868] DEBUG - wire << "            "Phone": "378654839674",[\n]"
[2015-07-30 19:15:23,869] DEBUG - wire << "            "MobilePhone": "87425343287",[\n]"
[2015-07-30 19:15:23,869] DEBUG - wire << "            "Fax": "345435",[\n]"
[2015-07-30 19:15:23,869] DEBUG - wire << "            "ContactDetailsType": ""[\n]"
[2015-07-30 19:15:23,869] DEBUG - wire << "        }],[\n]"
[2015-07-30 19:15:23,870] DEBUG - wire << "        "ExtensionData": [{[\n]"
[2015-07-30 19:15:23,870] DEBUG - wire << "[0x9][0x9][0x9]"PropertyName":"", [\n]"
[2015-07-30 19:15:23,870] DEBUG - wire << "[0x9][0x9][0x9]"PropertyValue":""[\n]"
[2015-07-30 19:15:23,870] DEBUG - wire << "[0x9][0x9][0x9]}][\n]"
[2015-07-30 19:15:23,871] DEBUG - wire << "}[\r][\n]"
[2015-07-30 19:15:23,871] DEBUG - wire << "0[\r][\n]"
[2015-07-30 19:15:23,871] DEBUG - wire << "[\r][\n]"

See in the 2nd line of the logs shows a value 44d and in the 2nd last line a value zero appended which has not been served anywhere in payload. I have confirmed from the system owner, that for these two junk values only the request is getting failed. Kindly suggest a way out to get reed of these two fields. Thanks in advance.

Upvotes: 1

Views: 878

Answers (2)

rohan
rohan

Reputation: 176

You can use: <property name="DISABLE_CHUNKING" value="true" scope="axis2"/> before sending your request to the backend server. This will work fine...

Upvotes: 1

Philippe Sevestre
Philippe Sevestre

Reputation: 974

This zero at the end is related to the way the payload is returned to the client, which is the "chunked" transfer.

( See: https://en.wikipedia.org/wiki/Chunked_transfer_encoding)

In short, the 44d is simply the number of bytes that is part if this "chunk". The last "0" implies that there are no more chunks.

Upvotes: 1

Related Questions