remove empty parameters from payload - http post / json

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

remove empty parameters from payload - http post / json

krishantha
I am using ESB 4.8.0
My backend service is not accepting empty optional parameters. Means if optional parameter is not supply then need to remove parameter name also from URL encoding.
For example

credentialFieldstypeName=IF_LOGIN&credentialFieldsame=LOGIN&credentialFieldsvalue=sha5.

Let’s says “credentialFieldsame” is optional on above URL then it’s need to come as

credentialFieldstypeName=IF_LOGIN&credentialFieldsvalue=sha5

Means completely remove parameter. If we send like bellow it gives error

credentialFieldstypeName=IF_LOGIN&credentialFieldsame=&credentialFieldsvalue=sha5

it is not possible to use fileters as I have 6 optional parameters. Means 64 combinations!!!
Is there any way to do this? Means remove empty parameters when x-www-form-urlencoding
Note: I am using json payload as cannot use xml I need to use "["  on parameter names.
http method is POST

payload as follows

<payloadFactory media-type="json">
                        <format>
                                {
                                "SessionToken": "$1",
                                "userToken": "$2",
                                "SiteAccId": "$3",
                                }

                        </format>
                        <args>

                                <arg expression="get-property('uri.var.SessionToken')" />
                                <arg expression="get-property('uri.var.userToken')" />
                                <arg expression="get-property('uri.var.SiteAccId')" />
                        </args>
                </payloadFactory>

<property name="messageType" value="application/x-www-form-urlencoded"
                        scope="axis2" />
Reply | Threaded
Open this post in threaded view
|

Re: remove empty parameters from payload - http post / json

indika prasad
This post was updated on .
You could be able to modify the payload using enrich mediator. Here is the nice example [1]  for payload modification. Also this [2] guide might be helpfull.

[1] http://mrmalakasilva.blogspot.com/2013/04/use-of-enrich-mediator-to-modify-payload.html
[2] http://docs.wso2.org/display/ESB480/JSON+Support
Reply | Threaded
Open this post in threaded view
|

Re: [Dev] remove empty parameters from payload - http post / json

malakasilva
You can inject optional parameters as required using enrich mediator as mentioned by Indika.

So you can create the initial payload and use enrich for optional parameters.

Best Regards,
Malaka


On Mon, Jan 27, 2014 at 7:24 AM, indika prasad <[hidden email]> wrote:
You could be able to modify the payload using enrich mediator. Here is the
nice example [1]  for payload modification.

[1]
http://mrmalakasilva.blogspot.com/2013/04/use-of-enrich-mediator-to-modify-payload.html




--
View this message in context: http://wso2-oxygen-tank.10903.n7.nabble.com/remove-empty-parameters-from-payload-http-post-json-tp91243p91254.html
Sent from the WSO2 Development mailing list archive at Nabble.com.
_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev



--

Best Regards,

Malaka Silva
Senior Tech Lead
M: +94 777 219 791
Fax :94 11 2145300 
LinkedIn : http://www.linkedin.com/pub/malaka-silva/6/33/77

WSO2, Inc. 
lean . enterprise . middleware 
http://www.wso2.com/

Save a tree -Conserve nature & Save the world for your future. Print this email only if it is absolutely necessary.

_______________________________________________
Dev mailing list
[hidden email]
http://wso2.org/cgi-bin/mailman/listinfo/dev