0

我开始:

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

我可以使用 get-property("uri.var.echoque") 和 $ctx:uri.var.echoque 记录 echoque,但是如果我将值设置为文字,它可以工作,所以我不知道如何使用 uri来自...的模板这是我的最后一个示例

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

有人可以解释如何使用其余 api 中的变量吗?我还尝试使用 json 类型 { "input: $1 } 并像 json: $.input 一样使用它,但没有...

4

1 回答 1

1

以下应该工作。您不必使用单独的变量。直接使用uri.var.echoque里面的呼叫中介。

<?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>
于 2020-10-17T12:52:00.833 回答