问题描述:

I'm using WSO2 ESB.

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">

<inSequence>

<property name="myvar" expression="//xformValues//myvar/text()"></property>

...

Then I'm storing that in an argument:

<args>

<arg evaluator="xml" expression="$ctx:myvar"></arg>

</args>

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"

class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>

<messageFormatter contentType="multipart/form-data"

And, I have the messageBuilder configured in the axis.xml file:

<messageBuilder contentType="application/x-www-form-urlencoded"

class="org.apache.synapse.commons.builders.XFormURLEncodedBuilder"/>

Any idea of what I'm doing wrong?

Thanks!

网友答案:

Just use

`<property name="myvar" expression="//myvar/text()"/>`

It works. Actually built message looks like

`<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <mediate>
         <myvar>helloaaaa</myvar>
      </mediate>
   </soapenv:Body>
</soapenv:Envelope>`

So your xpath evaluation fails. hope this helps.

Thanks,

网友答案:

I stumbled upon the answer.

The correct xpath should be:

<property name="myvar" expression="//mediate//myvar/text()"></property>

This appears to be a known issue, mentioned here:

https://wso2.org/jira/browse/ESBJAVA-3303

  • Randy
相关阅读:
Top