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.
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>
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>
Is there any way I can use Template Endpoint and HTTP endpoint in this scenario ?
Let me know alternative options as well.
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.
Please refer this link to get an idea about http endpoints.
Change as above. It will work.