【问题标题】:Use variables for URI in WSDL mediators WSO2在 WSDL 中介 WSO2 中为 URI 使用变量
【发布时间】:2020-07-27 05:40:16
【问题描述】:

我正在重构一个 wso2 项目,我想知道如何/是否可以执行以下操作。该项目旨在将数据发送到 SOAP Api。在每个环境中,此 API 都会公开一个 .wsdl 文件,并且 URL 和凭据是从一个环境到另一个环境的唯一变化。最自然的事情就是这样

  • Registry
  • 中创建
  • 像这样在作业开始时加载它
<propertyGroup>
  <property expression="get-property('registry', 'gov:/endpoints/sap_constructionSiteUser')" name="sap_constructionSiteUser" scope="default" type="STRING"/>
  <property expression="get-property('registry', 'gov:/endpoints/sap_constructionSitePassword')" name="sap_constructionSitePassword" scope="default" type="STRING"/>
  <property expression="get-property('registry', 'gov:/endpoints/sap_constructionSiteUrl')" name="uri.var.sap_constructionSiteUrl" scope="default" type="STRING"/>
</propertyGroup>

但我找不到在端点定义中使用此uri.var.sap_constructionSiteUrl直接方法。以下不起作用

<call>
  <endpoint>
     <wsdl optimize="mtom" uri="{uri.var.sap_constructionSiteUrl}" port="OUVERTURE_CHANTIER" service="OUVERTURE_CHANTIER" statistics="enable">
       <suspendOnFailure>
       <initialDuration>-1</initialDuration>
       <progressionFactor>-1</progressionFactor>
       <maximumDuration>0</maximumDuration>
       </suspendOnFailure>
       <markForSuspension>
       <retriesBeforeSuspension>0</retriesBeforeSuspension>
       </markForSuspension>
     </wsdl>
  </endpoint>
</call>

看起来uri= 只接受普通值。有没有一种方法可以在不将整个端点写入Registry 的情况下实现动态化(重点是让客户保持简单)

[环境]

  • wso2ei 6.5.0

====================编辑=================== =====

我刚刚创建了一个模板:

<template name="crm4sap-constructionSiteTemplate" xmlns="http://ws.apache.org/ns/synapse">
    <axis2ns488:parameter name="port" xmlns:axis2ns488="http://ws.apache.org/ns/synapse"/>
    <axis2ns489:parameter name="service" xmlns:axis2ns489="http://ws.apache.org/ns/synapse"/>
    <axis2ns490:parameter name="uri" xmlns:axis2ns490="http://ws.apache.org/ns/synapse"/>
    <endpoint name="$name">
        <wsdl port="$port" service="$service" uri="$uri">
            <suspendOnFailure>
                <initialDuration>-1</initialDuration>
                <progressionFactor>1.0</progressionFactor>
            </suspendOnFailure>
            <markForSuspension>
                <retriesBeforeSuspension>0</retriesBeforeSuspension>
            </markForSuspension>
        </wsdl>
    </endpoint>
</template>

我用它来称呼它

<call>
  <endpoint name="constructionSiteEndpoint" template="crm4sap-constructionSiteTemplate">
    <axis2ns468:parameter name="port" value="OUVERTURE_CHANTIER" xmlns:axis2ns468="http://ws.apache.org/ns/synapse"/>
    <axis2ns469:parameter name="service" value="OUVERTURE_CHANTIER" xmlns:axis2ns469="http://ws.apache.org/ns/synapse"/>
    <axis2ns469:parameter name="uri" value="{$ctx:sap_constructionSiteUrl}" xmlns:axis2ns469="http://ws.apache.org/ns/synapse"/>
  </endpoint>
</call>

变量替换似乎没有发生:

[2020-04-15 12:30:54,032] []  WARN - TemplateEndpointFactory Could not read the WSDL endpoint {$ctx:sap_constructionSiteUrl}
java.net.MalformedURLException: no protocol: {$ctx:sap_constructionSiteUrl}
        at java.net.URL.<init>(URL.java:600)
        at java.net.URL.<init>(URL.java:497)
        at java.net.URL.<init>(URL.java:446)

看起来像common problem

【问题讨论】:

    标签: wso2 wsdl wso2esb wso2ei synapse


    【解决方案1】:

    您可以尝试将此端点模板化,然后使用参数调用模板。您可以在运行时将动态值传递给模板。 https://docs.wso2.com/display/EI650/Endpoint+Template

    【讨论】:

      【解决方案2】:

      我能够按顺序使用以下代码来做到这一点:

       <call-template target="template-for-calling-soap">
              <with-param name="url" value="{get-property('soap-uri')}"/>
       </call-template>
      

      soap-uri 是一个本地条目或简单属性,名为 template-for-calling-soap 的序列模板将 url 值作为参数,代码如下:

      <template name="template-for-calling-soap" 
      xmlns="http://ws.apache.org/ns/synapse">
          <parameter name="url"/>
          <sequence>
             <property expression="$func:url" name="uri.var" scope="default" 
              type="STRING"/>
             <send>
                  <endpoint>
                      <address format="soap11" uri="${uri.var}"/>
                  </endpoint>
             </send>
          </sequence>
      </template>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-08
        • 2013-02-21
        • 2012-08-31
        • 2012-08-31
        相关资源
        最近更新 更多