I have a centrally defined endpoint that points to a RESTful API. At the moment it's a HTTP endpoint, but I can also work with an address endpoint if required.
My issue is that I can't seem to find a way to access the endpoint URI in a property mediator (much like you would be able to with a LocalEntry). I need to embed the URI in a subsequent request, so I'd like to do something like:
<property name="api_endpoint" expression="get-property('ApiEndpoint')"/>
Where ApiEndpoint
is the centrally defined endpoint in the ESB. I later can then use a PayloadFactory mediator to embed this in further requests.
Any help with this would be greatly appreciated.
Strainy
Update 11/01
Something similar to the following answer would do nicely:
https://stackoverflow.com/a/15265345/1784962
If I could access the configuration registry and get the endpoint XML configuration similar to the below property, that would be fantastic:
<property name="test"
expression="string(get-property('registry', 'conf:/endpoints/Drupal_Endpoint.xml')//@uri-template)"/>
Based on my understanding you are trying to set dynamic endpoint. You can achieve this using HTTP Endpoint Template [1]. Find the below sample proxy service.
<?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
Update if this is what you expected.
Thanks.
Ajanthan
Many thanks to @ajanthan-eliyatham for providing the hint around setting a dynamic endpoint! It turns out this was a simple fix, but I'd like to go into slightly more detail than what ajanthan has presented (though if anyone - including ajanthan - would like to expand on my answer, I'm happy to mark it as correct).
It's important that you select "Save in Registry" (as indicated in the image below) when saving an endpoint. This will prompt you to provide a key for storage in the configuration registry of the ESB.
A dynamic endpoint will be created:
You can reference the full XML configuration in your sequence like so:
<property name="drupal_ep"
expression="get-property('registry','conf:/Drupal_Endpoint')"
scope="default"
type="OM"/>
But, like me, if you're only interested in the uri-template component of the configuration you can use the following XPATH Query to extract the relevant attribute:
<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"/>