About the Web Services Gateway sample

The Web Services Gateway sample shows how you can use SOAP nodes, operating in gateway mode, to call and provide a web service. This sample builds on two existing samples (SOAP Nodes and Address Book), and modifies the URL on the SOAPRequest nodes so that all requests are routed through a new gateway flow that forwards the request to the appropriate web service provider.

In the sample the operation is extracted from the SOAP request message and a user defined configurable service is used to retrieve the URL of the web service provider.

The sample wizard overrides the URL on the SOAPRequest nodes in the consumer flow bar files. If you choose to rebuild the bar files these settings might be cleared and the gateway flow not invoked.

A diagram illustrating the configuration of this sample

The Web Services Gateway sample demonstrates the following tasks:

Before You Start

Before you start, you must be familiar with the existing samples that this sample builds upon.

The Message Flow

The following diagram shows the Web Services Gateway message flow:

A screen capture of the web gateway message flow

The following table shows the nodes in the message flow:

Node type Node name
SOAPInput GatewayInput
JavaCompute ComputeURL
SOAPRequest SOAP Request
SOAPReply GatewayReply

The SOAPInput node operates in gateway mode and accepts requests from either the Address Book sample or SOAP Node sample consumer flows.

The JavaCompute node gets the operation name from the incoming request message and stores this in csName. The sample setup wizard creates a User Defined configurable service called Gateway, and a property matching the operation names for two consumer flows from the existing samples. The BrokerProxy is used to get the value of the configurable service and set the URL for the request in the local environment.

List nodeset = (List)message.getRootElement().evaluateXPath("SOAP/Body/*[1]");
String csName=((MbElement)(nodeset.get(0))).getName();
		
String URL = null;
	    
try {
	//Get the broker proxy
	BrokerProxy bp = BrokerProxy.getLocalInstance();
	//Find the URL from a configurable service
	URL = bp.getConfigurableServiceProperty("UserDefined/Gateway/"+csName);			
} catch (Exception e) {
	URL="/";
}
 
//Set the WebServiceURL creating the path if it doesn't exist
le.getRootElement().evaluateXPath("?Destination/?SOAP/?Request/?Transport/?HTTP/?WebServiceURL[set-value('"+URL+"')]");

The SOAPRequest node sends the request to the appropriate provider flow.

The SOAPReply node returns the response to the calling consumer flow.

The messages

The SOAP messages are generated by the existing consumer and provider flows. The gateway flow uses the operation name to route it to the correct provider.

Extending the sample

After running the sample you might want to extend it by adding another web service provider. Because a configurable service is used to store the URL for the provider, all you need to do is add a property with the name of an existing service operation, and the value set to the URL.

Back to sample home