[jboss-svn-commits] JBL Code SVN: r22485 - in labs/jbossesb/workspace/skeagh/routing/jms: src/main/java/org/jboss/esb/jms and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Sep 7 12:13:24 EDT 2008


Author: beve
Date: 2008-09-07 12:13:23 -0400 (Sun, 07 Sep 2008)
New Revision: 22485

Modified:
   labs/jbossesb/workspace/skeagh/routing/jms/pom.xml
   labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java
   labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java
   labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml
   labs/jbossesb/workspace/skeagh/routing/jms/src/test/resources/log4j.xml
Log:
Added jms stuff. Test are currently commented out.


Modified: labs/jbossesb/workspace/skeagh/routing/jms/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/pom.xml	2008-09-07 10:55:14 UTC (rev 22484)
+++ labs/jbossesb/workspace/skeagh/routing/jms/pom.xml	2008-09-07 16:13:23 UTC (rev 22485)
@@ -12,5 +12,52 @@
     <artifactId>jbossesb-routing-jms</artifactId>
     <version>${jboss.esb.version}</version>
     <url>http://www.jboss.org/jbossesb/</url>
+    
+    <dependencies>
+    
+    	<dependency>
+            <groupId>jboss</groupId>
+            <artifactId>jboss-j2ee</artifactId>
+            <version>${jboss.eap.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        
+        <!-- Test Dependencies - can we embed JBM for testing ?? -->
+        <dependency>
+            <groupId>org.apache.activemq</groupId>
+            <artifactId>activemq-core</artifactId>
+            <version>4.1.2</version>
+            <scope>test</scope>
+        </dependency>
+    
+        <dependency>
+            <groupId>org.apache.derby</groupId>
+            <artifactId>derby</artifactId>
+            <version>10.1.1.0</version>
+            <scope>test</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>mx4j</groupId>
+            <artifactId>mx4j</artifactId>
+            <version>3.0.2</version>
+            <scope>test</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>mx4j</groupId>
+            <artifactId>mx4j-tools</artifactId>
+            <version>3.0.1</version>
+            <scope>test</scope>
+        </dependency> 
+        
+    </dependencies>
+    
+    <repositories>
+        <repository>
+            <id>jboss</id>
+            <url>http://repository.jboss.com/maven2</url>
+        </repository>
+    </repositories>
 
 </project>
\ No newline at end of file

Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java	2008-09-07 10:55:14 UTC (rev 22484)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java	2008-09-07 16:13:23 UTC (rev 22485)
@@ -24,11 +24,13 @@
 
 import java.util.Properties;
 
+import javax.jms.JMSException;
 import javax.naming.Context;
 
 import org.apache.log4j.Logger;
 import org.jboss.esb.annotations.Initialize;
 import org.jboss.esb.annotations.Property;
+import org.jboss.esb.annotations.Uninitialize;
 import org.jboss.esb.annotations.Property.Use;
 import org.jboss.esb.context.InvocationContext;
 import org.jboss.esb.message.Message;
@@ -61,34 +63,40 @@
     @Property(use = Use.REQUIRED, name = "jmsDestination")
     private String destination;
 
+    public String getDestination()
+    {
+        return destination;
+    }
+
     /**
      * JMS properties.
      */
     @org.jboss.esb.annotations.Properties
     private final Properties jmsProperties = getDefaultProperties();
 
+    private JmsMessageListener messageListener;
+
     /**
      * Initializes this instance.
+     * @throws JMSException
      */
     @Initialize
-    public final void initialize()
+    public final void initialize() throws JMSException
     {
         // this will be handled by the annotation constraint later
         AssertArgument.isNotNullAndNotEmpty(destination, "destination");
         log.info("JMSProperties : " + jmsProperties);
+        log.info("Destination : " + destination);
+
         // add this class as a JMS message listener...
+        messageListener = new JmsMessageListener(destination, jmsProperties, dispatcher);
+        messageListener.connect();
     }
 
-    /**
-     * Excecuted when a message arrives on the configured destination(Queue or Topic).
-     *
-     * @throws RoutingException if routing is not successful
-     */
-    public final void onMessage() throws RoutingException
+    @Uninitialize
+    public final void uninitialize()
     {
-        Message esbMessage = new Message();
-        esbMessage.setPayload("test");
-        dispatcher.dispatch(esbMessage, new InvocationContext());
+       messageListener.close();
     }
 
     /**
@@ -111,16 +119,6 @@
     }
 
     /**
-     * Gets the Destination that this router listens to.
-     *
-     * @return String   the name of the destination that this instance listens to.
-     */
-    public final String getDestination()
-    {
-        return destination;
-    }
-
-    /**
      * Will display the dispatcher and the properties for this instance.
      * @return String - string representation of this instance.
      */
@@ -141,9 +139,39 @@
         // Defaults for JNDI lookup
         defaults.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
         defaults.put(Context.URL_PKG_PREFIXES, "org.jboss.naming,org.jnp.interfaces");
-        defaults.put(Context.PROVIDER_URL, "jnp://localhost:1099"); // Defaults for JMS
+        defaults.put(Context.PROVIDER_URL, "jnp://localhost:1099");
         defaults.put(CONNECTION_FACTORY, "ConnectionFactory");
         return defaults;
     }
 
