[jboss-svn-commits] JBL Code SVN: r26695 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/soa/esb/actions/routing and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri May 22 09:41:09 EDT 2009


Author: beve
Date: 2009-05-22 09:41:09 -0400 (Fri, 22 May 2009)
New Revision: 26695

Added:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/JndiUtil.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/util/JndiUtilUnitTest.java
Modified:
   labs/jbossesb/trunk/product/docs/ProgrammersGuide.odt
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java
   labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml
Log:
Work for https://jira.jboss.org/jira/browse/JBESB-2555  "JMSRouter should accept extended JNDI configuration parameters"


Modified: labs/jbossesb/trunk/product/docs/ProgrammersGuide.odt
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java	2009-05-22 13:36:21 UTC (rev 26694)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java	2009-05-22 13:41:09 UTC (rev 26695)
@@ -55,45 +55,77 @@
 import org.jboss.soa.esb.notification.jms.DefaultJMSPropertiesSetter;
 import org.jboss.soa.esb.notification.jms.JMSPropertiesSetter;
 import org.jboss.soa.esb.util.ClassUtil;
+import org.jboss.soa.esb.util.JndiUtil;
 import org.jboss.soa.esb.util.Util;
 
 /**
  * JMS Routing Action Processor.
  * <p/>
  * Sample Action Configuration:
- * <pre>
- * &lt;action class="org.jboss.soa.esb.actions.routing.JMSRouter"&gt;
- *     &lt;property name="jndiName" value="queue/A"/&gt;
- * &lt;/action&gt;
+ * <pre>{@code
+ * <action class="org.jboss.soa.esb.actions.routing.JMSRouter">
+ *     <property name="jndiName" value="queue/A"/>
+ * </action>
  *
  * Option properties:
- *     &lt;property name="unwrap" value="false"/&gt;
- *     &lt;property name="jndi-context-factory" value="org.jnp.interfaces.NamingContextFactory"/&gt;
- *     &lt;property name="jndi-URL" value="127.0.0.1:1099"/&gt;
- *     &lt;property name="jndi-pkg-prefix" value="org.jboss.naming:org.jnp.interfaces"/&gt;
- *     &lt;property name="connection-factory" value="ConnectionFactory"/&gt;
- *     &lt;property name="persistent" value="true"/&gt;
- *     &lt;property name="priority" value="javax.jms.Message.DEFAULT_PRIORITY"/&gt;
- *     &lt;property name="time-to-live" value="javax.jms.Message.DEFAULT_TIME_TO_LIVE"/&gt;
- *     &lt;property name="security-principal" value="username"/&gt;
- *     &lt;property name="security-credential" value="pasword"/&gt;
- *     &lt;property name="property-strategy" value="&lt;property setter class name&gt;" /&gt;
- *     &lt;property name="message-prop-<i>&gt;prop-name&lt;</i>="<i>&gt; value="prop-value&lt;</i>" /&gt;
- * </pre>
+ *     <property name="unwrap" value="false"/>
+ *     <property name="jndi-context-factory" value="org.jnp.interfaces.NamingContextFactory"/>
+ *     <property name="jndi-URL" value="127.0.0.1:1099"/>
+ *     <property name="jndi-pkg-prefix" value="org.jboss.naming:org.jnp.interfaces"/>
+ *     <property name="connection-factory" value="ConnectionFactory"/>
+ *     <property name="persistent" value="true"/>
+ *     <property name="priority" value="javax.jms.Message.DEFAULT_PRIORITY"/>
+ *     <property name="time-to-live" value="javax.jms.Message.DEFAULT_TIME_TO_LIVE"/>
+ *     <property name="security-principal" value="username"/>
+ *     <property name="security-credential" value="pasword"/>
+ *     <property name="property-strategy" value="&lt;property setter class name&gt;" />
+ *     <property name="message-prop-<i><prop-name></i>="<i>> value="prop-value"<</i>" />
+ *     <property name="jndi-prefixes" value="org.xyz."<</i>" />
+ * }</pre>
  * Description of configuration attribues:
  * <ul>
- * <li><i>unwrap</i>:true will extract the message payload from the Message object before sending. false (default) will send the serialized Message object.
- * <li><i>jndi-context-factory</i>: the JNDI context factory to use. Default is "org.jnp.interfaces.NamingContextFactory"
- * <li><i>jndi-URL</i>: the JNDI URL to use. Default is "127.0.0.1:1099"
- * <li><i>jndi-pkg-prefix</i>: the JNDI naming package prefixes to use. Default is "org.jboss.naming:org.jnp.interfaces".
- * <li><i>connection-factory</i>: the name of the ConnectionFactory to use. Default is "ConnectionFactory".
- * <li><i>persistent</i>: the JMS DeliveryMode. 'true' or 'false'. Default is "true".
- * <li><i>priority</i>: the JMS Priority to be used. Default is "javax.jms.Message.DEFAULT_PRIORITY"
- * <li><i>time-to-live</i>: the JMS Time-To-Live to be used. Default is "javax.jms.Message.DEFAULT_TIME_TO_LIVE"
- * <li><i>security-principal</i>: security principal use when creating the JMS connection.
- * <li><i>security-credential</i>: the security credentials to use when creating the JMS connection. 
- * <li><i>property-strategy</i>: the implementation of the JMSPropertiesSetter interface, if overriding the default. 
- * <li><i>message-prop</i>: properties to be set on the message are prefixed with "message-prop-".
+ * <li><i>unwrap</i>:
+ * 'true' will extract the message payload from the Message object before sending. false (default) will send the serialized Message object.</li>
+ * 
+ * <li><i>jndi-context-factory</i>: 
+ * The JNDI context factory to use. Default is "org.jnp.interfaces.NamingContextFactory"</li>
+ * 
+ * <li><i>jndi-URL</i>: 
+ * The JNDI URL to use. Default is "127.0.0.1:1099"</li>
+ * 
+ * <li><i>jndi-pkg-prefix</i>: 
+ * The JNDI naming package prefixes to use. Default is "org.jboss.naming:org.jnp.interfaces".</li>
+ * 
+ * <li><i>connection-factory</i>: 
+ * The name of the ConnectionFactory to use. Default is "ConnectionFactory".</li>
+ * 
+ * <li><i>persistent</i>: 
+ * The JMS DeliveryMode. 'true' or 'false'. Default is "true".</li>
+ * 
+ * <li><i>priority</i>: 
+ * The JMS Priority to be used. Default is "javax.jms.Message.DEFAULT_PRIORITY"</li>
+ * 
+ * <li><i>time-to-live</i>: 
+ * The JMS Time-To-Live to be used. Default is "javax.jms.Message.DEFAULT_TIME_TO_LIVE"</li>
+ * 
+ * <li><i>security-principal</i>: 
+ * Security principal use when creating the JMS connection.</li>
+ * 
+ * <li><i>security-credential</i>: 
+ * The security credentials to use when creating the JMS connection. </li>
+ * 
+ * <li><i>property-strategy</i>: 
+ * The implementation of the JMSPropertiesSetter interface, if overriding the default. </li>
+ * 
+ * <li><i>message-prop</i>: 
+ * Properties to be set on the message are prefixed with "message-prop-".</li>
+ * 
+ * <li><i>jndi-prefixes</i>: 
+ * A comma separated string of prefixes. Properties that have these prefixes will be added to the JNDI environment.</li>
+ * 
+ * <li><i>org.xyz.propertyName</i>: 
+ * A jndi environment property that will be added to the jndi environment if the prefix 'org.xyz' was specified in the jndi-prefixes list.</li>
+ * 
  * </ul>
  *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
@@ -177,6 +209,7 @@
      * The JMS reply to destination.
      */
     private String jmsReplyToName ;
