wso2 / product-ei

An open source, a high-performance hybrid integration platform that allows developers quick integration with any application, data, or system.
https://wso2.com/integration/
Apache License 2.0
374 stars 280 forks source link

JSON Payload Reloaded via Enrich Mediator not as JSON format #5079

Closed vanjikumaran closed 1 month ago

vanjikumaran commented 4 years ago

Description: JSON Payload Reloaded via Enrich Mediator not as JSON format

Suggested Labels:

Suggested Assignees:

Affected Product Version: EI 6.6.0 OS, DB, other environment details and versions:
ProductName: Mac OS X ProductVersion: 10.15.4 BuildVersion: 19E287

openjdk version "11.0.6" 2020-01-14 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.6+10, mixed mode)

Steps to reproduce:

<api xmlns="http://ws.apache.org/ns/synapse" name="LasloTheGreat" context="/laslo">
   <resource methods="POST" url-mapping="/great">
      <inSequence>
         <enrich>
            <source type="body" clone="true"/>
            <target type="property" property="prop1"/>
         </enrich>
         <log>
            <property name="bla" expression="get-property('prop1')"/>
         </log>
         <payloadFactory media-type="xml">
            <format>
               <a xmlns="">sadfa</a>
            </format>
            <args/>
         </payloadFactory>
         <log level="full">
            <property name="a" value="========================="/>
         </log>
         <enrich>
            <source type="property" clone="true" property="prop1"/>
            <target type="body"/>
         </enrich>
         <respond/>
      </inSequence>
   </resource>
</api>                        

Request

curl --location --request POST 'http://192.168.0.35:8280/laslo/great' \
--header 'Content-Type: application/json' \
--data-raw '{
    "customerID": "1",
    "shipTo": "LK",
    "purchaseProducts": [
        {
            "productId": "1",
            "qty": "16.55"
        },
        {
            "productId": "2",
            "qty": "122.55"
        },
        {
            "productId": "3",
            "qty": "3.55"
        }
        ]
}'

Logs

[2020-05-04 10:06:04,411] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /laslo/great, MessageID: urn:uuid:57338598-52fa-4f03-accc-0b5422e15af3, Direction: request, bla = {"customerID":"1","shipTo":"LK","purchaseProducts":[{"productId":"1","qty":"16.55"},{"productId":"2","qty":"122.55"},{"productId":"3","qty":"3.55"}]} [2020-05-04 10:06:04,607] INFO {org.apache.synapse.mediators.builtin.LogMediator} - To: /laslo/great, MessageID: urn:uuid:57338598-52fa-4f03-accc-0b5422e15af3, Direction: request, a = =========================, Envelope: <?xml version='1.0' encoding='utf-8'?>sadfa</soapenv:Body></soapenv:Envelope>

Response

<jsonObject>
    <customerID>1</customerID>
    <shipTo>LK</shipTo>
    <purchaseProducts>
        <productId>1</productId>
        <qty>16.55</qty>
    </purchaseProducts>
    <purchaseProducts>
        <productId>2</productId>
        <qty>122.55</qty>
    </purchaseProducts>
    <purchaseProducts>
        <productId>3</productId>
        <qty>3.55</qty>
    </purchaseProducts>
</jsonObject>

Related Issues:

GDLMadushanka commented 4 years ago

Explanation of the current flow: In the given API, at the end of XML PayloadFactory we are adding "application/xml" as message-type and content-type headers. In enrich mediator, we are not doing such header changes. So the final header is "application/xml" and result is responded as XML.

vanjikumaran commented 4 years ago

However, there is a need for identifying the payload that is been loaded back into the message context.

lpastor74 commented 4 years ago

Is this been addressed or fixed?