Dynamically change endpoint address in WSO2 ESB
Asked Answered
G

6

6

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?

Gley answered 8/4, 2013 at 10:7 Comment(0)
R
5

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 )

Rooftree answered 4/6, 2015 at 11:31 Comment(1)
If the URI is not http?Etoile
A
2

Use Header meditaor to set "to" header and use default endpoint..Check this post for sample.

Alyssaalyssum answered 9/8, 2013 at 19:0 Comment(1)
That sample worked for me! The only change I did to make it work was to remove the <endpoint> and <default> tags from the top, and add them inside a <send> tag at the bottom. It'd look like this: <header xmlns:m1="services.samples/xsd" xmlns:m0="services.samples" name="To" expression="fn:concat(get-property('server'),get-property('service'))"/><send><endpoint><default/></endpoint></send></inSequence>Moazami
P
1

Use header mediator to set the "To" Address header with the value you extract from your assigned property.

Patter answered 9/4, 2013 at 2:20 Comment(1)
Thank you Mr Shelan Perera for your quick response. i used header mediator for this issue but i want to use End Point artifact so that i had more flexibility if require. how can i use xpath expression in endpoint? i used endpoint template but when i create endpoint from the template in console, only can set Value field not Expression in it's parameter. also i create EndPoint bye address and set Expression with get-property('EPadd') but it does not work. i do not know what should be written in the Xpath field when creating an EndPopint!Gley
L
0

When the server doesn't publish its WSDL, see Myobis comment here. Tried addPort without success.

Lavinalavine answered 26/1, 2014 at 17:35 Comment(0)
S
0

This method is worked for me correctly.

I need to create bellow dynamic url

http://localhost:8787/{dynamic parameter}

Inside the end point url is like this

http://localhost:8787/{uri.var.servicepath}

Set "test" variable as my dynamic parameter (If you need to set Expression value set it). Set "test" value inside the property mediator.(I did this insideproxy service)

<property name="uri.var.servicepath" scope="default" type="STRING" value="test"/>

create endpoint

In here I created HTTP End point

<endpoint name="ServiceEP" xmlns="http://ws.apache.org/ns/synapse">
   <http method="post" uri-template="http://localhost:8787/{uri.var.servicepath}"/>
</endpoint>

Then add this endpoint inside your Proxy service or API

<send>
   <endpoint key="ServiceEP"/>
</send>

Finally your proxy look like this

<inSequence>
   <property name="uri.var.servicepath" scope="default" type="STRING" 
   value="test"/>

   <send>
      <endpoint key="SurepayVASAppsEP"/>
    </send>
</inSequence>

Like this you can change every url parameter.Ex-:

http://{uri.var.hostname}:{uri.var.port}/{uri.var.servicepath}

Stephainestephan answered 20/7, 2017 at 5:22 Comment(0)
C
0

Another way to dynamically change the target endpoint url is through the use of the REST_URL_POSTFIX property.

Coccidioidomycosis answered 27/9, 2022 at 20:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.