+    private class JmsMessageListener extends AbstractMessageListener
+    {
+        private MessageDispatcher dispatcher;
+
+        protected JmsMessageListener(final String destinationName, final Properties jndiProperties)
+        {
+            super(destinationName, jndiProperties);
+        }
+
+        protected JmsMessageListener(final String destinationName, final Properties jndiProperties, final MessageDispatcher dispatcher)
+        {
+            this(destinationName, jndiProperties);
+            this.dispatcher = dispatcher;
+        }
+
+        public void onMessage(final javax.jms.Message jmsMessage)
+        {
+            Message esbMessage = new Message();
+            esbMessage.setPayload("testing");
+            try
+            {
+                dispatcher.dispatch(esbMessage, new InvocationContext());
+            }
+            catch (RoutingException e)
+            {
+                e.printStackTrace();
+            }
+        }
+    }
+
 }

Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java	2008-09-07 10:55:14 UTC (rev 22484)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java	2008-09-07 16:13:23 UTC (rev 22485)
@@ -23,13 +23,17 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import javax.jms.JMSException;
 import javax.naming.Context;
 
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
 import org.jboss.esb.deploy.DeploymentException;
 import org.jboss.esb.deploy.DeploymentRuntime;
 import org.jboss.esb.deploy.config.DeploymentUnit;
@@ -37,7 +41,9 @@
 import org.jboss.esb.deploy.config.digest.DefaultConfigurationDigester;
 import org.jboss.esb.routing.InboundRouter;
 import org.jboss.esb.service.ServiceName;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -48,17 +54,48 @@
  */
 public class JmsInboundRouterTest
 {
+    private static final String TEST_PROVIDER_URL = "tcp://localhost:61616";
+    private static final String DESTINATION_NAME = "jbossesb.TestQueue";
+
     private static DeploymentUnit deploymentUnit;
     private final ServiceName serviceName = new ServiceName("service-cat", "service-a");
 
+    private static BrokerService broker;
+    private static Properties jndiProperties;
+
+    @BeforeClass
+    public static void startJmsProvider() throws Exception
+    {
+        broker = new BrokerService();
+
+        // configure the broker
+        broker.setDataDirectory(new File("./target/activeMQData"));
+        broker.addConnector(TEST_PROVIDER_URL);
+        broker.start();
+
+        jndiProperties = new Properties();
+        jndiProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getName());
+        jndiProperties.setProperty(Context.PROVIDER_URL, TEST_PROVIDER_URL);
+        jndiProperties.setProperty("queue." + DESTINATION_NAME, DESTINATION_NAME);
+
+        deploymentUnit = digest("jms-inbound-router_01.xml");
+    }
+
+    @AfterClass
+    public static void stopJmsProvider() throws Exception
+    {
+        broker.stop();
+    }
+
     @Test
