Friday, August 9, 2013

Defining dynamic endpoint in wso2esb

In synapse(/wso2esb), when we define endpoints, we have to provide endpoint URL, which is  most of the time  hard coded. Those endpoint urls can not be changed dynamically at runtime.
But if user likes to send requests to an endpoint which address has to be constructed from incoming request/any other way, we can use Header mediator with Property mediator to achieve this.
For instance, if the End service name has to be picked from the request, we can use property mediator to pick and store the service name. Later use the Header mediator to set "To" header using the property mediator and forward the request to default endpoint.

The sample request is as follows( it contains the service name , which is used to find the endpoint address)

<soapenv:Envelope xmlns:soapenv="" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
            <xsd:symbol>MSFT </xsd:symbol>  

If we send above request to the "testProxy", which will forward the request to http://localhost:9000/services/SimpleStockQuoteService endpoint, which can be constructed as mentioned above.

testProxy conf:

  <proxy name="testProxy"    transports="https http"
          startOnLoad="true"   trace="disable">
            <property name="server"  value="http://localhost:9000/services/"
                      scope="default"  type="STRING"/>
            <property xmlns:m1="http://services.samples/xsd"
                      name="service"   expression="//m0:getQuote/m0:request/m1:service"
                      scope="default"   type="STRING"/>
            <header xmlns:m1="http://services.samples/xsd"
                    xmlns:m0="http://services.samples"   name="To"

You can use xpath functions in the Header/Property mediator expressions.


  1. This comment has been removed by the author.

  2. This comment has been removed by the author.

  3. This comment has been removed by the author.

  4. Getting following WARNING while using Header Mediator:

    targetHandler Connection closed by target host before receiving the request

    Can you please suggest something else that I can use here to make SOAP request URL dynamic?

  5. You get above issue because backend server has closed the connection after reading the request without sending a response back. Check with increased backend server connection timeout.

    In the above sample, the Header mediator sets the "To" header, where the request needs to be sent.(That is your actual backend service)

    Try invoke the backend service directly and see you can get response. Then try to troubleshoot the actual issue.

    Other way is, if you use ESB > V4.8.0, try to use HTTP endpoint.[1]