WSO2 ESB REST API - 动态 HTTP 端点(使用模板端点)外部化 - 主机名和端口号 [英] WSO2 ESB REST API - Dynamic HTTP EndPoint (using Template Endpoint) Externalise - Hostname and port number

查看:25
本文介绍了WSO2 ESB REST API - 动态 HTTP 端点(使用模板端点)外部化 - 主机名和端口号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to externalize the hostname and port number in HTTP endpoint, so I am trying to pass the hostname and port number in JVM argument while starting the ESB. Using script/class mediator, I can get it from system properties and put it in message context. Then using property mediator, I can access and log the value of it. Till this point, I don't have any issue but when I try to use this value to replace in the HTTP endpoint as below; it doesn't work.

实际 ESB Synapse API 配置:

Actual ESB Synapse API Config:

 <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 配置:

Expected ESB Synapse API Config:

  <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 端点?

Is there any way I can use Template Endpoint and HTTP endpoint in this scenario ?

也请告诉我其他选择.

推荐答案

既然您已经要求替代选项,您可以在主机名和端口的属性中介处进行字符串连接,然后直接在 uri-模板中使用它.

Since you have asked for alternative options you can do string concatenation at the property mediator for hostname and port and then directly use it in the uri-template.

请参阅此链接以了解有关 http 端点的信息.

Please refer this link to get an idea about http endpoints.

这篇关于WSO2 ESB REST API - 动态 HTTP 端点(使用模板端点)外部化 - 主机名和端口号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