[Dev] [ESB 5] Access Response JSON Payload in a Class Mediator

2016-10-27 Thread Isuru Haththotuwa
Hi,

How to do $subject? Need to modify the response payload from BE and send it
to the client.

Tried [1], but did not work.

[1].
   String jsonPayloadToString = JsonUtil
.jsonPayloadToString(((Axis2MessageContext)
messageContext)
.getAxis2MessageContext());
try {
JsonUtil.getNewJsonPayload(((Axis2MessageContext)
messageContext).getAxis2MessageContext(),
jsonPayloadToString, true, true);
} catch (AxisFault axisFault) {
log.error("Error building aggregated JSON payload",
axisFault);
return false;
}

-- 
Thanks and Regards,

Isuru H.
+94 716 358 048* *
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] [ESB 5] Access Response JSON Payload in a Class Mediator

2016-10-27 Thread Rajith Vitharana
Hi Isuru,

Below [1] worked for me to retrieve jsonbody. And then to set it back, what
you did worked for me. IE [2]

[1] - StringBuilder json =
JsonUtil.toJsonString(synCtx.getEnvelope().getBody());
[2] - JsonUtil.getNewJsonPayload(
((Axis2MessageContext) synCtx).getAxis2MessageContext(),
transformedJson, true, true);

Thanks,

On 27 October 2016 at 17:55, Isuru Haththotuwa  wrote:

> Hi,
>
> How to do $subject? Need to modify the response payload from BE and send
> it to the client.
>
> Tried [1], but did not work.
>
> [1].
>String jsonPayloadToString = JsonUtil
> .jsonPayloadToString(((Axis2MessageContext)
> messageContext)
> .getAxis2MessageContext());
> try {
> JsonUtil.getNewJsonPayload(((Axis2MessageContext)
> messageContext).getAxis2MessageContext(),
> jsonPayloadToString, true, true);
> } catch (AxisFault axisFault) {
> log.error("Error building aggregated JSON payload",
> axisFault);
> return false;
> }
>
> --
> Thanks and Regards,
>
> Isuru H.
> +94 716 358 048* *
>
>
>
> ___
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Rajith Vitharana

Senior Software Engineer,
WSO2 Inc. : wso2.com
Mobile : +94715883223
Blog : http://lankavitharana.blogspot.com/

___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] [ESB 5] Access Response JSON Payload in a Class Mediator

2016-10-27 Thread Rajkumar Rajaratnam
Hi Isuru,

I think you have to build the message first and call jsonPayloadToString().
Try this.

try {
   RelayUtils.buildMessage(a2mc);
} catch (IOException | XMLStreamException e) {
   log.error("Error occurred while building the message", e);
}

JsonUtil.jsonPayloadToString(a2mc);

Also make sure you are using
org.apache.synapse.commons.json.JsonStreamFormatter/org.apache.synapse.commons.json.JsonStreamBuilder
for application/json.

Thanks,
Raj.

On Thu, Oct 27, 2016 at 9:28 AM, Rajith Vitharana  wrote:

> Hi Isuru,
>
> Below [1] worked for me to retrieve jsonbody. And then to set it back,
> what you did worked for me. IE [2]
>
> [1] - StringBuilder json = JsonUtil.toJsonString(synCtx.
> getEnvelope().getBody());
> [2] - JsonUtil.getNewJsonPayload(
> ((Axis2MessageContext) synCtx).
> getAxis2MessageContext(),
> transformedJson, true, true);
>
> Thanks,
>
> On 27 October 2016 at 17:55, Isuru Haththotuwa  wrote:
>
>> Hi,
>>
>> How to do $subject? Need to modify the response payload from BE and send
>> it to the client.
>>
>> Tried [1], but did not work.
>>
>> [1].
>>String jsonPayloadToString = JsonUtil
>> .jsonPayloadToString(((Axis2MessageContext)
>> messageContext)
>> .getAxis2MessageContext());
>> try {
>> JsonUtil.getNewJsonPayload(((Axis2MessageContext)
>> messageContext).getAxis2MessageContext(),
>> jsonPayloadToString, true, true);
>> } catch (AxisFault axisFault) {
>> log.error("Error building aggregated JSON payload",
>> axisFault);
>> return false;
>> }
>>
>> --
>> Thanks and Regards,
>>
>> Isuru H.
>> +94 716 358 048* *
>>
>>
>>
>> ___
>> Dev mailing list
>> Dev@wso2.org
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Rajith Vitharana
>
> Senior Software Engineer,
> WSO2 Inc. : wso2.com
> Mobile : +94715883223
> Blog : http://lankavitharana.blogspot.com/
> 
>
> ___
> Dev mailing list
> Dev@wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
Rajkumar Rajaratnam
Committer & PMC Member, Apache Stratos
Senior Software Engineer, WSO2

Mobile : +94777568639
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] [ESB 5] Access Response JSON Payload in a Class Mediator

2016-10-27 Thread Rajkumar Rajaratnam
On Thu, Oct 27, 2016 at 9:42 AM, Rajkumar Rajaratnam 
wrote:

> Hi Isuru,
>
> I think you have to build the message first and call
> jsonPayloadToString(). Try this.
>
> try {
>RelayUtils.buildMessage(a2mc);
> } catch (IOException | XMLStreamException e) {
>log.error("Error occurred while building the message", e);
> }
>
> JsonUtil.jsonPayloadToString(a2mc);
>

​This code worked for me in AM 1.10. ​


