Search code examples
urlwso2sendapache-synapsewso2-esb

How can I assign a url from a property for a Send Mediator within WSO2 ESB?


I'm looking to create a Send Mediator using a url that's configured within a separate database.

I have the url in question assigned to a property myurl within my sequence.

How can I create a send using this property as the send's url?

Something like ..

<property name="myurl" value="http://www.google.com"></property>
<send>
  <endpoint>
    <http method="put" uri-template="{myurl}"></http>
  </endpoint>
</send>

errors .. (uri-mapping and using get-property('myurl') etc in the endpoint above has no luck either)

Using the URL ReWriter Mediator didn't help me, as the action doesn't allow an expression, only value

<rewrite>
  <rewriterule>
    <action value="get-property('myurl')" type="set" fragment="full"></action>
  </rewriterule>
</rewrite>
<send></send>

I'm not sure, even if the above worked .. how I'd be able to define it's a POST too ..

Any help would be gratefully appreciated!


Solution

  • You are missing the uri.var prefix for your property names. This page has more details on this.

    The URI templates allow a RESTful URI to contain variables that can be populated during mediation runtime using property values whose names have the "uri.var." prefix.

    Here is an example from the WSO2 docs of an endpoint that uses property names:

    <endpoint xmlns="http://ws.apache.org/ns/synapse" name="HTTPEndpoint">
        <http uri-template="http://localhost:8080/{uri.var.servicepath}/restapi/{uri.var.servicename}/menu?category={uri.var.category}&amp;type={uri.var.pizzaType}" method="GET"></http>
    </endpoint>
    

    And the part from the proxy service that calls the endpoint:

    <inSequence>           
        <property name="uri.var.servicepath" value="PizzaShopServlet"/>
        <property name="uri.var.servicename" value="PizzaWS"/>
        <property name="uri.var.category" value="pizza"/>
        <property name="uri.var.pizzaType" value="pan"/>
        <send>
            <endpoint key="HTTPEndpoint"/>
        </send>
    </inSequence>