Invoking components

Components with modules can use components on any node of a WebSphere Process Server cluster.

Before you begin

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

Why and when to perform this task

Components can use any service component available within a WebSphere Process Server 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.

Steps for this task

  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 either synchronously or asynchronously.

    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
	    		StockQuoteAsync sQuote = 
						(StockQuoteAsync)serviceManager.locateService("stockQuote");
	    		Ticket ticket =  sQuote.getQuoteAsync(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.

Dynamically invoking a component

When an module invokes a component that has a Web Service Descriptor Language (WSDL) port type interface, the module must invoke the component dynamically using the invoke() method.

Before you begin

This task assumes that a calling component is invoking a component dynamically.

Why and when to perform this task

With a WSDL port type interface, a calling component must use the invoke() method to invoke the component. A calling module can also invoke a component that has a Java interface this way.

Steps for this task

  1. Determine the module that contains the component required.
  2. Determine the array required by the component.
    The input array can be one of three types:
    • Primitive uppercase Java types or arrays of this type
    • Ordinary Java classes or arrays of the classes
    • Service Data Objects (SDOs)
  3. Define an array to contain the response from the component.

    The response array can be of the same types as the input array.

  4. Use the invoke() method to invoke the required component and pass the array object to the component.
  5. Process the result.

Examples of dynamically invoking a component

In the following example, a module uses the invoke() method to call a component that uses primitive uppercase Java data types.
Service service = (Service)serviceManager.locateService("multiParamInf");
		
		Reference reference = service.getReference();

		OperationType methodMultiType = 
				reference.getOperationType("methodWithMultiParameter");

		Type t = methodMultiType.getInputType();

		BOFactory boFactory = (BOFactory)serviceManager.locateService
				("com/ibm/websphere/bo/BOFactory");

		DataObject paramObject = boFactory.createbyType(t);

		paramObject.set(0,"input1")
		paramObject.set(1,"input2")
		paramObject.set(2,"input3")

		service.invoke("methodMultiParamater",paramObject);

The following example uses the invoke method with a WSDL port type interface as the target.

Service serviceOne = (Service)serviceManager.locateService("multiParamInfWSDL");
	
	DataObject dob = factory.create("http://MultiCallWSServerOne/bos", "SameBO");
			dob.setString("attribute1", stringArg);

	DataObject wrapBo = factory.createByElement
		("http://MultiCallWSServerOne/wsdl/ServerOneInf", "methodOne");
			wrapBo.set("input1", dob); //wrapBo encapsulates all the parameters of methodOne
			wrapBo.set("input2", "XXXX");
			wrapBo.set("input3", "yyyy");

	DataObject resBo= (DataObject)serviceOne.invoke("methodOne", wrapBo);

Terms of use |

Last updated: Tue Feb 21 17:21:49 2006

(c) Copyright IBM Corporation 2005.
This information center is powered by Eclipse technology (http://www.eclipse.org)