Declaring a Wrapped JMS Factory using Deployment Descriptors

4-2 Programming JMS for Oracle WebLogic Server

4.1.1 Declaring JMS Objects as Resources In the EJB or Servlet Deployment Descriptors

The following sections provide information on declaring JMS objects as resources: ■ Section 4.1.1.1, Declaring a Wrapped JMS Factory using Deployment Descriptors ■ Section 4.1.1.2, Declaring JMS Destinations using Deployment Descriptors For more information about packaging EJBs, see Implementing Enterprise JavaBeans in Programming WebLogic Enterprise JavaBeans for Oracle WebLogic Server. For more information about programming servlets, see Creating and Configuring Servlets in Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server.

4.1.1.1 Declaring a Wrapped JMS Factory using Deployment Descriptors

You can declare a JMS connection factory as part of an EJB or servlet by defining a resource-ref element in the ejb-jar.xml or web.xml file, respectively. This process creates a wrapped JMS connection factory that can benefit from the more advanced session pooling, automatic transaction enlistment, connection monitoring, and container-managed security features described in Section 4.4, Improving Performance Through Pooling. Here is an example of such a connection factory element: resource-ref res-ref-namejmsQCFres-ref-name res-typejavax.jms.QueueConnectionFactoryres-type res-authContainerres-auth res-sharing-scopeShareableres-sharing-scope resource-ref This element declares that a JMS QueueConnectionFactory object be bound into JNDI, at the location: java:compenvjmsQCF This JNDI name is only valid inside the context of the EJB or servlet where the resource-ref is declared, which is what the java:compenv JNDI context signifies. In addition to this element, there must be a matching resource-description element in the ejb-jar.xml for EJBs or weblogic.xml for servlets file that tells the Java EE container which JMS connection factory to put in that location. Here is an example: resource-description res-ref-namejmsQCFres-ref-name jndi-nameweblogic.jms.ConnectionFactoryjndi-name resource-description The connection factory specified here must already exist in the global JNDI tree. This example uses one of the default JMS connection factories that is automatically created when the built-in WebLogic JMS server is used. To use another WebLogic JMS Note: New applications will likely use EJB 3.0 annotations instead of deployment descriptors. Annotations are described in Section 4.1.3, Declaring JMS Destinations and Connection Factories using Annotations . Enhanced Support for Using WebLogic JMS with EJBs and Servlets 4-3 connection factory from the same cluster, simply include that connection factorys JNDI name inside the jndi-name element. To use a connection factory from another vendor, or from another WebLogic Server cluster, create a Foreign JMS Server. If the JNDI name specified in the resource-description element is incorrect, the application is still deployed. However, you will receive an error when you try to use the connection factory.

4.1.1.2 Declaring JMS Destinations using Deployment Descriptors