WSO2 ESB : DYNAMICALLY CHANGE ENDPOINT ADDRESS

2019-01-15 19:22发布

问题:

how can i set endpoint address dynamically

i set endpoint address in to a property in run time and need to replace URI of endpoint address with it's value.

how can i set URI value of address with this value?

回答1:

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 )



回答2:

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



回答3:

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



回答4:

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



回答5:

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}