PoolTest.java PoolTestHome.java PoolTestBean.java

4-12 Programming JMS for Oracle WebLogic Server res-sharing-scopeShareableres-sharing-scope resource-ref resource-env-ref resource-env-ref-namejmsTESTQUEUEresource-env-ref-name resource-env-ref-typejavax.jms.Queueresource-env-ref-type resource-env-ref session enterprise-beans assembly-descriptor container-transaction method ejb-namePoolTestBeanejb-name method-namemethod-name method trans-attributeRequiredtrans-attribute container-transaction assembly-descriptor ejb-jar

4.6.1.2 weblogic-ejb-jar.xml

This section declares matching resource-description queue connection factory and queue destination elements that tell the Java EE container which JMS connection factory and destination to put in that location. DOCweblogic-ejb-jar xmlns=http:www.bea.comnsweblogic920 xmlns:xsi=http:www.w3.org2001XMLSchema-instance xsi:schemaLocation=http:www.bea.comnsweblogic920 http:www.bea.comnsweblogic920weblogic-ejb-jar.xsd ... weblogic-ejb-jar weblogic-enterprise-bean ejb-namePoolTestBeanejb-name stateless-session-descriptor pool max-beans-in-free-pool8max-beans-in-free-pool initial-beans-in-free-pool2initial-beans-in-free-pool pool stateless-session-descriptor resource-description res-ref-namejmsQCFres-ref-name jndi-nameweblogic.jms.XAConnectionFactoryjndi-name resource-description resource-env-description res-env-ref-namejmsTESTQUEUEres-env-ref-name jndi-nameTESTQUEUEjndi-name resource-env-description jndi-namePoolTestjndi-name weblogic-enterprise-bean weblogic-ejb-jar

4.6.1.3 PoolTest.java

This section defines the remote interface for the PoolTest bean. It declares one method, called sendXATransactional. package weblogic.jms.pool.test; Enhanced Support for Using WebLogic JMS with EJBs and Servlets 4-13 import java.rmi.; import javax.ejb.; public interface PoolTest extends EJBObject { public String sendXATransactionalString text throws RemoteException; }

4.6.1.4 PoolTestHome.java

This section defines the home interface for the PoolTest bean. It is required by the EJB specification. package weblogic.jms.pool.test; import java.rmi.; import javax.ejb.; public interface PoolTestHome extends EJBHome { PoolTest create throws CreateException, RemoteException; }

4.6.1.5 PoolTestBean.java

This section defines the actual EJB code. It sends a message whenever the sendXATransactional method is called. package weblogic.jms.pool.test; import java.lang.reflect.; import java.rmi.; import javax.ejb.; import javax.jms.; import javax.naming.; import javax.transaction.; public class PoolTestBean extends PoolTestBeanBase implements SessionBean { private SessionContext context; private QueueConnectionFactory qcf; private Queue destination; public void ejbActivate { } public void ejbRemove { } public void ejbPassivate { } public void setSessionContextSessionContext ctx 4-14 Programming JMS for Oracle WebLogic Server { context = ctx; } private void lookupJNDIObjects throws NamingException { InitialContext ic = new InitialContext; try { qcf = QueueConnectionFactoryic.lookup java:compenvjmsQCF; destination = Queueic.lookupjava:compenvjmsTESTQUEUE; } finally { ic.close; } } public void ejbCreate throws CreateException { try { lookupJNDIObjects; } catch NamingException ne { throw new CreateExceptionne.toString; } } public String sendXATransactionalString text throws RemoteException { String id = Not sent yet; try { if qcf == null || destination == null { lookupJNDIObjects; } QueueConnection connection = qcf.createQueueConnection; try { QueueSession session = connection.createQueueSession false, 0; TextMessage message = session.createTextMessage text; QueueSender sender = session.createSenderdestination; sender.sendmessage; id = message.getJMSMessageID; } finally { connection.close; } } catch Exception e { Invalidate the JNDI objects if there is a failure this is necessary because the destination object may become invalid if the destination server has been shut down qcf = null; destination = null; throw new RemoteExceptionFailure in EJB: + e; } return id; } Enhanced Support for Using WebLogic JMS with EJBs and Servlets 4-15 }

4.6.2 Sending a JMS Message In a Java EE Container