+    private Properties environment;
 
     
     /**
@@ -232,7 +265,11 @@
         else if ( securityCredential != null && securityPrincipal == null ) 
             throw new ConfigurationException("'" + SECURITY_CREDITIAL + "' must be accompanied by a '" + SECURITY_PRINCIPAL + "'");
         
-        final Properties environment = getEnvironment() ;
+        // Extract and environment properties given as properties in the config.
+        environment = JndiUtil.parseEnvironmentProperties(propertiesTree);
+        environment.setProperty(Context.PROVIDER_URL, jndiUrl);
+        environment.setProperty(Context.INITIAL_CONTEXT_FACTORY, jndiContextFactory);
+        environment.setProperty(Context.URL_PKG_PREFIXES, jndiPkgPrefix);
         try {
             pool = ( securityPrincipal != null )  ? 
                     JmsConnectionPoolContainer.getPool(environment, connectionFactory, securityPrincipal, securityCredential) :
@@ -469,12 +506,8 @@
 		}
     }
     
-    private Properties getEnvironment()
+    Properties getEnvironment()
     {
-        final Properties environment = new Properties();
-        environment.setProperty(Context.PROVIDER_URL, jndiUrl);
-        environment.setProperty(Context.INITIAL_CONTEXT_FACTORY, jndiContextFactory);
-        environment.setProperty(Context.URL_PKG_PREFIXES, jndiPkgPrefix);
         return environment ;
     }
     

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/JndiUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/JndiUtil.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/JndiUtil.java	2009-05-22 13:41:09 UTC (rev 26695)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2009, 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.soa.esb.util;
+
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * Utilities class for managing JNDI related tasks.
+ * 
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ */
+public class JndiUtil
+{
+    private JndiUtil()
+    {
+    }
+    
+    public static Set<String> getJndiPrefixesSet(final String jndiPrefixesValue)
+    {
+        final Set<String> jndiPrefixesSet = new TreeSet<String>();
+        // Add default prefix.
+        jndiPrefixesSet.add("java.naming.") ;
+        
+        if (jndiPrefixesValue != null)
+        {
+            final String[] values = jndiPrefixesValue.split(",") ;
+            for (String value: values)
+            {
+                final String trim = value.trim() ;
+                if (trim.length() > 0)
+                {
+                    jndiPrefixesSet.add(trim) ;
+                }
+            }
+        }
+        return jndiPrefixesSet;
+    }
+    
+    /**
+     * Get the list of JNDI extension prefixes.
+     * 
+     * @param jndiPrefixesValue The JNDI prefix list or null if default.
+     * @return The list of JNDI extension prefixes.
+     */
+    public static String[] getJndiPrefixes(final String jndiPrefixesValue)
+    {
+        final Set<String> jndiPrefixesSet = getJndiPrefixesSet(jndiPrefixesValue);
+        return jndiPrefixesSet.toArray(new String[jndiPrefixesSet.size()]) ;
+    }
+    
+    /**
+     * Parses the passed-in {@link ConfigTree} and extracts all properties that 
+     * have been prefixed 
+     * 
+     * @param config
+     * @return
+     */
+    public static Properties parseEnvironmentProperties(final ConfigTree config)
+    {
+        final Properties env = new Properties();
+        
+        // Comma separated list of prefixes. Will always include at least 'java.naming.'
+        final String[] jndiPrefixes = getJndiPrefixes(getPropertyValue(config, JMSEpr.JNDI_PREFIXES));
+        
+        Set<String> attributeNames= config.getAttributeNames();
+        for (final String name : attributeNames) 
+        {
+            for(String jndiPrefix: jndiPrefixes) 
+            {
+                if (name.startsWith(jndiPrefix))
+                {
+                    env.setProperty(name, config.getAttribute(name));
+                    break;
+                }
+            }
+        }
+        
+        return env;
+    }
+    
+    public static String getPropertyValue(final ConfigTree config, final String propertyName)
+    {
+        return config.getAttribute(propertyName);
+    }
+    
+    
+}

Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java	2009-05-22 13:36:21 UTC (rev 26694)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java	2009-05-22 13:41:09 UTC (rev 26695)
@@ -30,10 +30,9 @@
 import java.io.Serializable;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.Properties;
 
