parseInt() method gives in Scientific notation. It is the behavior of Rhino
javascript Engine. So followed approach has been used.
[1]
<property name="uri.var.query" value=''/>
<script language="js">
<![CDATA[
//request body param variables
var requesterId = mc.getProperty('uri.var.requesterId');
var query='{';
//query = query.concat(email);
if (requesterId != null && requesterId != ""){
query = query.concat('"'+'requester_id":' +
requesterId+',');
}
query=query.substring(0, query.length-1);
mc.setProperty('uri.var.query', query);
]]>
</script>
<payloadFactory media-type="json">
<format>
$1}
</format>
<args>
<arg expression="$ctx:uri.var.query"/>
</args>
</payloadFactory>
Best Regards,
Yashothara.S
Software Engineer
WSO2
http://wso2.com
https://wso2.com/signature
<https://www.google.com/url?q=https%3A%2F%2Fwso2.com%2Fsignature&sa=D&sntz=1&usg=AFQjCNFqSCK3YQC9g0l53f6yjvsVrxRHXg>
On Thu, Sep 29, 2016 at 7:20 AM, Malaka Silva <[email protected]> wrote:
> What was the solution?
>
> On Wed, Sep 28, 2016 at 9:36 PM, Yashothara Shanmugarajah <
> [email protected]> wrote:
>
>> Yes Malaka. I have resolved this issue today.
>>
>> Best Regards,
>> Yashothara.S
>> Software Engineer
>> WSO2
>> http://wso2.com
>> https://wso2.com/signature
>> <https://www.google.com/url?q=https%3A%2F%2Fwso2.com%2Fsignature&sa=D&sntz=1&usg=AFQjCNFqSCK3YQC9g0l53f6yjvsVrxRHXg>
>>
>> On Wed, Sep 28, 2016 at 8:33 PM, Malaka Silva <[email protected]> wrote:
>>
>>> Hi Yashothara,
>>>
>>> Is the issues resolved?
>>>
>>> On Wed, Sep 21, 2016 at 12:57 PM, Yashothara Shanmugarajah <
>>> [email protected]> wrote:
>>>
>>>> Hi Nuwan,
>>>>
>>>> As it is an Optional Parameter, I need to send through the script
>>>> mediator. So I can't use payload mediator.
>>>>
>>>> Please find this proxy[1]. Here I didn't use connector. Even though I
>>>> am getting in scientific notation.
>>>>
>>>> [1]
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <proxy xmlns="http://ws.apache.org/ns/synapse"
>>>> name="checkConnectorScript"
>>>> startOnLoad="true"
>>>> statistics="disable"
>>>> trace="disable"
>>>> transports="https,http">
>>>> <target>
>>>> <inSequence onError="faultHandlerSeq">
>>>> <property expression="json-eval($.requesterId)"
>>>> name="requesterId"/>
>>>> <log level="custom">
>>>> <property expression="get-property('requesterId')"
>>>> name="121212121212121212121212121212"/>
>>>> </log>
>>>> <payloadFactory media-type="json">
>>>> <format>
>>>> {
>>>>
>>>> }
>>>> </format>
>>>> <args/>
>>>> </payloadFactory>
>>>> <script language="js">payload = mc.getPayloadJSON();
>>>> var requesterId = mc.getProperty('requesterId');
>>>>
>>>> var requesterIdInt = parseInt(mc.getProperty('reque
>>>> sterId'));
>>>> payload["requester_id"] = requesterIdInt;
>>>>
>>>> mc.setPayloadJSON(payload);</script>
>>>> <call>
>>>> <endpoint>
>>>> <http method="POST"
>>>> uri-template="https://wso2yash
>>>> o.freshdesk.com/api/v2/tickets"/>
>>>> </endpoint>
>>>> </call>
>>>> <respond/>
>>>> </inSequence>
>>>> <outSequence>
>>>> <log/>
>>>> </outSequence>
>>>> </target>
>>>> <description/>
>>>> </proxy>
>>>>
>>>>
>>>> Best Regards,
>>>> Yashothara.S
>>>> Software Engineer
>>>> WSO2
>>>> http://wso2.com
>>>> https://wso2.com/signature
>>>> <https://www.google.com/url?q=https%3A%2F%2Fwso2.com%2Fsignature&sa=D&sntz=1&usg=AFQjCNFqSCK3YQC9g0l53f6yjvsVrxRHXg>
>>>>
>>>> On Wed, Sep 21, 2016 at 10:48 AM, Nuwan Pallewela <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi Yashothara,
>>>>>
>>>>> I think this happens due to the use of script mediator. You do not
>>>>> need to use script mediator here. Just use the payload factory mediator to
>>>>> build the payload or use data mapper mediator if you need to do more
>>>>> complex mapping.
>>>>>
>>>>> [1] https://docs.wso2.com/display/ESB481/PayloadFactory+Mediator
>>>>> #PayloadFactoryMediator-Example2:JSON
>>>>>
>>>>> Thanks,
>>>>> Nuwan
>>>>>
>>>>> On Wed, Sep 21, 2016 at 10:33 AM, Yashothara Shanmugarajah <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> Please find the template[1] and proxy[2].
>>>>>>
>>>>>> [1]
>>>>>> <template name="createTicket" xmlns="http://ws.apache.org/ns/synapse
>>>>>> ">
>>>>>> <!--Required Parameters-->
>>>>>> <parameter name="requesterId" description="User ID of the
>>>>>> requester."/>
>>>>>> <sequence>
>>>>>> <property name="uri.var.requesterId"
>>>>>> expression="$func:requesterId"/>
>>>>>> <log level="custom">
>>>>>> <property name="909090909090909090909090909"
>>>>>> expression="$ctx:uri.var.requesterId"/>
>>>>>> </log>
>>>>>> <payloadFactory media-type="json">
>>>>>> <format>
>>>>>> {
>>>>>>
>>>>>> }
>>>>>> </format>
>>>>>> <args>
>>>>>>
>>>>>> </args>
>>>>>> </payloadFactory>
>>>>>>
>>>>>> <!-- Constructing payload with optional parameters -->
>>>>>> <script language="js">
>>>>>> <![CDATA[
>>>>>> payload = mc.getPayloadJSON();
>>>>>>
>>>>>> var requesterId = mc.getProperty("uri.var.requesterId");
>>>>>>
>>>>>> if (requesterId != null && requesterId != ""){
>>>>>> var requesterIdInt = parseInt(mc.getProperty("uri.v
>>>>>> ar.requesterId"));
>>>>>> payload["requester_id"] = requesterIdInt;
>>>>>> }
>>>>>>
>>>>>> mc.setPayloadJSON(payload);
>>>>>> ]]>
>>>>>> </script>
>>>>>>
>>>>>> <call>
>>>>>> <endpoint>
>>>>>> <http method="post" uri-template="{uri.var.apiUrl}
>>>>>> /api/v2/tickets"/>
>>>>>> </endpoint>
>>>>>> </call>
>>>>>>
>>>>>> <!-- Remove response custom header information -->
>>>>>> <header name="X-Runtime" scope="transport" action="remove"/>
>>>>>> <header name="X-Powered-By" scope="transport"
>>>>>> action="remove"/>
>>>>>>
>>>>>> </sequence>
>>>>>> </template>
>>>>>>
>>>>>>
>>>>>>
>>>>>> [2] <?xml version="1.0" encoding="UTF-8"?>
>>>>>> <proxy xmlns="http://ws.apache.org/ns/synapse"
>>>>>> name="createTicket"
>>>>>> startOnLoad="true"
>>>>>> statistics="disable"
>>>>>> trace="disable"
>>>>>> transports="https,http">
>>>>>> <target>
>>>>>> <inSequence onError="faultHandlerSeq">
>>>>>> <property expression="json-eval($.apiUrl)" name="apiUrl"/>
>>>>>> <property expression="json-eval($.apiKey)" name="apiKey"/>
>>>>>> <property expression="json-eval($.requesterId)"
>>>>>> name="requesterId"/>
>>>>>> <log level="custom">
>>>>>> <property expression="get-property('requesterId')"
>>>>>> name="121212121212121212121212121212"/>
>>>>>> </log>
>>>>>> <freshdesk.init>
>>>>>> <apiKey>{$ctx:apiKey}</apiKey>
>>>>>> <apiUrl>{$ctx:apiUrl}</apiUrl>
>>>>>> </freshdesk.init>
>>>>>> <freshdesk.createTicket>
>>>>>> <requesterId>{$ctx:requesterId}</requesterId>
>>>>>> </freshdesk.createTicket>
>>>>>> <respond/>
>>>>>> </inSequence>
>>>>>> <outSequence>
>>>>>> <log/>
>>>>>> <send/>
>>>>>> </outSequence>
>>>>>> </target>
>>>>>> <description/>
>>>>>> </proxy>
>>>>>>
>>>>>>
>>>>>> Best Regards,
>>>>>> Yashothara.S
>>>>>> Software Engineer
>>>>>> WSO2
>>>>>> http://wso2.com
>>>>>> https://wso2.com/signature
>>>>>> <https://www.google.com/url?q=https%3A%2F%2Fwso2.com%2Fsignature&sa=D&sntz=1&usg=AFQjCNFqSCK3YQC9g0l53f6yjvsVrxRHXg>
>>>>>>
>>>>>> On Wed, Sep 21, 2016 at 10:20 AM, Malaka Silva <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>> Hi Yashothara,
>>>>>>>
>>>>>>> Can you share the config you used.
>>>>>>>
>>>>>>> On Wed, Sep 21, 2016 at 9:33 AM, Yashothara Shanmugarajah <
>>>>>>> [email protected]> wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I need to send JSON payload with long (for e.g 19000010655) not as
>>>>>>>> String. In the back end it changes as a scientific notation
>>>>>>>> (1.9000096356E10)
>>>>>>>> in ESB 5.0.0. Is there any way to resolve this?
>>>>>>>>
>>>>>>>> Thanks.
>>>>>>>>
>>>>>>>> Best Regards,
>>>>>>>> Yashothara.S
>>>>>>>> Software Engineer
>>>>>>>> WSO2
>>>>>>>> http://wso2.com
>>>>>>>> https://wso2.com/signature
>>>>>>>> <https://www.google.com/url?q=https%3A%2F%2Fwso2.com%2Fsignature&sa=D&sntz=1&usg=AFQjCNFqSCK3YQC9g0l53f6yjvsVrxRHXg>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>>>>>>> Best Regards,
>>>>>>>
>>>>>>> Malaka Silva
>>>>>>> Senior Technical 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
>>>>>>> https://wso2.com/signature
>>>>>>> http://www.wso2.com/about/team/malaka-silva/
>>>>>>> <http://wso2.com/about/team/malaka-silva/>
>>>>>>> https://store.wso2.com/store/
>>>>>>>
>>>>>>> Don't make Trees rare, we should keep them with care
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> ----------------------------------------------------------
>>>>>
>>>>> *Nuwan Chamara Pallewela*
>>>>>
>>>>>
>>>>> *Software Engineer*
>>>>>
>>>>> *WSO2, Inc. *http://wso2.com
>>>>> *lean . enterprise . middleware*
>>>>>
>>>>> Email *[email protected] <[email protected]>*
>>>>> Mobile *+94719079739 <%2B94719079739>@*
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>>
>>> Best Regards,
>>>
>>> Malaka Silva
>>> Senior Technical 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
>>> https://wso2.com/signature
>>> http://www.wso2.com/about/team/malaka-silva/
>>> <http://wso2.com/about/team/malaka-silva/>
>>> https://store.wso2.com/store/
>>>
>>> Don't make Trees rare, we should keep them with care
>>>
>>
>>
>
>
> --
>
> Best Regards,
>
> Malaka Silva
> Senior Technical 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
> https://wso2.com/signature
> http://www.wso2.com/about/team/malaka-silva/
> <http://wso2.com/about/team/malaka-silva/>
> https://store.wso2.com/store/
>
> Don't make Trees rare, we should keep them with care
>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev