Dynamically change endpoint address in WSO2 ESB

Ramtin Ramtin picture Ramtin Ramtin · Apr 8, 2013 · Viewed 7k times · Source

How can I set the endpoint address dynamically?

I set endpoint address in a property at runtime, and need to replace the URI of endpoint address with its value.

How can I set the URI value of address with this value?

Answer

Brian picture Brian · Jun 4, 2015

You can create your endpoint like

<endpoint xmlns="http://ws.apache.org/ns/synapse" name="MyEndpoint">
   <http uri-template="{uri.var.full}?f={uri.var.f}{+uri.var.extra}" method="put">
   </http>
</endpoint>

Then before calling the endpoint 'MyEndpoint' set the properties .. the properties, to be parsed for an endpoint must begin with uri.

I also found out, that if you put a + before the property name, it doesn't URI encode it, so it's handy for creating parameters on the fly.. otherwise for known parameters, you can do like above for paramameter f

so .. something like

<property name="uri.var.full" value="http://jarhedz.com/viewtopic.php"/>
<property name="url.var.f" value="2"/>
<property name="uri.var.extra" value="&t=39"/>
<send>
    <endpoint key="MyEndpoint"></endpoint>
</send>

should bring you to the url http://jarhedz.com/viewtopic.php?f=2&t=39

(btw just as a note, if you're using the web editor, it'll complain about the & .. its buggy as hell .. save it as

&amp; 

.. and that saves it as & or set the property using javascript )