[jboss-svn-commits] JBL Code SVN: r32793 - in labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta: tests/src/org/jboss/soa/esb/actions/routing and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon May 10 09:36:14 EDT 2010


Author: kevin.conner at jboss.com
Date: 2010-05-10 09:36:13 -0400 (Mon, 10 May 2010)
New Revision: 32793

Modified:
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JMSRouterUnitTest.java
Log:
Add support for topics back into JMSRouter: JBESB-3288

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java	2010-05-08 01:23:37 UTC (rev 32792)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java	2010-05-10 13:36:13 UTC (rev 32793)
@@ -33,7 +33,6 @@
 import javax.jms.Message;
 import javax.jms.MessageProducer;
 import javax.jms.ObjectMessage;
-import javax.jms.Queue;
 import javax.jms.TextMessage;
 import javax.naming.Context;
 import javax.naming.NamingException;
@@ -167,9 +166,9 @@
      */
     private ConfigTree properties;
     /**
-     * The JMS Queue name from the configuration
+     * The JMS Destination name from the configuration
      */
-    private String queueName;
+    private String destinationName;
     /**
      * Strategy for setting JMSProperties
      */
@@ -217,7 +216,7 @@
      * Sole public constructor.
      * 
      * @param propertiesTree Action properties.
-     * @throws ConfigurationException Queue name not configured.
+     * @throws ConfigurationException Destination name not configured.
      * @throws JMSException Unable to configure JMS destination.
      * @throws NamingException Unable to configure JMS destination.
      */
@@ -226,8 +225,8 @@
 
         this.properties = propertiesTree;
 
-        queueName = properties.getAttribute("jndiName");
-        if(queueName == null) {
+        destinationName = properties.getAttribute("jndiName");
+        if(destinationName == null) {
             throw new ConfigurationException("JMSRouter must specify a 'jndiName' property.");
         }
 
@@ -284,7 +283,7 @@
             throw new ConfigurationException("Unexpected error obtaining JMS connection pool") ;
         }
         
