【问题标题】:How to use API Rest url template value into call template at WSO2如何在 WSO2 中将 API Rest url 模板值用于调用模板
【发布时间】:2020-10-16 23:49:19
【问题描述】:

我开始:

<?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 类型的 paylodfactory { "input: $1 } 并像 json 一样使用它:$.input but no...

【问题讨论】:

    标签: rest wso2 wso2ei wso2mi


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      • 2016-08-06
      • 2022-11-25
      • 1970-01-01
      相关资源
      最近更新 更多