This article extends Part 8 of the series, where you learned to use Enterprise Patterns to quickly build Java 2 Platform, Enterprise Edition (J2EE) applications using Rational Software Architect (RSA). In this article, you use the newly released WebSphere Platform Messaging Patterns to connect and integrate J2EE components. The results are simple examples of an ESB, an essential component in an SOA solution.
This article builds on the information in Part 8 and shows you how WebSphere Platform Messaging Patterns can help you rapidly configure connectivity on WebSphere Application Server (Application Server) 6.0. You also learn how to add mediation capabilities using the mediation patterns that are provided.
Overview of Rational Software Architect WebSphere Platform Messaging Patterns
The WebSphere Platform Messaging Patterns are packaged as a reusable asset that can be imported and installed into Rational Software Architect. This asset extends the Enterprise Patterns asset by adding support for WebSphere Platform Messaging. In this asset four application patterns generate EJB components and Java artifacts, and two topology patterns generate JACL script for configuring the service integration bus in Application Server 6.0.
The application patterns are:
- Message Delegate
- Used to create a client to send a message over JMS. Similar to the Business Delegate in the Enterprise Patterns, it is implemented as a plain old Java object (POJO). The pattern generates the code into the Application Client project and also automatically updates the application client deployment descriptor.
- Message Logger Mediation
- Logging of a message for audit purpose is a common mediation pattern. The Message Logger Mediation pattern leverages Service Data Object (SDO) to log the incoming message to a database table for future retrieval or audit.
- XSLT Mediation
- Transformation of the message from one format to another is also a common mediation pattern. The XSLT Mediation pattern enables users to transform the input message from one format to another using the XSLT stylesheet that is specified in the pattern parameter.
- Mediation List Handler
- Used to configure a list of mediations into a mediation handler list that can be invoked in sequence. A mediation handler list is a simple pipeline of mediations. This pattern updates the EJB deployment descriptors.
The topology patterns are:
- Service Integration Bus
- Configures the service integration bus on Application Server 6.0 to use a queue destination and to optionally associate mediation with the queue.
- JMS Connection
- Configures a Java Message Service (JMS) connection with Java Naming and Directory Interface (JNDI) names for the connection factory, queue, and activation spec for connecting to the physical queue. These parameters are used by the Message Delegate pattern to make a JMS connection.
Install WebSphere Platform Messaging Patterns
WebSphere Platform Messaging Patterns require Rational Software Architect 6.0.0.1 or 6.0.1. Installing this asset requires connecting to the RAS repository using the Rational XDE Repository Connection wizard, as shown in Part 8. Import the WebSphere Pattern Messaging Patterns asset using the Asset Explorer Import menu, as shown in Figure 1.
Figure 1. Importing WebSphere Platforms Messaging Patterns asset

After you restart Rational Software Architect, the WebSphere Platform Messaging Patterns appear in the Pattern Explorer, as show in Figure 2.
Figure 2. WebSphere Platform Messaging Patterns in Pattern Explorer

Relationship to Enterprise Patterns and ODFinance scenario
In Part 8 we used the Enterprise Patterns to create the Session Façade, Business Delegate, and the Message Façade code. Together they provide the function on the service provider side, as shown in Figure 3.
In this article, we'll extend what we built by generating a JMS client to send a message using the Message Delegate pattern. And we show you how to configure WebSphere Platform Messaging using the topology patterns. We'll then add the logging and XSLT transformation mediations to the bus using the mediation patterns that are included in the new asset.
Figure 3. Adding WebSphere Platform Messaging to the ODFinance scenario

Before you begin:
- Import the Finance.ear file from the download provided in Part 8. Figure 4 shows the J2EE perspective after the EAR is imported. The
AccountingMessageFacadeBeanimplements theonMessage()method that takes the input message and invokes the business delegate to update the customer information in the database. - Create a new Unified Modeling Language (UML) model, for example ESBDemo. Drag and drop the Service Integration Bus pattern into the model. The Service Integration Bus pattern takes two parameters:
- The first is a UML component with a <<Bus>> keyword to represent the bus.
- The second is a UML component with a <<Queue>> keyword to represent a queue destination.
Figure 4. J2EE perspective after importing Finance.ear

In Part 8, the user had to manually configure the Service Integration Bus using the Application Server 6.0 admin console. Using the WebSphere Platform Messaging Topology patterns, you can visually construct a deployment model and generate the underlying JACL scripts.
In this example, we create a bus named FinanceBus and a queue named FinanceQueue. In the FinanceBus component, specify the server name server1 and the node name wwwa-jabbottNode02. These UML components are shown in Figure 5.
Figure 5. Service Integration Bus Pattern

The next step is to use the JMS Connection pattern to create a JMS connection component that encapsulates the JMS connection parameters.
- Drag and drop the JMS Connection pattern into the model.
- Bind the
FinanceQueuecomponent to the Queue parameter. Review Part 8 of the series to get the JNDI names for the JMS resources (for example, connection factory is jms/FinanceCF). - Create a new UML component FinanceJMSConnection to encapsulate these parameters.
The completed pattern is shown in Figure 6.
Figure 6. JMS Connection Pattern

Run UML to JACL transform to generate the JACL script
The new UML to JACL transform is included in this asset. You can use the transform to generate a JACL script for the UML deployment model. Select Transform > Run Transformation > UML to JACL to invoke the transform, as shown in Figure 7. This generates a FinanceBus.jacl file in the FinanceEJB project under the ejbModule directory.
Figure 7. UML to JACL transformation