-        createQueueSetup(queueName, jndiContextFactory, jndiUrl, jndiPkgPrefix, connectionFactory, securityPrincipal, securityCredential);
+        createQueueSetup(destinationName, jndiContextFactory, jndiUrl, jndiPkgPrefix, connectionFactory, securityPrincipal, securityCredential);
     }
 
     /**
@@ -332,7 +331,7 @@
         SESSION.set(jmsSession) ;
         try {
             if(!(message instanceof org.jboss.soa.esb.message.Message)) {
-                throw new ActionProcessingException("Cannot send Object [" + message.getClass().getName() + "] to destination [" + queueName + "]. Object must be an instance of org.jboss.soa.esb.message.Message) .");
+                throw new ActionProcessingException("Cannot send Object [" + message.getClass().getName() + "] to destination [" + destinationName + "]. Object must be an instance of org.jboss.soa.esb.message.Message) .");
             }
         
             final org.jboss.soa.esb.message.Message esbMessage = (org.jboss.soa.esb.message.Message)message;
@@ -355,7 +354,7 @@
             } catch (JMSException jmse) {
                 throw jmse ;
             } catch(Exception e) {
-                final String errorMessage = "Exception while sending message [" + message + "] to destination [" + queueName + "]." ;
+                final String errorMessage = "Exception while sending message [" + message + "] to destination [" + destinationName + "]." ;
                 logger.error(errorMessage);
                 throw new ActionProcessingException(errorMessage, e);
             }
@@ -383,7 +382,7 @@
         	jmsMessage = SESSION.get().createTextMessage();
 
             if(logger.isDebugEnabled()) {
-                logger.debug("Sending Text message: [" + objectFromBody + "] to destination [" + queueName + "].");
+                logger.debug("Sending Text message: [" + objectFromBody + "] to destination [" + destinationName + "].");
             }
 
             ((TextMessage)jmsMessage).setText((String)objectFromBody);
@@ -391,7 +390,7 @@
         	jmsMessage = SESSION.get().createBytesMessage();
 
             if(logger.isDebugEnabled()) {
-                logger.debug("Sending byte[] message: [" + objectFromBody + "] to destination [" + queueName + "].");
+                logger.debug("Sending byte[] message: [" + objectFromBody + "] to destination [" + destinationName + "].");
             }
 
             ((BytesMessage)jmsMessage).writeBytes((byte[])objectFromBody);
@@ -439,7 +438,7 @@
 		jmsMessage = SESSION.get().createObjectMessage();
 
 		if(logger.isDebugEnabled()) {
-		    logger.debug("Sending Object message: [" + message + "] to destination [" + queueName + "].");
+		    logger.debug("Sending Object message: [" + message + "] to destination [" + destinationName + "].");
 		}
 		((ObjectMessage)jmsMessage).setObject((Serializable) message);
 		return jmsMessage;
@@ -471,7 +470,7 @@
         return null;
     }
 
-    protected void createQueueSetup( String queueName,
+    protected void createQueueSetup( String destinationName,
     		String jndiContextFactory,
     		String jndiUrl,
     		String jndiPkgPrefix,
@@ -487,15 +486,10 @@
                 Context oCtx = NamingContextPool.getNamingContext(environment);
                 try {
                     try {
-                        jmsDestination = (Queue) oCtx.lookup(queueName);
+                        jmsDestination = (Destination) oCtx.lookup(destinationName);
                     } catch (NamingException ne) {
-                        try {
-                            oCtx = NamingContextPool.replaceNamingContext(oCtx, environment);
-                            jmsDestination = (Queue) oCtx.lookup(queueName);
-                        } catch (NamingException nex) {
-                            //ActiveMQ
-                            jmsDestination = jmsSession.createQueue(queueName);
-                        }
+                        oCtx = NamingContextPool.replaceNamingContext(oCtx, environment);
+                        jmsDestination = (Destination) oCtx.lookup(destinationName);
                     }
                     final MessageProducer jmsProducer = jmsSession.createProducer(jmsDestination);
                     jmsProducer.close() ;
@@ -508,7 +502,7 @@
 		} 
 		catch (Throwable t) 
 		{
-			throw new ConfigurationException("Failed to configure JMS Queue for routing.", t);
+			throw new ConfigurationException("Failed to configure JMS Destination for routing.", t);
 		}
     }
     
@@ -517,9 +511,9 @@
         return environment ;
     }
     
-    protected void createQueueSetup( String queueName ) throws ConfigurationException
+    protected void createQueueSetup( String destinationName ) throws ConfigurationException
 	{
-    	createQueueSetup(queueName, null, null, null, null, null, null);
+    	createQueueSetup(destinationName, null, null, null, null, null, null);
 	}
     
 

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JMSRouterUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JMSRouterUnitTest.java	2010-05-08 01:23:37 UTC (rev 32792)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JMSRouterUnitTest.java	2010-05-10 13:36:13 UTC (rev 32793)
@@ -43,6 +43,7 @@
 import javax.jms.QueueSession;
 import javax.jms.Session;
 import javax.jms.TextMessage;
+import javax.jms.TopicConnection;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -66,9 +67,11 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.MockTopic;
 import org.mockejb.jms.ObjectMessageImpl;
 import org.mockejb.jms.QueueConnectionFactoryImpl;
 import org.mockejb.jms.TextMessageImpl;
+import org.mockejb.jms.TopicConnectionFactoryImpl;
 import org.mockejb.jndi.MockContextFactory;
 
 /**
@@ -79,7 +82,9 @@
 public class JMSRouterUnitTest
 {
     private static final String CONNECTION_FACTORY = "ConnectionFactory" ;
+    private static final String TOPIC_CONNECTION_FACTORY = "TopicConnectionFactory" ;
     private static final String QUEUE_NAME = "failQueue" ;
+    private static final String TOPIC_NAME = "failTopic" ;
     private static final String PROPERTY_SETTER_TEST_NAME = "MockJMSPropertiesSetter" ;
     private final String messageID = "1234-junittest";
     private final String bodyContent = "hello";
@@ -96,7 +101,9 @@
         try
         {
             ctx.rebind(CONNECTION_FACTORY, new MockQueueConnectionFactory());
+            ctx.rebind(TOPIC_CONNECTION_FACTORY, new MockTopicConnectionFactory());
             ctx.rebind(QUEUE_NAME, new MockQueue(QUEUE_NAME));
+            ctx.rebind(TOPIC_NAME, new MockTopic(TOPIC_NAME));
         }
         finally
         {
@@ -326,6 +333,16 @@
         router.route(msg) ;
         assertEquals("Property setter value", PROPERTY_SETTER_TEST_NAME, router.getJmsMessage().getStringProperty(PROPERTY_SETTER_TEST_NAME)) ;
     }
+
+    @Test
+    public void testTopicDestination() throws ConfigurationException, NamingException, JMSException
+    {
+        final ConfigTree config = new ConfigTree("topic") ;
+        config.setAttribute("jndiName", TOPIC_NAME);
+        config.setAttribute(JMSEpr.CONNECTION_FACTORY_TAG, TOPIC_CONNECTION_FACTORY);
+        new JMSRouter(config) ;
+        assertEquals("Topic Connection creation count", 1, MockTopicConnectionFactory.topicConnectionCount) ;
+    }
     
     private void assertProcessContract( final String messageID, final org.jboss.soa.esb.message.Message msg, JMSRouter router ) throws ActionProcessingException, JMSException
     {
@@ -362,7 +379,20 @@
                     new MockQueueExceptionHandlerInvocationHandler(super.createQueueConnection())) ;
         }
     }
-    
+
+    private static final class MockTopicConnectionFactory extends TopicConnectionFactoryImpl
+    {
+        static int topicConnectionCount ;
+        
+        @Override
+        public TopicConnection createTopicConnection() throws JMSException
+        {
+            topicConnectionCount++ ;
+            return (TopicConnection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {TopicConnection.class},
+                    new MockTopicExceptionHandlerInvocationHandler(super.createTopicConnection())) ;
+        }
+    }
+
     private static final class MockQueueExceptionHandlerInvocationHandler implements InvocationHandler
     {
         private final QueueConnection queueConnection ;
@@ -413,6 +443,36 @@
         }
     }
     
+    private static final class MockTopicExceptionHandlerInvocationHandler implements InvocationHandler
+    {
+        private final TopicConnection topicConnection ;
+        private ExceptionListener exceptionListener ;
+            
+        MockTopicExceptionHandlerInvocationHandler(final TopicConnection topicConnection)
+        {
+            this.topicConnection = topicConnection ;
+        }
+            
+        public Object invoke(final Object proxy, final Method method, final Object[] args)
+            throws Throwable
+        {
+            final String methodName = method.getName() ;
+            if ("setExceptionListener".equals(methodName))
+            {
+                exceptionListener = (ExceptionListener)args[0] ;
+                return null ;
+            }
+            else if ("getExceptionListener".equals(methodName))
+            {
+                return exceptionListener ;
+            }
+            else
+            {
+                return method.invoke(topicConnection, args) ;
+            }
+        }
+    }
+    
     private static final class MockQueueSessionInvocationHandler implements InvocationHandler
     {
         private final MockQueueExceptionHandlerInvocationHandler exceptionHandler ;



More information about the jboss-svn-commits mailing list