Reputation: 1187
I have installed WSO2 EI 6.1.1 on a Linux box. I have created a pass through proxy for a rest interface that gets both GET and PUT requests. I have set a Java Class Mediator that is supposed to make some deicisions based on a parameter included in the url of the requests:
http://xx.xx.xx.xx:8280/services/app/url?token=ABCD
When I ask for the context of the request from the class I can see the content of the envelope and the resquest.
System.out.println("Context: \n " + context.getMessageString());
To : /services/app/url?token=ABCD
MessageID : urn:uuid:431940fd-201e-43a3-aad1-0ca5e36297dd
Body : <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
How can I get the value of the token parameter? No way I have tried has worked.
UPDATE:
This is the current sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="jsonvalidate" xmlns="http://ws.apache.org/ns/synapse">
<log>
<property expression="get-property('query.param.token')" name="token"/>
</log>
<property name="pass" scope="default" type="STRING" value="yes"/>
<property expression="get-property('query.param.token')"
name="token" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd"/>
<class name="authzMediator.validate">
<axis2ns15:property name="validated" value="1" xmlns:axis2ns15="http://ws.apache.org/ns/synapse"/>
<axis2ns16:property name="validated1" value="yes" xmlns:axis2ns16="http://ws.apache.org/ns/synapse"/>
</class>
<log category="DEBUG">
<property expression="get-property('token')" name="token1" xmlns:ns="http://org.apache.synapse/xsd"/>
</log>
<filter xmlns:ns="http://org.apache.synapse/xsd" xpath="get-property('pass') = 'yes'">
<then>
<class name="authzMediator.trace">
<axis2ns17:property name="msg" value="YES" xmlns:axis2ns17="http://ws.apache.org/ns/synapse"/>
</class>
</then>
<else>
<class name="authzMediator.trace">
<axis2ns18:property name="msg" value="NO" xmlns:axis2ns18="http://ws.apache.org/ns/synapse"/>
</class>
<drop/>
</else>
</filter>
</sequence>
What I see is that in the first step (log) I see this:
[EI-Core] INFO - LogMediator To: /services/lsrest/clients/jordipc/3/0/14?token=patata, MessageID: urn:uuid:3b08226e-4a46-474a-8d7c-c4c786e51b4c, Direction: request, token = null
Upvotes: 0
Views: 561
Reputation: 1187
The final result was based on a double action:
Define a property mediator with an expresion value $url:token
and name "token".
In the Class mediator call this function context.getProperty("token")
Upvotes: 0
Reputation: 2093
You can access the value of the token parameter with get-property('uri.var.token') [1].
There are two approaches to using this value.
(1) Pass token as a parameter to the class mediator. Follow [2] for a sample.
(2) Access this property in the class mediator mediate()
method as below.
token = synCtx.getProperty('uri.var.token');
[1] https://docs.wso2.com/display/ESB490/HTTP+Endpoint [2] https://docs.wso2.com/display/ESB490/Class+Mediator
Upvotes: 1