Skip to main content

Get started with WebSphere ESB: Create and publish POJO as a service

Vasudevan Thiyagarajan (vthiyaga@in.ibm.com), System Engineer, IBM India Pvt. Ltd.
Vasudevan Thiyagarajan is a system engineer with IBM in Bangalore, India, and is involved in Telecom related-product development in the IBM WebSphere family. He holds a masters degree in Computer Applications. His areas of interest include distributed computing and middleware technologies.

Summary:  Learn how to develop a service component from a Plain Old Java™ Object (POJO) and publish it in IBM® WebSphere® Enterprise Service Bus. Find out how to define an interface in the Web Services Description Language (WSDL) and implement it in Java™, and see how to associate a service component with a standalone reference and how to use a standalone reference to access the service across the ESB.

Date:  17 Nov 2006
Level:  Introductory
Activity:  1151 views

Prerequisites

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:

  1. 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.
  2. 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
ESB overview

Creating an interface in WSDL

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
Creating a WSDL interface with the New 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
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
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
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
Generating implementation for the new service component

Figure 7. Adding implementation to the generated skeleton
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
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
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
Template of the new JSP file

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
Exporting the project as an integration module

Figure 12. Integration module exporting
Exporting the project as an integration module

Deploy the EAR file in WebSphere ESB through Admin Console and access "the URL" in your browser.


Figure 13. Final output
Final output

Conclusion

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.



Download

DescriptionNameSizeDownload method
Source codeTemp-Conv-Module.ear16KBHTTP

Information about download methods


Resources

About the author

Vasudevan Thiyagarajan is a system engineer with IBM in Bangalore, India, and is involved in Telecom related-product development in the IBM WebSphere family. He holds a masters degree in Computer Applications. His areas of interest include distributed computing and middleware technologies.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=SOA and Web services
ArticleID=175171
ArticleTitle=Get started with WebSphere ESB: Create and publish POJO as a service
publish-date=11172006
author1-email=vthiyaga@in.ibm.com
author1-email-cc=flanders@us.ibm.com

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers