WSO2 ESB:从HTTP /地址端点获取属性中的URI?

时间:2016-01-10 09:37:49

标签: wso2esb synapse

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

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

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

其中ApiEndpoint是ESB中集中定义的端点。然后,我可以使用PayloadFactory介体将其嵌入到更多请求中。

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

Strainy

更新11/01

类似于以下答案的东西会做得很好:
https://stackoverflow.com/a/15265345/1784962

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

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

2 个答案:

答案 0 :(得分:2)

根据我的理解,您正在尝试设置动态端点。您可以使用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

答案 1 :(得分:0)

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

选择&#34; 保存在注册表中&#34;这一点非常重要保存端点时(如下图所示)。这将提示您在ESB的配置注册表中提供存储密钥。
enter image description here

将创建动态端点: enter image description here

您可以在序列中引用完整的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"/>
相关问题