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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Sep 4 11:04:27 EDT 2008


Author: beve
Date: 2008-09-04 11:04:27 -0400 (Thu, 04 Sep 2008)
New Revision: 22403

Added:
   labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/
   labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsConstants.java
   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/
   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
Modified:
   labs/jbossesb/workspace/skeagh/routing/jms/pom.xml
Log:
Work in progress. 


Modified: labs/jbossesb/workspace/skeagh/routing/jms/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/pom.xml	2008-09-04 14:54:30 UTC (rev 22402)
+++ labs/jbossesb/workspace/skeagh/routing/jms/pom.xml	2008-09-04 15:04:27 UTC (rev 22403)
@@ -12,5 +12,20 @@
     <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>4.2.0.GA</version>
+        </dependency>
+    </dependencies>
+    
+    <repositories>
+        <repository>
+            <id>jboss</id>
+            <url>http://repository.jboss.com/maven2</url>
+        </repository>
+    </repositories>
 
 </project>
\ No newline at end of file

Added: labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsConstants.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsConstants.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsConstants.java	2008-09-04 15:04:27 UTC (rev 22403)
@@ -0,0 +1,52 @@
+/*
+ * Milyn - Copyright (C) 2006
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License (version 2.1) as published
+ * by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License for more details:
+ * http://www.gnu.org/licenses/lgpl.txt
+ */
+package org.jboss.esb.jms;
+
+/**
+ * Contants used for the JMS Routers.
+ *
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public final class JmsConstants
+{
+    /**
+     * Private constructor.
+     */
+    private JmsConstants()
+    {
+    }
+
+    /**
+     * ConnectionFactory property name used in configuration files.
+     */
+    public static final String CONNECTION_FACTORY = "org.jboss.esb.jms.connectionFactory";
+
+    /**
+     * DeliveryMode property name used in configuration files.
+     */
+    public static final String DELIVERY_MODE = "org.jboss.esb.jms.deliveryMode";
+
+    /**
+     * Priority property name used in configuration files.
+     */
+    public static final String PRIORITY = "org.jboss.esb.jms.priority";
+
+    /**
+     * Time-to-Live property name used in configuration files.
+     */
+    public static final String TIME_TO_LIVE = "org.jboss.esb.jms.timeToLive";
+
+}

Added: 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	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java	2008-09-04 15:04:27 UTC (rev 22403)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.jms;
+
+import static org.jboss.esb.jms.JmsConstants.CONNECTION_FACTORY;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+
+import org.apache.log4j.Logger;
+import org.jboss.esb.annotation.ConfigParam;
+import org.jboss.esb.annotation.ConfigParam.Use;
+import org.jboss.esb.annotations.Initialize;
+import org.jboss.esb.routing.InboundRouter;
+import org.jboss.esb.routing.MessageDispatcher;
+import org.jboss.esb.util.AssertArgument;
+
+/**
+ * Inbound router for JMS.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class JmsInboundRouter implements InboundRouter
+{
+    /**
+     * Logger.
+     */
+    private final Logger log = Logger.getLogger(JmsInboundRouter.class);
+
+    /**
+     * MessageDispatcher used to dipatch the message to the ESB.
+     */
+    private MessageDispatcher dispatcher;
+
+    /**
+     * JMS destination name.
+     */
+    @ConfigParam(use = Use.REQUIRED)
+    private String destination;
+
+    /**
+     * default jms properties.
+     */
+    private final Properties jmsProperties = getDefaultProperties();
+
+    /**
+     * Optional properties.
+     */
+    private Properties properties;
+
+    /**
+     * Initializes this instance.
+     */
+    @Initialize
+    public final void initialize()
+    {
+        // this will be handled by the annotation constraint later
+        AssertArgument.isNotNullAndNotEmpty(destination, "destination");
+
+        if (properties != null)
+        {
+            // add/overwrite properties from the configuration
+            jmsProperties.putAll(properties);
+        }
+        log.debug("JMSProperties : " + jmsProperties);
+
+        // add this class as a JMS message listener...
+    }
+
+    /**
+     * Gets the JMS properties.
+     *
+     * @return Properties - the properties used by this instance.
+     */
+    public final Properties getProperties()
+    {
+        return (Properties) jmsProperties.clone();
+    }
+
+    /**
+     * Set the dispatcher used by this instance.
+     * @param dispatcher - the dispatcher to use
+     */
+    public final void setDispatcher(final MessageDispatcher dispatcher)
+    {
+        this.dispatcher = dispatcher;
+    }
+
+    /**
+     * Will display the dispatcher and the properties for this instance.
+     * @return String - string representation of this instance.
+     */
+    @Override
+    public final String toString()
+    {
+        return "[dispatcher=" + dispatcher + ", properties=" + properties + "]";
+    }
+
+    /**
+     * Returns the default JMS properties.
+     *
+     * @return Properties - the default JMS properties
+     */
+    private static Properties getDefaultProperties()
+    {
+        final Properties defaults = new Properties();
+        // 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(CONNECTION_FACTORY, "ConnectionFactory");
+        return defaults;
+    }
+
+}