In a command line, invoke the wsadmin command (in the Application Server 6.0 bin directory) with the FinanceBus.jacl to create the bus and queue configuration:
wsadmin.bat âf e:\FinanceEJB\ejbModule\FinanceBus.jacl |
Figure 8 shows the messages that display on the Console tab after the JACL script is run.
Figure 8. Messages display on server console

Apply the Message Delegate pattern
Now that you've configured the Service Integration Bus, it's time to create the service requester that will send a message using the JMS connection.
In the model, create a new UML package, service.requester, to contain the client artifacts. Drag and drop the Message Delegate pattern. The first parameter represents the POJO class that will contain the
send message implementation. The second parameter takes a JMS UML component. Bind the FinanceJMSConnection component we created earlier into this parameter. Figure 9 shows the completed pattern instance.
Figure 9. Message Delegate pattern

Run UML to Java Transform to generate the client code
Create a new Application Client project called MessageRequester to contain the client code. Invoke the UML to Java Transform from the service.requester package and select MessageRequester Application Client Project, as shown in Figure 10. This generates the MessageDelegate implementation in this project under the service.requester package, as well as updates the application client deployment descriptor with the appropriate WebSphere bindings for the resource references.
Figure 10. UML to Java transformation

To send a message, you can select Run and create a new Application Server 6.0 application client configuration. Select the appropriate EAR and application client module. Select Run to run the application client. The WebSphere 6.0 Application Client console should now show the invocation of the MessageDelegate, as shown in Figure 11a. The AccountingMessageFacadeMDB then receives the message text with the customer information, as shown in Figure 11b.
Figure 11a. Service requester â application client sends a request message

Figure 11b. Service provider â AccountingMessageFacade MDB receives the message

Mediations allow you to manipulate a message as it traverses the bus. The Message Logger Mediation pattern logs a copy of the message to a database table. The XSLT Mediation pattern transforms the incoming message using the specified XSLT stylesheet. We can use the Mediation List Handler pattern to compose these two mediations into a single mediation handler list so they can be executed sequentially. In this section you will add mediations to the message being sent between the service requester and the service provider described earlier.
- In the model, create a new UML package called
mediations. - Drag and drop the Message Logger Mediation pattern. Generate a new class,
MessageLoggerMediationfor the logging mediation, and specify the JNDI name for the database. - Drag and drop the XSLT Mediation pattern. Generate a new class,
XSLTMediationfor the XSLT mediation, and specify the URI for the XSL stylesheet. - Drag and drop the Mediation List Handler pattern. Specify the name of the mediation list handler as
MyMediationList. Drag and drop the two mediations marked with the <<Mediation>> keyword into the second parameter.
Any class marked with the <<Mediation>> keyword can be added to the mediation list. Hence, you can implement your own mediation logic in the Java class that gets generated by the transform. Figure 12 shows the model after the three mediation patterns are applied.
Figure 12. Composing Mediations with patterns

Run UML to EJB Transform to generate the Mediation EJBs
Now let's generate the code for the mediations into the FinanceEJB project. Invoke the UML to EJB Transform from the mediations package and select the FinanceEJB project. This generates a new package (mediations) that contains the MessageLoggerMediation and the XSLTMediation class. It also updates the Mediation handlers in the EJB deployment descriptor.
Add the mediation to the message queue
You need to add the mediation handler list MyMediationList to the FinanceQueue before the logging and transformation can happen. To add the mediation handler, simply update the topology diagram in Figure 5 by creating an association to the <<Mediation>> MyMediationList, as shown in Figure 13.
Now run the UML to JACL transform again to generate a new JACL script. Notice that a new section is added to create the mediation and to mediate the queue. Run those sections in the JACL to update the Application Server 6.0 configuration.
Figure 13. Adding mediation to the FinanceQueue

Configure JNDI name for the Logging database
Make sure you set up the JDBC providers for logging table. The JNDI name must match the one specified in the MessageLoggerMediation, and the LOGMESSAGE table must be created in the database. (See the readme file in the code download for more detailed instructions.)
In this article, you learned how the recently released Rational Software Architect WebSphere Platform Messaging Patterns can help you rapidly build an ESB application on WebSphere Application Server 6.0. You also discovered how to compose a larger J2EE application using these new WebSphere Platform Messaging patterns together with the previous Enterprise Patterns such as Message Façade, Business Delegate, and Session Façade. As more and more reusable patterns are captured in Rational Software Architect, more of the best practices can be automatically generated, reducing the development time and improving overall quality.
| Description | Name | Size | Download method |
|---|---|---|---|
| Finance sample built with WPMPatterns | i-odoebp11code.zip | 1970KB | HTTP |
Information about download methods
Learn
-
"Building an Enterprise Service Bus with WebSphere Application Server V6 Series" (developerWorks, April 2005): Get details about implementing a JMS application.
- Pattern solutions: Learn more about the role of Patterns.
- Rational Software Architect: Learn more about Rational Software Architect.
- WebSphere Application Server: Get more information about WebSphere Application Server.
- "A practical introduction to message mediation, Part 1" (developerWorks, March 2005)
- "Working with the ESB and Mediations, Part 1" (developerWorks, February 2005): Get a practical guide on mediations.
Get products and technologies
- Rational Software Architect: Download a free trial version of Rational Software Architect.

Christina Lau is a Senior Technical Staff Member at IBM. Christina is an architect on the On Demand Development team focusing on next-generation technologies for the IBM On Demand Operating Environment.

Murray Beaton is an Advisory Software Developer for the On Demand Software Development team. Murray's previous role was Technical Team Lead with WebSphere Studio Application Developer.

James Abbott is an Advisory Software Developer for the On Demand Software Development team. His major focus is on patterns and transforms for model-driven development. During his career, he has worked on a series of model-based application development tools for IBM Rational Software and other companies.
Comments (Undergoing maintenance)

