Reputation: 31
I know there are enough similar topics, but I can't get the parameter from the url. Help me figure it out. What am I doing wrong? Here is an example of my code:
<api context="/auth" name="AuthHarv" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET" uri-template="/harv/token={tokenVal}">
<inSequence>
<log separator="
">
<property expression="$url:uri.var.tokenVal" name="token1"/>
<property expression="$url:uri.var.token" name="token2"/>
<property expression="$url:tokenVal" name="token3"/>
<property expression="$url:token" name="token4"/>
<property expression="$url:uri.var.tokenVal" name="uri.var.token1"/>
<property expression="$url:uri.var.token" name="uri.var.token2"/>
<property expression="$url:tokenVal" name="uri.var.token3"/>
<property expression="$url:token" name="uri.var.token4"/>
<property expression="get-property('uri.var.tokenVal')" name="getToken1"/>
<property expression="get-property('uri.var.token')" name="getToken2"/>
<property expression="get-property('tokenVal')" name="getToken3"/>
<property expression="get-property('token')" name="getToken4"/>
<property expression="get-property('uri.var.tokenVal')" name="uri.var.getToken1"/>
<property expression="get-property('uri.var.token')" name="uri.var.getToken2"/>
<property expression="get-property('tokenVal')" name="uri.var.getToken3"/>
<property expression="get-property('token')" name="uri.var.getToken4"/>
<property expression="get-property('query.param.tokenVal')" name="paramToken1"/>
<property expression="get-property('query.param.token')" name="paramToken2"/>
<property expression="get-property('query.param.tokenVal')" name="uri.var.paramToken1"/>
<property expression="get-property('query.param.token')" name="uri.var.paramToken2"/>
</log>
<property expression="concat('https://localhost:44343/Account/login?token=', $ctx:token)" name="uri.var.url" scope="default" type="STRING"/>
<log separator="
">
<property expression="$ctx:uri.var.url" name="path to harvest"/>
</log>
<call>
<endpoint>
<http method="get" uri-template="{uri.var.url}">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<log separator="
">
<property expression="json-eval($)" name="JSON_auth_from_harvest"/>
</log>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
This is what I get in the log:
Direction: request
token1 =
token2 =
token3 =
token4 =
uri.var.token1 =
uri.var.token2 =
uri.var.token3 =
uri.var.token4 =
getToken1 = token_value
getToken2 = null
getToken3 = null
getToken4 = null
uri.var.getToken1 = token_value
uri.var.getToken2 = null
uri.var.getToken3 = null
uri.var.getToken4 = null
paramToken1 = null
paramToken2 = null
uri.var.paramToken1 = null
uri.var.paramToken2 = null
[2022-04-13 19:34:05,164] INFO {LogMediator} - {api:AuthHarvest} To: /auth/harv/token=token_value
Why can't I get the value from $url:prop? Thank you very much for your help.
Upvotes: 0
Views: 846
Reputation: 1294
The issue seems to be with how you defined your uri-template (uri-template="/harv/token={tokenVal}"
).
Path parameter
If you want to define a path parameter, it should be.
uri-template="/harv/{tokenVal}"
You can access it with
<property name="pathParam" expression="get-property('uri.var.tokenVal')"></property>
Query parameter
If the parameter is sent as a query parameter
uri-template="/harv?token={tokenVal}"
You can access it with
<property name="queryParam" expression="get-property('query.param.token')"></property>
<property name="queryParam" expression="$url:token"></property>
Refer to documentation [1] to get more information on this.
[1]-https://ei.docs.wso2.com/en/7.2.0/micro-integrator/use-cases/examples/rest_api_examples/setting-query-params-outgoing-messages/
Upvotes: 0
Reputation: 1340
You have defined the uri template
not entirely correctly with REST. It should be something like:
uri-template="/harv?token={tokenValue}"
(with question mark).
And then You can get the parameter value using:
<property name="token" expression="get-property('query.param.token')"/>
or
<property name="tokenVal" expression="get-property('uri.var.tokenVal')"/>
And as I see, even in your template, you get the value:
getToken1 = token_value
and uri.var.getToken1 = token_value
Upvotes: 1