Wednesday, February 11, 2009

How to create a Proxy Service in WSO2 ESB 2.0

The ability to host proxy services is a key feature of the WSO2 ESB. In this post I will explain how a Proxy Service can be created in the new WSO2 ESB 2.0 release.

As its name suggests a Proxy Service is a virtual service that hides the actual service. When defining a Proxy Service in the WSO2 ESB you could provide a inSequence, outSequence, faultSequence and a target endpoint (Not all of these are required).

A sequence as its name suggests send the message through a sequence of mediations. Hence users could perform mediation on requests heading into a Proxy Service (using the inSequence) as well as responses it receives (using the outSequence).

When an endpoint is defined in a Proxy Service, messages that are directed to it goes through the inSequence before been sent to the actual endpoint.

Now that we've covered a few basic ideas on the terms used in Proxy Services lets go ahead and create one. Its always advisable to declare entities in your configuration as reusable components (Just as you do it in OOP). Hence lets define our sequences and endpoints as reusable entities and use them in the creation of the Proxy Service.

For this example I would be creating a proxy service for the digit2image service which can be found on mooshup.com (The community site of the WSO2 Mashup Server).

  1. Lets create our endpoint. An Endpoint can be created by visiting the Endpoints link (Located under Manage).

    There are four distinct kind of endpoints, Please refer the documentation on endpoints for there detail. For this example I will create a simple Address Endpoint.


    When creating a address endpoint I simple specify its name and an Address (Having a look at the wsdl of our actual service, I find that the endpoint URL is http://mooshup.com/services/system/digit2image.SOAP12Endpoint/

  2. Lets create a sequence. A sequence can be created by visiting the Sequences link (Located under Manage)



    When it comes to sequences, you could create complex sequences using one or more of the inbuilt mediators or using your own custom mediators. For simplicity I will be creating a sequence with a simple Log mediator. All it does is log the message to the console.


  3. Now that we have our reusable components in place its time to create the actual Proxy Service. This can be done by visiting the Proxy Service link (Located Under Add).


    This will take you through a 3 step wizard.
    1. In the first step I provide a name for my service. Additionally I could configure several properties on a Proxy Service, for simplicity I will be sticking to the defaults. You could refer the documentation on Proxy Service creation for more details.


    2. step 2 asks for an Insiquence and a targetEndpoint. Its mandatory that you have at-least one of these. You could optionally have both as well. In our example lets use the sequence we created in Step 2 (DemoSequence) as the inSequence and the endpoint we created in Step 1 (digit2ImageServiceEndpoint) as our target endpoint.


    3. step 3 asks us for an outSequence and a faultSequence, both of which are optional. So lets use the default of none.

    Once you've done hit finish. Now we have created our new Proxy Service on WSO2 ESB 2.0.
Note : If you want this proxy service to be saved dont forget to go to the synapse link and hit save so that this Proxy will be available when you restart the server.

4 comments:

Yaytay said...

Creating a proxy service in that way doesn't give any control over the URL that is used to expose the proxy service.
How can I expose a proxy service on a URL that I specify (using a unique port number)?

Keith Chapman said...

The port number for this proxy service will be the port that the ESB is running on. I don't see any use in giving specific port numbers to proxy services. IMHO that's not a valid scenario.

Anonymous said...

Hey Keith, followed your direction to create the proxy and it successfully created one but why am i not able to use Try This Service? It throws me error "Fault: Server connection has failed. [detail]
Unknown". Can you plz advise? Btw, we are trying to use WSO2 ESB to host some services.Is it a good idea to still utilize the sample axis2 server to host services on ESB or should Axis2 server be used explicitly? Your directions will surely help. Thanks in adv.
Regards.

Dizzy said...

I have a few REST services running in WebLogic that I want to proxy through WSo2 ESB. Seems like mounting a REST based end point and exposing it as a SOAP based service is supported but it seems like I cannot simple proxy and mediate my REST service as a REST service through WSo2 ESB. The only proxy I can find in version 2.1.3 is a SOAP based proxy. We are using an AJAX based UI and MUST use REST. Any ideas?