WebSphere Enterprise Service Bus for z/OS, Version 6.2.0 Operating Systems: z/OS


Invoking components

Components with modules can use components on any node of a WebSphere® ESB cluster.

Before you begin

Before invoking a component, make sure that the module containing the component is installed on WebSphere ESB.

About this task

Components can use any service component available within a WebSphere ESB cluster by using the name of the component and passing the data type the component expects. Invoking a component in this environment involves locating and then creating the reference to the required component.
Note: A component in a module can invoke a component within the same module, known as an intra-module invocation. Implement external calls (inter-module invocations) by exporting the interface in the providing component and importing the interface in the calling component.
Important: When invoking a component that resides on a different server than the one on which the calling module is running, you must perform additional configurations to the servers. The configurations required depend on whether the component is called asynchronously or synchronously. How to configure the application servers in this case is described in related tasks.
Procedure
  1. Determine the components required by the calling module.

    Note the name of the interface within a component and the data type that interface requires.

  2. Define a data object.

    Although the input or return can be a Java™ class, a service data object is optimal.

  3. Locate the component.
    1. Use the ServiceManager class to obtain the references available to the calling module.
    2. Use the locateService() method to find the component.

      Depending on the component, the interface can either be a Web Service Descriptor Language (WSDL) port type or a Java interface.

  4. Invoke the component synchronously.

    You can either invoke the component through a Java interface or use the invoke() method to dynamically invoke the component.

  5. Process the return.

    The component might generate an exception, so the client has to be able to process that possibility.

Example of invoking a component

The following example creates a ServiceManager class.
ServiceManager serviceManager = new ServiceManager();
The following example uses the ServiceManager class to obtain a list of components from a file that contains the component references.
InputStream myReferences = new FileInputStream("MyReferences.references");
ServiceManager serviceManager = new ServiceManager(myReferences);
The following code locates a component that implements the StockQuote Java interface.
StockQuote stockQuote = (StockQuote)serviceManager.locateService("stockQuote");
The following code locates a component that implements either a Java or WSDL port type interface. The calling module uses the Service interface to interact with the component.
Tip: If the component implements a Java interface, the component can be invoked through either the interface or the invoke() method.
Service stockQuote = (Service)serviceManager.locateService("stockQuote");
The following example shows MyValue, code that calls another component.
public class MyValueImpl implements MyValue {

	public float myValue throws MyValueException {
		
		ServiceManager serviceManager = new ServiceManager();

	    // variables
	        Customer customer = null;
	        float quote = 0;
	        float value = 0;

	    // invoke
	        CustomerInfo cInfo = 
						(CustomerInfo)serviceManager.locateService("customerInfo");
	        customer = cInfo.getCustomerInfo(customerID);

	    if (customer.getErrorMsg().equals("")) {

	        // invoke
	    		StockQuote sQuote = 
						(StockQuote)serviceManager.locateService("stockQuote");
	    		Ticket ticket =  sQuote.getQuote(customer.getSymbol());
				// … do something else …
	    		quote =  sQuote.getQuoteResponse(ticket, Service.WAIT);

	        // assign
	        	value = quote * customer.getNumShares();
	    } else {

	        // throw
	       	throw new MyValueException(customer.getErrorMsg()); 
	    }
	    // reply
	        return value;
	}
}

What to do next

Configure the wires between the calling module references and the component interfaces.

task Task topic

Terms of use | Feedback


Timestamp icon Last updated: 21 June 2010


http://publib.boulder.ibm.com/infocenter/dmndhelp/v6r2mx/topic//com.ibm.websphere.wesb620.zseries.doc/doc/tdev_devclientcomps.html
Copyright IBM Corporation 2005, 2010. All Rights Reserved.
This information center is powered by Eclipse technology (http://www.eclipse.org).