How to use API Rest url template value into call template at WSO2

224 views Asked by At

I start with:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/echo/2" name="echo" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" uri-template="/{echoque}">
        <inSequence/>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

And I can log echoque with get-property("uri.var.echoque"), aslo $ctx:uri.var.echoque, but if I set the value to literal, it works, so I don know how to use the uri template from... here is my last example

<?xml version="1.0" encoding="UTF-8"?>
<api context="/echo/sound" name="echo" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" uri-template="/{echoque}">
        <inSequence>
            <log>
                <property expression="get-property(&quot;uri.var.echoque&quot;)" name="Input"/>
            </log>
            <call>
                <endpoint>
                    <http method="get" uri-template="http://echotest.localhost/echo/{uri.var.sound}">
                        <suspendOnFailure>
                            <initialDuration>-1</initialDuration>
                            <progressionFactor>-1</progressionFactor>
                            <maximumDuration>0</maximumDuration>
                        </suspendOnFailure>
                        <markForSuspension>
                            <retriesBeforeSuspension>0</retriesBeforeSuspension>
                        </markForSuspension>
                    </http>
                    <property expression="$ctx:uri.var.echoque" name="uri.var.sound"/>
                </endpoint>
            </call>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

Can someone explain how to use the variables from the rest api? I also tryed paylodfactory using a json tyle { "input: $1 } and use it like json: $.input but no...

1

There are 1 answers

0
Arunan On BEST ANSWER

The following should work. You don't have to use a separate variable. Directly use the uri.var.echoque inside the call mediator.

<?xml version="1.0" encoding="UTF-8"?>
<api context="/echo/sound" name="echo" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" uri-template="/{echoque}">
        <inSequence>
            <log>
                <property expression="get-property(&quot;uri.var.echoque&quot;)" name="Input"/>
            </log>
            <call>
                <endpoint>
                    <http method="get" uri-template="http://echotest.localhost/echo/{uri.var.echoque}">
                        <suspendOnFailure>
                            <initialDuration>-1</initialDuration>
                            <progressionFactor>-1</progressionFactor>
                            <maximumDuration>0</maximumDuration>
                        </suspendOnFailure>
                        <markForSuspension>
                            <retriesBeforeSuspension>0</retriesBeforeSuspension>
                        </markForSuspension>
                    </http>
                </endpoint>
            </call>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>