Develop service components to provide reusable logic to multiple
applications within your server.
Before you begin
This task assumes that you have already developed and identified processing
that is useful for multiple modules.
About this task
Multiple modules can use a service component. Exporting a service
component makes it available to other modules that refer to the service component
through an interface. This task describes how to build the service component
so that other modules can use it.
Note: A single service component
can contain multiple interfaces.
Procedure
- Define the data object to move data between the caller and the
service component.
The data object and its type is part of the
interface between the callers and the service component.
- Define an interface that the callers will use to reference the
service component.
This interface definition names the service
component and lists any methods available within the service component.
- Generate the class that implements calling the service.
- Develop the implementation of the generated class.
- Save the component interfaces and implementations
in files with a .java extension.
- Package the service module and necessary resources
in a JAR file.
See "Deploying a module to a production server" in
this information center for a description of steps 6 through 8.
- Run the serviceDeploy command to create an installable
EAR file containing the application.
- Install the application on the server node.
- Optional: Configure the wires between the callers and
the corresponding service component, if calling a service component in another
service module.
The "Administering" section of this information
center describes configuring the wires.
Examples of developing components
This example shows
a synchronous service component that implements a single method, CustomerInfo.
The first section defines the interface to the service component that implements
a method called getCustomerInfo.
public interface CustomerInfo {
public Customer getCustomerInfo(String customerID);
}
The following block of code implements the service component.
public class CustomerInfoImpl implements CustomerInfo {
public Customer getCustomerInfo(String customerID) {
Customer cust = new Customer();
cust.setCustNo(customerID);
cust.setFirstName("Victor");
cust.setLastName("Hugo");
cust.setSymbol("IBM");
cust.setNumShares(100);
cust.setPostalCode(10589);
cust.setErrorMsg("");
return cust;
}
}
x
The following section is the implementation of the class
associated with StockQuote.
public class StockQuoteImpl implements StockQuote {
public float getQuote(String symbol) {
return 100.0f;
}
}
What to do next
Invoke the service.