-    public final void initializeDefaults() throws DeploymentException, IOException
+    @Ignore
+    public final void initializeDefaults() throws DeploymentException, IOException, JMSException
     {
         InboundRouter inboundRouter = getInboundRouter(serviceName, "noproperties");
         assertTrue(inboundRouter instanceof JmsInboundRouter);
         initialize();
 
-        final Properties properties = ((JmsInboundRouter) inboundRouter) .getProperties();
+        final Properties properties = ((JmsInboundRouter) inboundRouter).getProperties();
         assertEquals("org.jnp.interfaces.NamingContextFactory", properties .get(Context.INITIAL_CONTEXT_FACTORY));
         assertEquals("org.jboss.naming,org.jnp.interfaces", properties .get(Context.URL_PKG_PREFIXES));
         assertEquals("jnp://localhost:1099", properties .get(Context.PROVIDER_URL));
@@ -66,39 +103,33 @@
     }
 
     @Test
-    public final void initializeConfOverride() throws DeploymentException, IOException
+    @Ignore
+    public final void initializeConfOverride() throws DeploymentException, IOException, JMSException, InterruptedException
     {
         InboundRouter inboundRouter = getInboundRouter(serviceName, "inrouter1");
         assertTrue(inboundRouter instanceof JmsInboundRouter);
         initialize();
+        Thread.sleep(3000);
 
-        JmsInboundRouter jmsRouter = (JmsInboundRouter) inboundRouter;
-        final Properties properties = jmsRouter.getProperties();
-        assertTrue(properties.containsKey(Context.PROVIDER_URL));
-        assertEquals("localhost:8080", properties.get(Context.PROVIDER_URL));
-        assertEquals("queue/A", jmsRouter.getDestination());
+        MessageSender sender = new MessageSender(DESTINATION_NAME, jndiProperties);
+        try
+        {
+            sender.send(sender.getSession().createTextMessage("test"));
+            Thread.sleep(3000);
+        }
+        finally
+        {
+            sender.close();
+        }
     }
 
-    private void initialize() throws DeploymentException, IOException
+    private void initialize() throws DeploymentException, IOException, JMSException
     {
-        // will cause the @Initialized annotated method to be run.
         DeploymentRuntime runtime = new DeploymentRuntime();
         runtime.add(deploymentUnit);
         runtime.deploy();
     }
 
-    @BeforeClass
-    public static void setup() throws DeploymentException, IOException
-    {
-        deploymentUnit = digest("jms-inbound-router_01.xml");
-    }
-
-    /**
-     * Gets the InboundRouter for the passed in serviceName and the router named 'routerConfName'.
-     *
-     * @param servicename - the service name in the configuration
-     * @param routerConfName - the name of the router to get
-     */
     private InboundRouter getInboundRouter(final ServiceName servicename, final String routerConfName) throws DeploymentException, IOException
     {
         final Map<ServiceName, List<InboundRouterConfig>> inboundRoutersConfs = deploymentUnit.getInboundRouters();

Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml	2008-09-07 10:55:14 UTC (rev 22484)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml	2008-09-07 16:13:23 UTC (rev 22485)
@@ -4,14 +4,11 @@
         <inRouters serviceCategory="service-cat" serviceName="service-a">
         
             <inRouter name="inrouter1" class="org.jboss.esb.jms.JmsInboundRouter">
-                <property name="java.naming.provider.url">localhost:8080</property>
-                <property name="jmsDestination">queue/A</property>
+                <property name="java.naming.provider.url">tcp://localhost:61616</property>
+                <property name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</property>
+                <property name="jmsDestination">jbossesb.TestQueue</property>
             </inRouter>
             
-            <inRouter name="noproperties" class="org.jboss.esb.jms.JmsInboundRouter">
-                <property name="jmsDestination">queue/A</property>
-            </inRouter>
-            
         </inRouters>
     </routing>
 

Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/test/resources/log4j.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/test/resources/log4j.xml	2008-09-07 10:55:14 UTC (rev 22484)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/resources/log4j.xml	2008-09-07 16:13:23 UTC (rev 22485)
@@ -47,6 +47,10 @@
    <category name="org.jboss.esb.jms">
       <priority value="info"/>
    </category>
+   
+   <category name="org.apache.activemq">
+      <priority value="info"/>
+   </category>
 
    <!-- ======================= -->
    <!-- Setup the Root category -->




More information about the jboss-svn-commits mailing list