如何将JSON或SOAP属性用于Path URL Param或Query Param WSO2 Entrerprise Integrator

问题描述

我在WSO2 IE上还很陌生,我正在尝试使用SOAP请求来调用REST API。 第一部分是可以的,但是我的API之一需要将属性接收到其PATH或QUERY参数中。该属性是通过其体内的soap调用发送的。

问题是,在发送它之前,如何动态获取此body属性并将其动态传递到URL的PATH / QUERY参数中?

Picture of my architecture

解决方法

您的要求是构造一个动态URL。使用ESB Server可以轻松完成此操作。在这里,我们有不同的选项来构造此动态URL。以下是为实现此目的而创建的示例代理服务。

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="sample_proxy"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="http,https">
   <target>
      <inSequence>
         <log level="custom">
            <property expression="$body//target" name="Target endpoint"/>
         </log>
         <property name="uri.var.host" value="http://localhost:8280"/>
         <property name="uri.var.context" value="services"/>
         <property expression="$body//target" name="uri.var.resourcepath"/>
         <call>
            <endpoint>
               <http method="GET"
                     uri-template="{uri.var.host}/{uri.var.context}/{uri.var.resourcepath}"/>
            </endpoint>
         </call>
         <respond/>
      </inSequence>
   </target>
   <description/>
</proxy>
          

我们正在将以下请求发送到此代理服务。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
   <target>sample_path</target>
   </soapenv:Body>
</soapenv:Envelope>  

在上述代理服务中,我们执行的操作是使用soap消息中的参数构造动态URL,请参阅博客文章[1]进一步阐明动态URL。

在这里,为了从主体中提取参数,我们使用了XPath。请参考文档[2]进一步说明XPath。我们已经在目标元素内提取了值,并将其添加到URL的末尾。因此,这将从ESB服务器调用http:// localhost:8280 / services / sample_path。

如果您对使用查询参数构造URL感兴趣,可以通过串联所需的URL并使用地址端点[1]来实现。

[1] -https://dzone.com/articles/constructing-dynamic-endpoint-urls-in-wso2-esb [2] -https://docs.wso2.com/display/EI6xx/Accessing+Properties+with+XPath#AccessingPropertieswithXPath-$ctx

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...