Hi Folks I am also getting this issue in APIM 1.8.0 too. I created an new API and navigate to the implementation page, then I have set my inline script like below,
mc.setProperty('CONTENT_TYPE', 'application/json'); var jsonPayLoad = mc.getPayloadJSON(); mc.setPayloadJSON(jsonPayLoad); After publishing the API, I send a curl POST request with sample json payload to the API, but I could not see the results as i expected, Instead it is given a empty bracket like this '{}'. Please note I have enabled below properties in my axis2.xml <messageFormatter contentType="application/json" class="org.apache.synapse.commons.json.JsonStreamFormatter"/> <messageBuilder contentType="application/json" class="org.apache.synapse.commons.json.JsonStreamBuilder"/> What could be the problem here? Regards Roshan. On Tue, Jan 13, 2015 at 7:37 AM, Maz Lakadia <mlaka...@hotmail.com> wrote: > Just in case someone has the same issue, I managed to get mine working. > > I had to do a workaround method: > > 1. Use property mediator before the script mediator to set a property: > <property name="JSONPayload" expression="json-eval($.)"/> > > 2. Within the script mediator, get the payload (as a string) by doing this: > var pl_string = mc.getProperty("JSONPayload"); > > 3. Now have to convert the string into a JS object: > var pl = JSON.parse(pl_string); > > 4. Manipulate the payload as if you'd obtained it using getPayloadJSON(). > > I know it's a hacked together method, but none of the other ways were > working for me so I tried this one. > > Some information in case anyone wants to debug it: > > I'm using API Manager 1.7. > > I set the message builders and formatters to these: > Builder class = "org.apache.synapse.commons.json.JsonStreamBuilder" > Formatter class = "org.apache.synapse.commons.json.JsonStreamFormatter" > > > Hope this helps, > > Maz > > > > ------------------------------ > From: mlaka...@hotmail.com > To: mal...@wso2.com; dev@wso2.org > Date: Mon, 12 Jan 2015 08:54:09 +1300 > > Subject: Re: [Dev] getPayloadJSON returning an empty object > > I'm using the ESB that comes with WSO2 API Manager 1.7.0. > > The Formatter is: class="org.apache.axis2.json.JSONMessageFormatter" > The Builder is: class="org.apache.axis2.json.JSONBuilder" > > > ------------------------------ > Date: Fri, 9 Jan 2015 09:25:53 +0530 > From: mal...@wso2.com > To: dev@wso2.org > Subject: Re: [Dev] getPayloadJSON returning an empty object > > Also specify what is the ESB version used? 4.9.0 M4 or 4.8.1? > > On Fri, Jan 9, 2015 at 7:54 AM, Asanka Dissanayake <asan...@wso2.com> > wrote: > > Hi Maz, > What is the JSON builder and formatter you are using? You can find them in > <Carbon_Home>/repository/conf/axis2/axis2.xml under Formatters and Builders. > > Thanks, > Asanka > > On Thu, Jan 8, 2015 at 8:14 PM, Bhathiya Jayasekara <bhath...@wso2.com> > wrote: > > Hi Maz, > > I quickly tried out your config and it worked fine for me. I'm copying my > full config here for your reference. > > <api xmlns="http://ws.apache.org/ns/synapse" name="jsonTest" > context="/json"> > <resource methods="POST"> > <inSequence> > <loopback></loopback> > </inSequence> > <outSequence> > *<script language="js">var older = mc.getPayloadJSON(); var > newer=older; mc.setPayloadJSON(newer);</script>* > <send></send> > </outSequence> > </resource> > </api> > > > *Request:* > curl -X POST -d "{\"origin\":\"202.37.75.130\"}" -H "Content-Type: > application/json" http://10.113.56.222:8281/json > > *Response:* > {"origin":"202.37.75.130"} > > Hope this helps. > > Thanks, > Bhathiya > > On Fri, Jan 9, 2015 at 3:55 AM, Maz Lakadia <mlaka...@hotmail.com> wrote: > > I am doing some very simple script mediation as a test to see if I can > change the payload being returned by my server. > > My unmediated payload comes out as: > > {"origin":"202.37.75.130"} > > Then I try doing a very simple check to see whether get and set work for > payloads: > > <script language="js"> > var older = mc.getPayloadJSON(); > var newer=older; > mc.setPayloadJSON(newer); > </script> > > My result from this is: > > {"jsonObject":""} > > I have done testing that shows that setPayloadJSON() works, which means > that my getPayloadJSON must be returning an empty object. > > Looking at the log file shows this: > > ERROR {org.apache.synapse.mediators.bsf.ScriptMessageContext} - JSON object > is null. {org.apache.synapse.mediators.bsf.ScriptMessageContext} > > Is there anyone else having this error? Is this happening because the > Payload is actually a Java object rather than a JSON object? > > > Thanks, > Maz > > _______________________________________________ > Dev mailing list > Dev@wso2.org > http://wso2.org/cgi-bin/mailman/listinfo/dev > > > > > -- > *Bhathiya Jayasekara* > *Software Engineer,* > *WSO2 inc., http://wso2.com <http://wso2.com>* > > *Phone: +94715478185* > *LinkedIn: http://www.linkedin.com/in/bhathiyaj > <http://www.linkedin.com/in/bhathiyaj>* > *Twitter: https://twitter.com/bhathiyax <https://twitter.com/bhathiyax>* > *Blog: http://movingaheadblog.blogspot.com > <http://movingaheadblog.blogspot.com/>* > > _______________________________________________ > Dev mailing list > Dev@wso2.org > http://wso2.org/cgi-bin/mailman/listinfo/dev > > > > > -- > > > *Asanka DissanayakeSoftware Engineer* > *WSO2 Inc. - lean . enterprise . middleware | wso2.com <http://wso2.com/>* > > *email: asan...@wso2.com <ruch...@wso2.com>, blog: > cyberwaadiya.blogspot.com > <http://cyberwaadiya.blogspot.com>, asankastechtalks.wordpress.com > <http://asankastechtalks.wordpress.com> mobile: +94 71 8373821* > > _______________________________________________ > Dev mailing list > Dev@wso2.org > http://wso2.org/cgi-bin/mailman/listinfo/dev > > > > > -- > > Best Regards, > > Malaka Silva > Senior Tech Lead > M: +94 777 219 791 > Tel : 94 11 214 5345 > Fax :94 11 2145300 > Skype : malaka.sampath.silva > LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77 > Blog : http://mrmalakasilva.blogspot.com/ > > WSO2, Inc. > lean . enterprise . middleware > http://www.wso2.com/ > http://www.wso2.com/about/team/malaka-silva/ > <http://wso2.com/about/team/malaka-silva/> > > Save a tree -Conserve nature & Save the world for your future. Print this > email only if it is absolutely necessary. > > _______________________________________________ Dev mailing list > Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev > > _______________________________________________ Dev mailing list > Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev > > _______________________________________________ > Dev mailing list > Dev@wso2.org > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- Roshan Wijesena. Senior Software Engineer-WSO2 Inc. Mobile: *+94719154640* Email: ros...@wso2.com *WSO2, Inc. :** wso2.com <http://wso2.com/>* lean.enterprise.middleware.
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev