[jboss-svn-commits] JBL Code SVN: r20638 - labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jun 19 06:32:28 EDT 2008


Author: kevin.conner at jboss.com
Date: 2008-06-19 06:32:28 -0400 (Thu, 19 Jun 2008)
New Revision: 20638

Modified:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
Log:
narrow scope of JNDI context: JBESB-1821

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java	2008-06-19 08:41:08 UTC (rev 20637)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java	2008-06-19 10:32:28 UTC (rev 20638)
@@ -28,12 +28,12 @@
 import java.util.Properties;
 
 import javax.jms.DeliveryMode;
+import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.ObjectMessage;
 import javax.jms.Session;
-import javax.jms.Topic;
 import javax.naming.Context;
 import javax.naming.NamingException;
 import javax.xml.parsers.ParserConfigurationException;
@@ -98,26 +98,28 @@
 
     public void cleanup() {
         synchronized(this) {
-            if (_messageProducer != null) {
-                try {
-                    _messageProducer.close();
-                } catch (Exception e) {
-                    _logger.debug(e.getMessage(), e);
-                } finally {
-                    _messageProducer = null;
-                    closeSession();
+            try {
+                if (_messageProducer != null) {
+                    try {
+                        _messageProducer.close();
+                    } catch (Exception e) {
+                        _logger.debug(e.getMessage(), e);
+                    } finally {
+                        _messageProducer = null;
+                    }
                 }
-            }
 
-            if (_messageConsumer != null) {
-                try {
-                   _messageConsumer.close();
-                } catch (JMSException e) {
-                    _logger.debug(e.getMessage(), e);
-                } finally {
-                    _messageConsumer = null;
-                    closeSession();
+                if (_messageConsumer != null) {
+                    try {
+                       _messageConsumer.close();
+                    } catch (JMSException e) {
+                        _logger.debug(e.getMessage(), e);
+                    } finally {
+                        _messageConsumer = null;
+                    }
                 }
+            } finally {
+                closeSession() ;
             }
         }
     } // ________________________________
@@ -311,48 +313,46 @@
     } // ________________________________
 
     private void createMessageProducer() throws CourierException, NamingContextException {
-        Context oJndiCtx = null;
-        
         synchronized(this) {
             if (_messageProducer == null) {
                 try {
-                    oJndiCtx = NamingContextPool.getNamingContext(_epr.getJndiEnvironment());
-
-                    String sType = _epr.getDestinationType();
-                    if (JMSEpr.QUEUE_TYPE.equals(sType)) {
-                        Session qSess = getJmsSession(_epr.getAcknowledgeMode());
-                        javax.jms.Queue queue = null;
-                        try {
-                            queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
-                                    .getDestinationName());
-                        } catch (NamingException ne) {
+                    final Session session = getJmsSession(_epr.getAcknowledgeMode());
+                    Destination destination = null ;
+                    final String destinationName = _epr.getDestinationName() ;
+                    Context oJndiCtx = NamingContextPool.getNamingContext(_epr.getJndiEnvironment());
+                    try {
+                        String sType = _epr.getDestinationType();
+                        if (JMSEpr.QUEUE_TYPE.equals(sType)) {
                             try {
-                                oJndiCtx = NamingContextPool.replaceNamingContext(oJndiCtx, _epr.getJndiEnvironment());
-                                queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
-                                        .getDestinationName());
-                            } catch (NamingException nex) {
-                                //ActiveMQ
-                                queue = qSess.createQueue(_epr.getDestinationName());
+                                destination = (Destination) oJndiCtx.lookup(destinationName);
+                            } catch (NamingException ne) {
+                                try {
+                                    oJndiCtx = NamingContextPool.replaceNamingContext(oJndiCtx, _epr.getJndiEnvironment());
+                                    destination = (Destination) oJndiCtx.lookup(destinationName);
+                                } catch (NamingException nex) {
+                                    //ActiveMQ
+                                    destination = session.createQueue(destinationName);
+                                }
                             }
+                        } else if (JMSEpr.TOPIC_TYPE.equals(sType)) {
+                            try {
+                                destination = (Destination) oJndiCtx.lookup(destinationName);
+                            }
+                            catch (NamingException ne) {
+                                destination = session.createTopic(destinationName);
+                            }
+                        } else {
+                            throw new CourierException("Unknown destination type");
                         }
-                        _messageProducer = qSess.createProducer(queue);
-                    } else if (JMSEpr.TOPIC_TYPE.equals(sType)) {
-                        Session tSess = getJmsSession(_epr.getAcknowledgeMode());
-                        Topic topic = null;
-                        try {
-                            topic = (Topic) oJndiCtx.lookup(_epr
-                                    .getDestinationName());
+                        _messageProducer = session.createProducer(destination);
+                        _messageProducer.setDeliveryMode(_epr.getPersistent()?DeliveryMode.PERSISTENT:DeliveryMode.NON_PERSISTENT);
+                        if ( _logger.isDebugEnabled() )
+                            _logger.debug("JMSCourier deliveryMode: " + _messageProducer.getDeliveryMode() + ", peristent:" + _epr.getPersistent());
+                    } finally {
+                        if (oJndiCtx != null) {
+                            NamingContextPool.releaseNamingContext(oJndiCtx) ;
                         }
-                        catch (NamingException ne) {
-                            topic = tSess.createTopic(_epr.getDestinationName());
-                        }
-                        _messageProducer = tSess.createProducer(topic);
-                    } else {
-                        throw new CourierException("Unknown destination type");
                     }
-                    _messageProducer.setDeliveryMode(_epr.getPersistent()?DeliveryMode.PERSISTENT:DeliveryMode.NON_PERSISTENT);
-                    if ( _logger.isDebugEnabled() )
-                        _logger.debug("JMSCourier deliveryMode: " + _messageProducer.getDeliveryMode() + ", peristent:" + _epr.getPersistent());
                 }
                 catch (JMSException ex) {
                     _logger.debug("Error from JMS system.", ex);
@@ -361,10 +361,6 @@
                 }
                 catch (URISyntaxException ex) {
                     throw new CourierException(ex);
-                } finally {
-                    if (oJndiCtx != null) {
-                        NamingContextPool.releaseNamingContext(oJndiCtx) ;
-                    }
                 }
             }
         }
@@ -491,42 +487,39 @@
                 boolean success = false;
                 try {
                     Properties environment = _epr.getJndiEnvironment();
+                    final Session session = getJmsSession(_epr.getAcknowledgeMode());
+                    Destination destination = null ;
+                    final String destinationName = _epr.getDestinationName() ;
                     oJndiCtx = NamingContextPool.getNamingContext(environment);
                     try
                     {
                         String sType = _epr.getDestinationType();
                         if (JMSEpr.QUEUE_TYPE.equals(sType)) {
-                            Session qSess = getJmsSession(_epr.getAcknowledgeMode());
-                            javax.jms.Queue queue = null;
                             try {
-                                queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
-                                        .getDestinationName());
+                                destination = (Destination) oJndiCtx.lookup(destinationName);
                             } catch (NamingException ne) {
                                 try {
                                     oJndiCtx = NamingContextPool.replaceNamingContext(oJndiCtx, environment);
-                                    queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
-                                            .getDestinationName());
+                                    destination = (Destination) oJndiCtx.lookup(destinationName);
                                 } catch (NamingException nex) {
                                     //ActiveMQ
-                                    queue = qSess.createQueue(_epr.getDestinationName());
+                                    destination = session.createQueue(destinationName);
                                 }
                             }
-                            _messageConsumer = qSess.createConsumer(queue, _epr.getMessageSelector());
                         } else if (JMSEpr.TOPIC_TYPE.equals(sType)) {
-                            Session tSess = getJmsSession(_epr.getAcknowledgeMode());
-                            Topic topic = null;
                              try {
-                                   topic = (Topic) oJndiCtx.lookup(_epr
-                                                            .getDestinationName());
+                                   destination = (Destination) oJndiCtx.lookup(destinationName);
                              }
                              catch (NamingException ne) {
-                                   topic = tSess.createTopic(_epr.getDestinationName());
+                                   destination = session.createTopic(destinationName);
                              }
-                                  _messageConsumer = tSess.createConsumer(topic, _epr
-                                         .getMessageSelector());
                         } else {
                             throw new CourierException("Unknown destination type");
                         }
+                        if (destination == null) {
+                            throw new CourierException("Could not locate destination: " + destinationName);
+                        }
+                        _messageConsumer = session.createConsumer(destination, _epr.getMessageSelector());
                         success = true;
                     } finally {
                         NamingContextPool.releaseNamingContext(oJndiCtx) ;




More information about the jboss-svn-commits mailing list