>
>
> Also make sure you are using org.apache.synapse.commons.json.
> JsonStreamFormatter/org.apache.synapse.commons.json.JsonStreamBuilder for
> application/json.
>
> Thanks,
> Raj.
>
> On Thu, Oct 27, 2016 at 9:28 AM, Rajith Vitharana 
> wrote:
>
>> Hi Isuru,
>>
>> Below [1] worked for me to retrieve jsonbody. And then to set it back,
>> what you did worked for me. IE [2]
>>
>> [1] - StringBuilder json = JsonUtil.toJsonString(synCtx.g
>> etEnvelope().getBody());
>> [2] - JsonUtil.getNewJsonPayload(
>> ((Axis2MessageContext) synCtx).getAxis2MessageContext
>> (),
>> transformedJson, true, true);
>>
>> Thanks,
>>
>> On 27 October 2016 at 17:55, Isuru Haththotuwa  wrote:
>>
>>> Hi,
>>>
>>> How to do $subject? Need to modify the response payload from BE and send
>>> it to the client.
>>>
>>> Tried [1], but did not work.
>>>
>>> [1].
>>>String jsonPayloadToString = JsonUtil
>>> .jsonPayloadToString(((Axis2MessageContext)
>>> messageContext)
>>> .getAxis2MessageContext());
>>> try {
>>> JsonUtil.getNewJsonPayload(((Axis2MessageContext)
>>> messageContext).getAxis2MessageContext(),
>>> jsonPayloadToString, true, true);
>>> } catch (AxisFault axisFault) {
>>> log.error("Error building aggregated JSON payload",
>>> axisFault);
>>> return false;
>>> }
>>>
>>> --
>>> Thanks and Regards,
>>>
>>> Isuru H.
>>> +94 716 358 048* *
>>>
>>>
>>>
>>> ___
>>> Dev mailing list
>>> Dev@wso2.org
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>> Rajith Vitharana
>>
>> Senior Software Engineer,
>> WSO2 Inc. : wso2.com
>> Mobile : +94715883223
>> Blog : http://lankavitharana.blogspot.com/
>> 
>>
>> ___
>> Dev mailing list
>> Dev@wso2.org
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Rajkumar Rajaratnam
> Committer & PMC Member, Apache Stratos
> Senior Software Engineer, WSO2
>
> Mobile : +94777568639
>



-- 
Rajkumar Rajaratnam
Committer & PMC Member, Apache Stratos
Senior Software Engineer, WSO2

Mobile : +94777568639
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


Re: [Dev] [ESB 5] Access Response JSON Payload in a Class Mediator

2016-10-30 Thread Isuru Haththotuwa
Hi Rajith/Raj,

Thanks for the responses. Both methods worked for me, and yes you need to
build the message first.

On Thu, Oct 27, 2016 at 7:16 PM, Rajkumar Rajaratnam 
wrote:

>
>
> On Thu, Oct 27, 2016 at 9:42 AM, Rajkumar Rajaratnam 
> wrote:
>
>> Hi Isuru,
>>
>> I think you have to build the message first and call
>> jsonPayloadToString(). Try this.
>>
>> try {
>>RelayUtils.buildMessage(a2mc);
>> } catch (IOException | XMLStreamException e) {
>>log.error("Error occurred while building the message", e);
>> }
>>
>> JsonUtil.jsonPayloadToString(a2mc);
>>
>
> ​This code worked for me in AM 1.10. ​
>
>
>>
>>
>> Also make sure you are using org.apache.synapse.commo
>> ns.json.JsonStreamFormatter/org.apache.synapse.commons.json.JsonStreamBuilder
>> for application/json.
>>
>> Thanks,
>> Raj.
>>
>> On Thu, Oct 27, 2016 at 9:28 AM, Rajith Vitharana 
>> wrote:
>>
>>> Hi Isuru,
>>>
>>> Below [1] worked for me to retrieve jsonbody. And then to set it back,
>>> what you did worked for me. IE [2]
>>>
>>> [1] - StringBuilder json = JsonUtil.toJsonString(synCtx.g
>>> etEnvelope().getBody());
>>> [2] - JsonUtil.getNewJsonPayload(
>>> ((Axis2MessageContext) synCtx).getAxis2MessageContext
>>> (),
>>> transformedJson, true, true);
>>>
>>> Thanks,
>>>
>>> On 27 October 2016 at 17:55, Isuru Haththotuwa  wrote:
>>>
 Hi,

 How to do $subject? Need to modify the response payload from BE and
 send it to the client.

 Tried [1], but did not work.

 [1].
String jsonPayloadToString = JsonUtil
 .jsonPayloadToString(((Axis2MessageContext)
 messageContext)
 .getAxis2MessageContext());
 try {
 JsonUtil.getNewJsonPayload(((Axis2MessageContext)
 messageContext).getAxis2MessageContext(),
 jsonPayloadToString, true, true);
 } catch (AxisFault axisFault) {
 log.error("Error building aggregated JSON payload",
 axisFault);
 return false;
 }

 --
 Thanks and Regards,

 Isuru H.
 +94 716 358 048* *



 ___
 Dev mailing list
 Dev@wso2.org
 http://wso2.org/cgi-bin/mailman/listinfo/dev


>>>
>>>
>>> --
>>> Rajith Vitharana
>>>
>>> Senior Software Engineer,
>>> WSO2 Inc. : wso2.com
>>> Mobile : +94715883223
>>> Blog : http://lankavitharana.blogspot.com/
>>> 
>>>
>>> ___
>>> Dev mailing list
>>> Dev@wso2.org
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>> Rajkumar Rajaratnam
>> Committer & PMC Member, Apache Stratos
>> Senior Software Engineer, WSO2
>>
>> Mobile : +94777568639
>>
>
>
>
> --
> Rajkumar Rajaratnam
> Committer & PMC Member, Apache Stratos
> Senior Software Engineer, WSO2
>
> Mobile : +94777568639
>



-- 
Thanks and Regards,

Isuru H.
+94 716 358 048* *
___
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev