0

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)"/>
Community
  • 1
  • 1
Strainy
  • 523
  • 1
  • 5
  • 19

2 Answers2

2

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

  • Hi Ajanthan, where are you retrieving the "endpoint_1" property from? Is it associated with your centrally defined endpoints? For ease of configuration, my question refers to using the already defined endpoints (i.e. the ones you define under the **Endpoints** screen in the ESB admin console UI). Hopefully you can still help me out :) – Strainy Jan 11 '16 at 09:25
  • Think i made a mistake when renaming the property. The property part should be like this. and defining the endpoint url here. Is your requirement is getting the uri from already defined endpoints. Please add a sample proxy you have. It will help to give a solution. – Ajanthan Eliyathamby Jan 11 '16 at 11:20
  • Hi Ajanthan, thanks for helping. But I'm looking for something similar to this: http://stackoverflow.com/a/15265345/1784962 - I've tried accessing the endpoint config in a property with the following expression: string(get-property('registry','conf:/endpoints/My_Endpoint.xml')//@uri-template) - but I'm not getting anything. – Strainy Jan 11 '16 at 11:25
0

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.
enter image description here

A dynamic endpoint will be created: enter image description here

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"/>
Strainy
  • 523
  • 1
  • 5
  • 19