-import javax.jms.Destination;
 import javax.jms.JMSException;
-import javax.jms.Queue;
 import javax.jms.TextMessage;
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -260,6 +259,28 @@
 		assertEquals("Property setter value", PROPERTY_SETTER_TEST_NAME, router.getJmsMessage().getStringProperty(PROPERTY_SETTER_TEST_NAME)) ;
 	}
 	
+	@Test
+    public void parseEnvironmentProperties() throws ConfigurationException, NamingException, JMSException
+    {
+        final String envPrefix = "test.prefix.";
+        final String propertyName = envPrefix + "test.propertyName";
+        final String propertyValue = "propertyValue";
+        final ConfigTree config = createConfigTree();
+        
+        // Add the jndi prefixes property.
+        config.setAttribute(JMSEpr.JNDI_PREFIXES, envPrefix);
+        
+        // Add the additional env property
+        config.setAttribute(propertyName, propertyValue);
+        
+        JMSRouter router = new JMSRouter(config);
+        Properties env = router.getEnvironment();
+        
+        assertEquals(4, env.size());
+        assertTrue(env.containsKey(propertyName));
+        assertEquals(propertyValue, env.get(propertyName));
+    }
+	
 	@Before
 	public void setup() throws URISyntaxException
 	{

Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/util/JndiUtilUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/util/JndiUtilUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/util/JndiUtilUnitTest.java	2009-05-22 13:41:09 UTC (rev 26695)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2009, 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.soa.esb.util;
+
+import static org.junit.Assert.*;
+
+import java.util.Properties;
+import java.util.Set;
+
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link JndiUtil}.
+ * 
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ */
+public class JndiUtilUnitTest
+{
+    @Test
+    public void getJndiPrefixesSet()
+    {
+        Set<String> set = JndiUtil.getJndiPrefixesSet("test.vendorName");
+        assertEquals(2, set.size());
+        assertTrue(set.contains("test.vendorName"));
+        assertTrue(set.contains("java.naming."));
+    }
+    
+    @Test
+    public void getPropertyValue()
+    {
+        final ConfigTree config = new ConfigTree("config") ;
+        config.setAttribute(JMSEpr.JNDI_PREFIXES, "test");
+        String value = JndiUtil.getPropertyValue(config, JMSEpr.JNDI_PREFIXES);
+        assertEquals("test", value);
+    }
+    
+    @Test
+    public void parseEnvironmentProperties()
+    {
+        final String envPrefix1 = "test.prefix.";
+        final String envPrefix2 = "test.prefix2.";
+        final String envPrefix = envPrefix1 + "," + envPrefix2;
+        final String propertyName = envPrefix1 + "vendor.propertyName";
+        final String propertyName2 = envPrefix2 + "propertyName2";
+        final String propertyName3 = "java.naming.object";
+        final String propertyValue = "propertyValue";
+        final String propertyValue2 = "propertyValue2";
+        final String propertyValue3 = "someValue";
+        
+        final ConfigTree config = new ConfigTree("config") ;
+        config.setAttribute(JMSEpr.JNDI_PREFIXES, envPrefix);
+        config.setAttribute(propertyName, propertyValue);
+        config.setAttribute(propertyName2, propertyValue2);
+        config.setAttribute("java.naming.object", "someValue");
+        
+        final Properties env = JndiUtil.parseEnvironmentProperties(config);
+        
+        assertEquals(3, env.size());
+        assertTrue(env.containsKey(propertyName));
+        assertTrue(env.containsKey(propertyName2));
+        assertTrue(env.containsKey(propertyName3));
+        assertEquals(propertyValue, env.get(propertyName));
+        assertEquals(propertyValue2, env.get(propertyName2));
+        assertEquals(propertyValue3, env.get(propertyName3));
+    }
+
+}

Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml	2009-05-22 13:36:21 UTC (rev 26694)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml	2009-05-22 13:41:09 UTC (rev 26695)
@@ -46,6 +46,14 @@
 						<property name="unwrap" value="true"/>
 						<property name="security-principal" value="guest"/>
 						<property name="security-credential" value="guest"/>
+
+						<!-- Example of adding Extension properties -->
+						<!-- comma separated list of prefixes -->
+						<property name="jndi-prefixes" value="org.xyz."/>
+						<property name="org.xyz.propertyName" value="propertyValue"/>
+
+						<!-- All properties with prefix 'java.naming' will be added -->
+						<property name="java.naming.someproperty" value="propertyValue"/>
 				   </action>                
                     
             </actions>




More information about the jboss-svn-commits mailing list