Developing SOA Applications using POJOs

GlassFish ESB

You may previously have used OpenESB, and if so you will be familiar with GlassFish ESB. GlassFish ESB is simply the OpenESB core runtime, bundled with the GlassFish application server, the NetBeans IDE and some of the more common JBI components already deployed to the ESB.

With release 2.2 of GlassFish ESB, the PoJo Service Engine has been included with the software download. Both GlassFish ESB and a number of additional JBI Components can be downloaded from the Open ESB website at:

Creating a PoJo and Deploying to GlassFish ESB

Using GlassFish ESB, its easy to create PoJos and deploy them to the JBI runtime adding different bindings such as SOAP or REST to it or to deploy them to the BPEL engine and use them as part of a business process. By deploying to GlassFish ESB, we are allowing many different types of client to consume our PoJos.

For this article, I'm going to write a simple PoJo that reverses strings and then deploy this to GlasFish ESB with a SOAP binding. This will allow any web service client that supports SOAP to access the PoJo.

If you are familiar at all with NetBeans, then creating a PoJo for deployment to the ESB will be a simple matter. The first stage is creating a Java project in which the PoJo can be created. Note that PoJos are created in standard Java projects and not in a SOA project template.

Using the "New Project" option in NetBeans, create a new "Java Class Library" project and call it ReversePoJo.

Developing SOA Applications using POJOs

Upon creating a standard Java Project, PoJos can be created in the project by using the New PoJo Service menu option under the ESB category. Select this option and create a new PoJo Service as shown below.

Developing SOA Applications using POJOs

Developing SOA Applications using POJOs

Class Name: ReversePoJo
Package: com.davidsalter.soa.reversepojo
Method Name: reverseString
Input Argument Type: String
Return Type: String

When we press the Finish button, NetBeans will create an empty PoJo using the details supplied. The code is shown below.

public class ReversePoJo {

public ReversePoJo() {

@Operation (outMessageTypeQN="{http://reversepojo.soa.}ReversePoJoOperationResponse")
public String reverseString(String input) {
return input;

Looking at this code, we can see that this is indeed a simple PoJo. The class does not extend any special framework classes and does not need to implement any framework interfaces. We can see however that there are two annotations used on the class which are required to allow us to deploy the class to GlassFish ESB.

@Provider defines that the PoJo is a JBI provider, i.e. it provides business logic to other components. In this case, we are stating that the ReversePoJo class can provide business logic to other components, either by adding bindings to the service and exposing directly from the ESB, or being invoked within the ESB from the BPEL runtime.

@Operation defines methods in the class that can be consumed - that is methods that other components can invoke. In the simplest case, @Operation methods take a String as a parameter and return a String. More complex types such as org.w3c.dom.Node and javax.jbi.messaging.NormalizedMessage can however be used for both input and output parameters.

To implement the reverseString method in this class, add the following implementation.

@Operation (outMessageTypeQN="{http://reversepojo.soa.}ReversePoJoOperationResponse")
public String reverseString(String input) {

StringBuffer reverse = new StringBuffer();
for (int i = input.length(); i > 0; i--) {

return reverse.toString();

This code simply takes the input argument, reverses it and returns it to the caller.

One of the benefits of writing PoJos for deployment to the ESB runtime is that the PoJos can be easily tested. Unit tests can be added to a NetBeans project by selecting the Tools | Create Unit Tests menu option in the project explorer. A simple unit test for this class is shown below.

public class ReversePoJoTest {

public ReversePoJoTest() {

public void testReverseString() {

String input = "abcdefg";
ReversePoJo instance = new ReversePoJo();
String expResult = "gfedcba";
String result = instance.reverseString(input);
assertEquals(expResult, result);


Creating A SOAP Binding for PoJos

So far, we've looked at PoJos and seen how we can create a PoJo project that can be deployed to the ESB, and how we can create PoJos within the project. To deploy our ReversePojo to the ESB, we need to add a SOAP binding to it. Within GlassFish ESB, we do this as a Composite Application.

To create a Composite Application, select File | New Project and create a Composite Application from the SOA category on the New Project dialog screen.

Developing SOA Applications using POJOs

Create a new Composite Application called ReverseCompositeApplication as shown in the following screen shot.

Developing SOA Applications using POJOs

Project Name: ReverseCompositeApp

Upon creating a blank composite application, the design surface for the application is shown.

Developing SOA Applications using POJOs

This surface allows the developer to add different JBI consumers and providers (such as the PoJo we developed earlier) to the composite application, wire them together and add different bindings to the application.

For this sample application, we first need to drag and drop the ReversePoJo java application into the JBI modules section of the design surface. This then registers our PoJo as a JBI module to use in the application. Next, we need to add a SOAP binding onto the application. This is done by dragging and dropping a SOAP WSDL binding from the WSDL Bindings palette onto the WSDL ports of the design surface. At this point we need to build the Composite application so that NetBeans can correctly display the components and we can wire them together. After building the application, simply drag a connection from the SOAP binding consumer port to the PoJo provider port to complete the application.

Developing SOA Applications using POJOs

What we've done here is created a Composite Application that uses the ReversePojo JBI module as a service provider. We've then added a SOAP binding onto the Composite Application so that external clients can access the PoJo via SOAP calls.

Testing the Composite Application

Now that we've written our simple composite application, we need to test it to ensure that it is all working as expected. To create a new test case, right click on the Test node for the ReverseCompositeApp and select New Test Case.

Developing SOA Applications using POJOs

When creating the test case, NetBeans will display a list of all of the WSDL files found within the Composite Application so that you can specify which one to test. We want to select the WSDL for the composite application so that we can perform a full integration test on the application. On the Select WSDL Document dialog, select ReverseCompositeApp.wsdl

Developing SOA Applications using POJOs

After selecting the WSDL to test, we need to select the operation we wish to test. Select ReversePoJoOperation on the following screen.

Developing SOA Applications using POJOs

Finally, select Finish to create the test case. When the test case is created, NetBeans will automatically show the XML that is to be passed to the web service for testing. This is stored in a file called Input.xml.

<soapenv:Envelope xsi:schemaLocation=

Edit this file and change the value of the <part1/> element as shown above. This data will be passed into the reverseString method of the ReversePoJo class, so we would expect to get a return result the same as we did for the JUnit test earlier - gfedcba.

Right click on the unit test and select the Run option to start the unit test. NetBeans will package up the Composite Application and deploy it to the JBI runtime, starting GlassFish if necessary. Since we have not specified any expected test results, NetBeans will ask if the results from the test are to be stored for future test runs.

Developing SOA Applications using POJOs

If we select Yes, the results are stored in the Output.xml file so when future tests are run, NetBeans will compare the test results with this file to indicate whether the tests are successful or not.

Opening up the Output.xml will show the test results.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=
<m:ReversePoJoOperationResponse xmlns:m="ReverseCompositeApp"

Hopefully, if everything has gone to plan, you will see the the <part1> element successfully contains the value gfedcba - the reverse of the input string.


In this article I've shown how GlassFish ESB can be used to create and deploy PoJo based JBI components and how composite applications can be created to consume the PoJo services with different WSDL bindings.

Although a simple example, hopefully this shows the power of the GlassFish ESB runtime which when combined with the design time tools of NetBeans can greatly aid development of integration and SOA based applications.

The source code for this article can be downloaded from:

You've been reading an excerpt of:

GlassFish Administration

Explore Title