【问题标题】:WSO2 ESB REST API - Dynamic HTTP EndPoint (using Template Endpoint) Externalise - Hostname and port numberWSO2 ESB REST API - 动态 HTTP 端点(使用模板端点)外部化 - 主机名和端口号
【发布时间】:2014-03-31 05:46:11
【问题描述】:

我想在 HTTP 端点中外部化主机名和端口号,所以我试图在启动 ESB 时在 JVM 参数中传递主机名和端口号。 使用脚本/类中介,我可以从系统属性中获取它并将其放入消息上下文中。然后使用属性中介,我可以访问并记录它的值。 到目前为止,我没有任何问题,但是当我尝试使用此值替换 HTTP 端点时,如下所示;它不起作用。

实际的 ESB Synapse API 配置:


 <api xmlns="http://ws.apache.org/ns/synapse" name="ContentLength" context="/content">
    <resource methods="GET">
       <inSequence>
          <send>
             <endpoint>
               <http method="get" uri-template="http://198.160.1.223:8080/greeting/{uri.var.name}"></http>
             </endpoint>
          </send>
       </inSequence>
       <outSequence>
          <send></send>
       </outSequence>
   </resource>
 </api>

预期的 ESB Synapse API 配置:


  <api xmlns="http://ws.apache.org/ns/synapse" name="ContentLength" context="/content">
     <resource methods="GET">
        <inSequence>
            <script language="js">mc.setProperty("system.hostname",java.lang.System.getProperty("my.hostname"));mc.setProperty("system.port.no",java.lang.System.getProperty("my.port.no"));</script>
        <log level="custom">
           <property name="system.hostname" expression="get-property('system.hostname')"/>
           <property name="system.port.no" expression="get-property('system.port.no')"/>
        </log>
            <send>
              <endpoint>
                <http method="get" uri-template="http://{system.prop.my.hostname}:{system.prop.my.port.no}/greeting/{uri.var.name}"></http>
              </endpoint>
           </send>
        </inSequence>
        <outSequence>
           <send></send>
        </outSequence>
    </resource>
  </api>

在这种情况下有什么方法可以使用模板端点和 HTTP 端点?

也让我知道其他选择。

【问题讨论】:

    标签: wso2 wso2esb


    【解决方案1】:
    <property name="uri.var.host" expression="get-property('system.hostname')"/>
           <property name="uri.var.port" expression="get-property('system.port.no')"/>
        </log>
            <send>
              <endpoint>
                <http method="get" uri-template="http://{uri.var.host}:{uri.var.port}/greeting/{uri.var.name}"></http>
              </endpoint>
           </send>
    

    如上改变。它会起作用的。

    【讨论】:

    • 感谢拉加万。有效。我错过了点 uri 模板变量必须以 uri.var 开头。 [HTTP 端点允许您使用类似于 REST API 的 URI 模板定义 REST 端点。 URI 模板允许 RESTful URI 包含可以在调解运行时期间使用名称具有“uri.var”的属性值填充的变量。字首。 HTTP 端点还可以定义在 RESTful 调用中使用的特定 HTTP 方法。]
    【解决方案2】:

    由于您已要求提供替代选项,因此您可以在属性调解器中对主机名和端口进行字符串连接,然后直接在 uri 模板中使用它。

    请参考this link 以了解有关 http 端点的信息。

    【讨论】:

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