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?

Community
  • 1
  • 1
Ramtin Ramtin
  • 173
  • 3
  • 12

6 Answers6

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 )

Brian
  • 186
  • 2
  • 11
2

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

Ratha
  • 9,434
  • 17
  • 85
  • 163
  • That sample worked for me! The only change I did to make it work was to remove the and tags from the top, and add them inside a tag at the bottom. It'd look like this:
    – lsantsan Mar 24 '15 at 17:04
1

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

Shelan Perera
  • 1,753
  • 1
  • 11
  • 10
  • 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! – Ramtin Ramtin Apr 10 '13 at 08:22
0

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

Community
  • 1
  • 1
karl
  • 1,059
  • 11
  • 12
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}

Priyantha
  • 4,839
  • 6
  • 26
  • 46
0

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

Scott
  • 46
  • 5