Added: 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	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java	2008-09-04 15:04:27 UTC (rev 22403)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.jms;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.naming.Context;
+
+import org.jboss.esb.deploy.DeploymentException;
+import org.jboss.esb.deploy.DeploymentRuntime;
+import org.jboss.esb.deploy.config.DeploymentUnit;
+import org.jboss.esb.deploy.config.InboundRouterConfig;
+import org.jboss.esb.deploy.config.digest.DefaultConfigurationDigester;
+import org.jboss.esb.routing.InboundRouter;
+import org.jboss.esb.service.ServiceName;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test for {@link JmsInboundRouter}.
+ *
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ *
+ */
+public class JmsInboundRouterTest
+{
+    private static DeploymentUnit deploymentUnit;
+    private final ServiceName serviceName = new ServiceName("service-cat", "service-a");
+
+    @Test
+    public final void initializeDefaults() throws DeploymentException, IOException
+    {
+        InboundRouter inboundRouter = getInboundRouter(serviceName, "noproperties");
+        assertTrue(inboundRouter instanceof JmsInboundRouter);
+        initialize();
+
+        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));
+        assertEquals("ConnectionFactory", properties .get(JmsConstants.CONNECTION_FACTORY));
+    }
+
+    @Test
+    public final void initializeConfOverride() throws DeploymentException, IOException
+    {
+        InboundRouter inboundRouter = getInboundRouter(serviceName, "inrouter1");
+        assertTrue(inboundRouter instanceof JmsInboundRouter);
+        initialize();
+
+        final Properties properties = ((JmsInboundRouter) inboundRouter) .getProperties();
+        assertTrue(properties.containsKey(Context.PROVIDER_URL));
+        assertEquals("localhost:8080", properties.get(Context.PROVIDER_URL));
+    }
+
+    private void initialize() throws DeploymentException, IOException
+    {
+        // 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();
+        final List<InboundRouterConfig> routerConfsForService = inboundRoutersConfs .get(servicename);
+        for (InboundRouterConfig inboundRouterConfig : routerConfsForService)
+        {
+            if (inboundRouterConfig.getName().equals(routerConfName))
+            {
+                return inboundRouterConfig.getRouter();
+            }
+        }
+        return null;
+    }
+
+    private static DeploymentUnit digest(final String config) throws IOException, DeploymentException
+    {
+        DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
+        return digester.digest(JmsInboundRouterTest.class .getResourceAsStream(config));
+    }
+}

Added: 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	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml	2008-09-04 15:04:27 UTC (rev 22403)
@@ -0,0 +1,18 @@
+<jbossesb xmlns="http://www.jboss.org/jbossesb/xsd/jbossesb-5.0.xsd">
+
+    <routing>
+        <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="destination">queue/A</property>
+            </inRouter>
+            
+            <inRouter name="noproperties" class="org.jboss.esb.jms.JmsInboundRouter">
+                <property name="destination">queue/A</property>
+            </inRouter>
+            
+        </inRouters>
+    </routing>
+
+</jbossesb>
\ No newline at end of file

Added: labs/jbossesb/workspace/skeagh/routing/jms/src/test/resources/log4j.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/test/resources/log4j.xml	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/resources/log4j.xml	2008-09-04 15:04:27 UTC (rev 22403)
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!--                                                                       -->
+<!--  Log4j Configuration                                                  -->
+<!--                                                                       -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml,v 1.26.2.5 2005/09/15 09:31:02 dimitris Exp $ -->
+
+<!--
+   | For more configuration infromation and examples see the Jakarta Log4j
+   | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+   <!-- ============================== -->
+   <!-- Append messages to the console -->
+   <!-- ============================== -->
+
+   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+      <param name="Target" value="System.out"/>
+
+      <layout class="org.apache.log4j.PatternLayout">
+         <!-- The default pattern: Date Priority [Category] Message\n -->
+         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%t][%c{1}] %m%n"/>
+      </layout>
+   </appender>
+
+   <!-- ================ -->
+   <!-- Limit categories -->
+
+   <category name="org.milyn">
+      <priority value="error"/>
+   </category>
+   
+   <category name="org.quartz">
+      <priority value="error"/>
+   </category>
+   
+   <category name="org.jboss">
+      <priority value="error"/>
+   </category>
+
+   <category name="org.jboss.esb.jms">
+      <priority value="info"/>
+   </category>
+
+   <!-- ======================= -->
+   <!-- Setup the Root category -->
+   <!-- ======================= -->
+
+   <root>
+      <appender-ref ref="CONSOLE"/>
+   </root>
+
+</log4j:configuration>
+




More information about the jboss-svn-commits mailing list