Friday, May 27, 2016

WSO2 ESB Accessing application/x-www-form-urlencoded Data


I want to pass application/x-www-form-urlencoded data to the ESB:
curl -v -X POST 'http://myhost/myapi/stuff' -d 'myvar=hello' -H "Content-Type: application/x-www-form-urlencoded"
...and then be able to receive each form variable in my ESB API .
To get a given variable, I'm doing this:
<resource methods="POST" uri-template="/stuff">
         <property name="myvar" expression="//xformValues//myvar/text()"></property>
Then I'm storing that in an argument:
   <arg evaluator="xml" expression="$ctx:myvar"></arg>
Then I'm later trying to stuff it in a payload with $1.
I know that the issue is with the property line:
<property name="myvar" expression="//xformValues//myvar/text()"></property>
...because if I store a literal value in the line, it will work.
I do have the messageReceiver configured in the axis.xml:
<messageFormatter contentType="application/x-www-form-urlencoded"
<messageFormatter contentType="multipart/form-data"
And, I have the messageBuilder configured in the axis.xml file:
<messageBuilder contentType="application/x-www-form-urlencoded"
ANSWER : Just use
`<property name="myvar" expression="//myvar/text()"/>`
wire logs
[2016-05-27 12:59:22,160] DEBUG - wire >> "POST /foo123 HTTP/1.1[\r][\n]"
[2016-05-27 12:59:22,161] DEBUG - wire >> "User-Agent: curl/7.37.1[\r][\n]"
[2016-05-27 12:59:22,161] DEBUG - wire >> "Host:[\r][\n]"
[2016-05-27 12:59:22,161] DEBUG - wire >> "Accept: */*[\r][\n]"
[2016-05-27 12:59:22,161] DEBUG - wire >> "Authorization: Basic QU93ZmJQRW5YcXVDVnhIS1ZZT2ZlVFQxT01NYTpEeGpBY3dodFB5Wm5JTU9CZmJEakRHc21FQjBh[\r][\n]"
[2016-05-27 12:59:22,161] DEBUG - wire >> "Content-Type: application/x-www-form-urlencoded;charset=UTF-8[\r][\n]"
[2016-05-27 12:59:22,161] DEBUG - wire >> "Content-Length: 135[\r][\n]"
[2016-05-27 12:59:22,161] DEBUG - wire >> "[\r][\n]"
[2016-05-27 12:59:22,161] DEBUG - wire >> "grant_type=authorization_code&code=291a24141f1e3332baf9799c4c378033&redirect_uri="
[2016-05-27 12:59:22,163] DEBUG - LogMediator Start : Log mediator
[2016-05-27 12:59:22,163]  INFO - LogMediator To: /foo123, MessageID: urn:uuid:c20f24d4-668d-447e-9de0-dbe5885b6d16, Direction: request
[2016-05-27 12:59:22,164] DEBUG - LogMediator End : Log mediator
[2016-05-27 12:59:22,164] DEBUG - LogMediator Start : Log mediator
[2016-05-27 12:59:22,164]  INFO - LogMediator payload = <mediate><code>291a24141f1e3332baf9799c4c378033</code><redirect_uri></redirect_uri><grant_type>authorization_code</grant_type></mediate>,code = 291a24141f1e3332baf9799c4c378033
[2016-05-27 12:59:22,164] DEBUG - LogMediator End : Log mediator
[2016-05-27 12:59:22,165] DEBUG - wire << "HTTP/1.1 200 OK[\r][\n]"
[2016-05-27 12:59:22,165] DEBUG - wire << "Authorization: Basic QU93ZmJQRW5YcXVDVnhIS1ZZT2ZlVFQxT01NYTpEeGpBY3dodFB5Wm5JTU9CZmJEakRHc21FQjBh[\r][\n]"
[2016-05-27 12:59:22,166] DEBUG - wire << "Host:[\r][\n]"
[2016-05-27 12:59:22,166] DEBUG - wire << "Content-Type: application/x-www-form-urlencoded;charset=UTF-8[\r][\n]"
[2016-05-27 12:59:22,166] DEBUG - wire << "Accept: */*[\r][\n]"
[2016-05-27 12:59:22,166] DEBUG - wire << "Date: Fri, 27 May 2016 19:59:22 GMT[\r][\n]"
[2016-05-27 12:59:22,166] DEBUG - wire << "Server: WSO2-PassThrough-HTTP[\r][\n]"
[2016-05-27 12:59:22,166] DEBUG - wire << "Transfer-Encoding: chunked[\r][\n]"
[2016-05-27 12:59:22,166] DEBUG - wire << "[\r][\n]"
[2016-05-27 12:59:22,166] DEBUG - wire << "91[\r][\n]"
[2016-05-27 12:59:22,166] DEBUG - wire << "code=291a24141f1e3332baf9799c4c378033&[\r][\n]"
[2016-05-27 12:59:22,166] DEBUG - wire << "0[\r][\n]"
[2016-05-27 12:59:22,167] DEBUG - wire << "[\r][\n]"
<api xmlns="" name="foo123" context="/foo123">
   <resource methods="POST">
         <property name="payload" expression="//mediate"></property>
         <property name="code" expression="//mediate/code"></property>
         <log level="custom" separator=",">
            <property name="payload" expression="$ctx:payload"></property>
            <property name="code" expression="$ctx:code"></property>


  1. woah that is too much computer science for my simple brain. even though as layman i could gather enough from this blog that it was pretty descriptive and and i am pretty sure that people who top custom essay services and always in search of extra information willfind this artice truly helpful.

  2. You should console that you design out your alternatives and make an awesome application that suits your prerequisites and requirements. website to app

  3. I am very thankful for the author who shared the informative blog. This helps the first home buyers in a better way to choose the appropriate location.
    Apartments for sale in Chennai
    Studio apartments in Chennai
    Apartments in OMR
    Flats for sale in Adyar
    Flats for sale in Vadapalani

  4. I m Really looking forward to read more. Your site is very helpful for us .. This is one of the awesome post i got the best information through your site and Visit also this site
    Black satta king
    disawar satta king
    gaziabad satta king
    faridabad satta king
    gali satta king

  5. Shop Online in Auckland Newzealand on a single click. We provide you quality items which you will be buy online at lowest price..! Buy online sofa beds nz at lowest price on Treasurebox store.

  6. Pinoy TV Channel with the heart bears through online tv. If you are getting tired of your pointy life until one day you woke up feeling heavier than usual you woke up with the heart tears through your whose heart are you and how did you get here you can watch all of pinoy tv shows channel and Pinoy Lambingan hd tv program political talk show reality on this site Gallardo asked but there was no reply sorry mother.

  7. They are sure and glad to recommend this dependable site to likeminded individuals in their esteemed circle.satta king