【问题标题】:WSO2 ESB: Get URI in property from HTTP/Address Endpoint?WSO2 ESB:从 HTTP/地址端点获取属性中的 URI?
【发布时间】:2016-01-12 05:56:04
【问题描述】:

我有一个集中定义的端点,它指向一个 RESTful API。目前它是一个 HTTP 端点,但如果需要,我也可以使用地址端点。

我的问题是我似乎找不到在属性中介器中访问端点 URI 的方法(就像您可以使用 LocalEntry 一样)。我需要在后续请求中嵌入 URI,所以我想做类似的事情:

<property name="api_endpoint" expression="get-property('ApiEndpoint')"/>

其中ApiEndpoint 是 ESB 中集中定义的端点。然后我可以使用 PayloadFactory 中介将其嵌入到进一步的请求中。

对此的任何帮助将不胜感激。

紧张

11 月 1 日更新

类似于以下答案的内容会很好:
https://stackoverflow.com/a/15265345/1784962

如果我可以访问配置注册表并获得类似于以下属性的端点 XML 配置,那就太好了:

<property name="test" 
          expression="string(get-property('registry', 'conf:/endpoints/Drupal_Endpoint.xml')//@uri-template)"/>

【问题讨论】:

    标签: wso2esb synapse


    【解决方案1】:

    根据我的理解,您正在尝试设置动态端点。您可以使用 HTTP 端点模板 [1] 实现此目的。查找以下示例代理服务。

    <?xml version="1.0" encoding="UTF-8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse"
           name="DynamicEndPointProxyService"
           transports="https,http"
           statistics="disable"
           trace="disable"
           startOnLoad="true">
       <target>
          <inSequence>
             <property name="endpoint_1"
                       value="http://ajanthan-ThinkPad-T440p:8089/test/get"
                       type="STRING"/>
             <log level="custom">
                <property name="SET ENDPOINT: " expression="get-property('endpoint_1')"/>
             </log>
             <send>
                <endpoint name="endpointName"
                          template="HttpEndPointTemplate"
                          uri="${endpoint_1}"/>
             </send>
             <log level="full"/>
          </inSequence>
          <outSequence>
             <log level="full"/>
             <send/>
          </outSequence>
       </target>
       <description/>
    </proxy> 
    

    [1]https://docs.wso2.com/display/ESB481/Working+with+Templates

    如果这是您所期望的,请更新。

    谢谢。 阿詹坦

    【讨论】:

    • 嗨 Ajanthan,您从哪里检索“endpoint_1”属性?它是否与您集中定义的端点相关联?为了便于配置,我的问题是指使用已定义的端点(即您在 ESB 管理控制台 UI 的 Endpoints 屏幕下定义的端点)。希望你仍然可以帮助我:)
    • 认为我在重命名属性时犯了一个错误。属性部分应该是这样的。 ajanthan-ThinkPad-T440p:8089/test/get" type="STRING"/> 并在此处定义端点 url。您的要求是从已定义的端点获取 uri。请添加您拥有的示例代理。这将有助于提供解决方案。
    • 您好,Ajanthan,感谢您的帮助。但我正在寻找类似的东西:stackoverflow.com/a/15265345/1784962 - 我尝试使用以下表达式访问属性中的端点配置: string(get-property('registry','conf:/endpoints/My_Endpoint.xml ')//@uri-template) - 但我什么也没得到。
    【解决方案2】:

    非常感谢@ajanthan-eliyatham 提供有关设置动态端点的提示!事实证明这是一个简单的修复,但我想比 ajanthan 提供的更详细一些(尽管如果有人 - 包括 ajanthan - 想扩展我的答案,我很高兴将其标记为正确)。

    在保存端点时选择“保存在注册表中”(如下图所示)很重要。这将提示您在 ESB 的配置注册表中提供存储密钥。

    将创建一个动态端点:

    您可以像这样在您的序列中引用完整的 XML 配置:

    <property name="drupal_ep"
                    expression="get-property('registry','conf:/Drupal_Endpoint')"
                    scope="default"
                    type="OM"/>
    

    但是,和我一样,如果您只对配置的 uri-template 组件感兴趣,您可以使用以下 XPATH 查询来提取相关属性:

    <property name="drupal_ep"
                    expression="get-property('registry','conf:/Drupal_Endpoint')"
                    scope="default"
                    type="OM"/>
    <property name="drupal_uri" 
              expression="get-property('drupal_ep')//@uri-template"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-19
      • 2013-07-05
      • 2019-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多