Show TOC

Example: Describing JMS Connection Factories in the web-j2ee-engine.xmlLocate this document in the navigation structure

Use

We want to use a JMS connection factory with a custom resource name.

  1. In the jms-resources.xml in the external archive, the connection factory is described with a name which will serve as a resource name.

  2. In the web-j2ee-engine.xml in the Web application, we map the connection factory name to the new resource name.

  3. In the web.xml in the Web application, we describe the resource reference using the new resource name.

  4. In the source code of the Web application, we get the connection factory using JNDI lookup.

    The lookup string we use starts with java:comp/env , which is the standard prefix for looking up resources, and finishes with the new resource name.

The following graphic illustrates the above steps, the relations between the components, and the exact source code extracts.

Alternatively, you could use the same JMS connection factory without describing it in the web.xml and web-j2ee-engine.xml . You only need the description in the jms-resources.xml .

In such case, you access the JMS resource in the Web application source code using the following pattern:

Source Code
queueConnFactory = (QueueConnectionFactory) 
context.lookup("jmsfactory/default/<name>");
            

jmsfactory/default is the standard prefix to use in the lookup string in that case. <name> is the JMS connection factory name as specified in the jms-resources.xml .

With our connection factory, the source code may look like this:

Source Code
 public void doGet( HttpServletRequest req , HttpServletResponse resp){

                   //…
                   //Initializing naming context
                   Context ctx = new InitialContext();

                   //Connection Factory lookup 
        queueConnFactory = (QueueConnectionFactory) ctx.lookup("jmsfactory/default/TestQueueConnFactory");
        //operations with the obtained ConnectionFactory                
                //…
         }