This article assumes that you have installed IBM WebSphere ESB 6.0 and IBM WebSphere Integration Developer 6.0.
Introduction to WebSphere Enterprise Service Bus
WebSphere Enterprise Service Bus is a platform that allows applications to integrate in a flexible manner and helps an enterprise realize its Service-Oriented Architecture (SOA) goals. An ESB allows service consumers and service producers to interact with each other without any direct dependency between them. In an ESB, the application that requires services from other applications is termed the "service consumer" and the application that provides the service is termed a "service provider." An ESB decouples both the service consumer and producer, and it's important to note that you can change the interface definition of the service consumer or service producer without modifying the other.
WebSphere Enterprise Service Bus can perform the following major tasks, which decouple the service provider from the service consumer:
- Request and response routing: The entire communication between service provider and service consumer takes place in the form of a message. The service consumer requests the service and creates a request message for the ESB. The ESB platform will act as a transport medium between producer and consumer. The ESB will identify the actual service producer and pass the request to the producer. Once the service producer finishes the operation, it will generate the response in the form of a message and then give it back to the ESB. The ESB transmits the response back to the actual consumer. In the entire communication process, neither the producer nor the consumer are aware of each other. Only the ESB knows where to route the request and response messages.
- Message transformation and conversion:The ESB allows both the producer and consumer to have their own protocols and messaging formats. There is no need for them both to follow the same protocol and message formats -- the ESB takes care of handling different protocols and different message formats. It knows how to transform one message format into another and similarly, it knows how to convert a message in one protocol into another protocol.
The following diagram shows the role of an ESB:
Figure 1. ESB overview
Let's start with a sample service component that will convert Celsius to Fahrenheit. The Temperature Converter component has a method called convert which accepts the given temperature in Celsius as input and returns the corresponding temperature in Fahrenheit as the output. We'll test with a JavaServer Pages (JSP) client that accesses the service component through a standalone reference.
Every service component you are publishing in WebSphere ESB should have a well-defined interface. We can create the interface TemperatureConverterInterface for the above service component in WebSphere Integration Developer as shown below:
Figure 2. Creating a WSDL interface with the New Java Interface Wizard
Add a request and response operation with one input and one output to the above interface as shown below. Here the operation is named as convert with one input Celsius as double and one output Fahrenheit as double.
Figure 3. Adding operations to the interface
Implementing the service component as a POJO from WSDL through Assembly Editor
Next we create an implementation as a Plain Old Java Object (POJO) for the above interface. We can create the implementation (service component) in Java with the help of Assembly Editor as shown below. Assembly Editor, part of WebSphere Integration Developer, allows a developer to wire SCA components through interfaces (imports and exports) and bindings. We will name the implementation "TemperatureConverterImpl.java."
Figure 4. Creating a service component with Assembly Editor
Next we need to associate the interface TemperatureConverterInterface with this component through the "Add Interface" option.
Figure 5. Associating an interface with a generated service component
Now the interface is associated with the component. We can generate the skeleton of the implementation with the help of the "Generate Implementation" option.
Figure 6. Generating implementation for the new service component
Figure 7. Adding implementation to the generated skeleton
We need to provide the implementation of the convert method in the above class as shown below:
Listing 1. Convert method implementation
public Double convert(Double celsius) {
double dCelsius = celsius.doubleValue();
double fahr;
fahr = (((0.9/0.5) * dCelsius) + 32);
return new Double(fahr);
} |
Associating a service component with a standalone reference
The next step is to create a standalone reference and associate it with a service component so the JSP client can access the component through a standalone reference.
Figure 8. Creating a standalone reference
We can associate the TemperatureConverterInterface.wsdl with the standalone reference through the "Add Reference" button. By default, the standalone reference will be named TemperatureConverterInterfacePartner.
Figure 7. Wiring the standalone reference with a service component
Creating a client and accessing the service through a standalone reference
Now we need to develop a client JSP to test our service component. The JSP will allow the user to enter the Celsius value. That will in turn pass the value to the service to convert it into Fahrenheit, and finally, the result displays.
Figure 10. The new JSP file template
The component will be a called through JSP with the help of the ServiceManager class as shown below.
Listing 2. JSP implementation
String cel = request.getParameter("celcius");
if(cel != null && cel.length() > 0){
try{
ServiceManager serviceManager = new ServiceManager();
Service service = (Service) serviceManager.locateService
("TemperatureConverterInterfacePartner");
Double celDouble = Double.valueOf(cel);
DataObject respObject = (DataObject) service.invoke("convert", celDouble);
if(respObject!= null){
out.println(respObject.getDouble("Fahrenheit"));
}
}catch(Exception e){
//handele it
}
} |
Packaging and deploying the application in WebSphere ESB
The component and client are now ready to be packaged and deployed in WebSphere ESB for testing. Export the application as Integration Module EAR, as shown below.
Figure 11. Exporting the project as an integration module
Figure 12. Integration module exporting
Deploy the EAR file in WebSphere ESB through Admin Console and access "the URL" in your browser.
Figure 13. Final output
You now know how to create a service component using the bottom-up approach (interface to implementation), and how to publish it in IBM WebSphere ESB. And you learned how to access the service component from a client through a standalone reference.
| Description | Name | Size | Download method |
|---|---|---|---|
| Source code | Temp-Conv-Module.ear | 16KB | HTTP |
Information about download methods
- The developerWorks article
"Build an SOA framework with Apache Geronimo and POJOs" looks at some of the components and techniques of the Geronimo framework you can use for successful service-oriented development using POJO tactics.
-
"Java SCA invocation styles" offers an overview of Java usage within the Service Component Architecture's (SCA) Plain Old Java Object (POJO) component, and the data flow in and out of POJO components.
-
"Creating WebSphere Process Server Custom Selectors with WebSphere Integration Developer"
walks you through creating an IBM WebSphere Process Server 6.0 custom selector component that makes a selection based on the name of a component passed into the selector.
Comments (Undergoing maintenance)





