Chapter 11. JMS scenario 365
1.1.1) sendActivationMail() invokes sendMail(), passing the text of the
message and e-mail address.
1.1.2) sendMail() creates a connection to the message service provider, a
session for sending and receiving messages, and an empty text
message.
1.1.4) sendMail() sets the text for the message.
1.1.6) sendMail() creates a message producer to create a message.
1.1.8) sendMail() sends the message.
11.3 Applying the design guidelines
In the ITSOMart application, the following applies:
򐂰 The Mail Service Proxy acts as the JMS client.
򐂰 A JMS message of type
text is used to send the e-mail information to the
MailService.
򐂰 The default messaging provider in WebSphere Application Server V6 is used
as the JMS provider.
11.3.1 Point-to-point messaging model
The messaging model used for this example is the JMS point-to-point model. In
this model, a client typically sends a message to a specific queue and receives a
message from a specific queue. The ITSOMart application connects to a single
messaging application at the back-end and therefore point-to-point is the most
suitable model.
The front-end application uses the send-and-forget messaging pattern. The
back-end application uses the message consumer pattern to process requests
and the send-and-forget pattern to deliver the reply.
For further reference on JMS point-to-point and publish/subscribe, refer to the
JMS Specification available at:
http://java.sun.com/products/jms/docs.html
11.3.2 JMS resource lookups using JNDI
The sample application uses a utility class named JNDILookup to look up the
JMS resources. JMSLookup adds some useful functionality, such as caching the
JMS objects references. See Example 11-1 on page 366.
366 Patterns: Implementing Self-Service in an SOA Environment
Example 11-1 JNDI lookup of JMS Connection Factory
/*
* Created on Apr 17, 2005
*/
package com.ibm.patterns.util;
import java.util.HashMap;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @author sandyg
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class JNDILookup {
private static JNDILookup instance = new JNDILookup();
private Context ic = null;
private HashMap objectNames=new HashMap();
public static JNDILookup singleton() {
return instance;
}
private void getInitialContext() throws NamingException {
ic = (Context)new InitialContext().lookup("java:comp/env");
}
public Object getJndiObject(String jndiName) throws NamingException{
//Check if object exists in HashMap if so return
Object retreived=null;
if (objectNames.containsKey(jndiName)) {
retreived = objectNames.get(jndiName);
return retreived;
}
//The object was not found, do a lookup
retreived = findObject(jndiName);
return retreived;
}
private Object findObject(String jndiName) throws NamingException{
Object retreived=null;
//hmm.. object was not found, this is the first run we need to lookup
and put in HashMap

Get Patterns: Implementing Self-Service in an SOA Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.