[jboss-cvs] JBossAS SVN: r95168 - in projects/naming/trunk/jnpserver/src: test/java/org/jnp and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 20 08:41:00 EDT 2009
Author: wolfc
Date: 2009-10-20 08:40:59 -0400 (Tue, 20 Oct 2009)
New Revision: 95168
Added:
projects/naming/trunk/jnpserver/src/test/java/org/jnp/server/
projects/naming/trunk/jnpserver/src/test/java/org/jnp/server/test/
projects/naming/trunk/jnpserver/src/test/java/org/jnp/server/test/jbname37/
projects/naming/trunk/jnpserver/src/test/java/org/jnp/server/test/jbname37/OptionalJavaCompTestCase.java
Modified:
projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingBeanImpl.java
Log:
JBNAME-37: made setup of java:comp optional
Modified: projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingBeanImpl.java
===================================================================
--- projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingBeanImpl.java 2009-10-20 10:33:38 UTC (rev 95167)
+++ projects/naming/trunk/jnpserver/src/main/java/org/jnp/server/NamingBeanImpl.java 2009-10-20 12:40:59 UTC (rev 95168)
@@ -56,6 +56,9 @@
private EventMgr eventMgr;
/** The SecurityManager */
private SecurityManager securityMgr;
+
+ /** Whether or not to setup java:comp during startup */
+ private boolean installJavaComp = true;
// Static --------------------------------------------------------
public static void main(String[] args)
@@ -121,6 +124,16 @@
return new NamingServer(null, null, eventMgr, securityMgr);
}
+ public boolean getInstallJavaComp()
+ {
+ return installJavaComp;
+ }
+
+ public void setInstallJavaComp(boolean b)
+ {
+ this.installJavaComp = b;
+ }
+
/**
*
* @throws Exception
@@ -172,17 +185,20 @@
if( providerURL != null )
log.warn("Context.PROVIDER_URL in server jndi.properties, url="+providerURL);
- /* Bind an ObjectFactory to "java:comp" so that "java:comp/env" lookups
- produce a unique context for each thread contexxt ClassLoader that
- performs the lookup.
- */
- ClassLoader topLoader = Thread.currentThread().getContextClassLoader();
- ENCFactory.setTopClassLoader(topLoader);
- RefAddr refAddr = new StringRefAddr("nns", "ENC");
- Reference envRef = new Reference("javax.namingMain.Context", refAddr, ENCFactory.class.getName(), null);
- Context ctx = (Context)iniCtx.lookup("java:");
- ctx.rebind("comp", envRef);
- ctx.close();
+ if(installJavaComp)
+ {
+ /* Bind an ObjectFactory to "java:comp" so that "java:comp/env" lookups
+ produce a unique context for each thread contexxt ClassLoader that
+ performs the lookup.
+ */
+ ClassLoader topLoader = Thread.currentThread().getContextClassLoader();
+ ENCFactory.setTopClassLoader(topLoader);
+ RefAddr refAddr = new StringRefAddr("nns", "ENC");
+ Reference envRef = new Reference("javax.namingMain.Context", refAddr, ENCFactory.class.getName(), null);
+ Context ctx = (Context)iniCtx.lookup("java:");
+ ctx.rebind("comp", envRef);
+ ctx.close();
+ }
iniCtx.close();
}
Added: projects/naming/trunk/jnpserver/src/test/java/org/jnp/server/test/jbname37/OptionalJavaCompTestCase.java
===================================================================
--- projects/naming/trunk/jnpserver/src/test/java/org/jnp/server/test/jbname37/OptionalJavaCompTestCase.java (rev 0)
+++ projects/naming/trunk/jnpserver/src/test/java/org/jnp/server/test/jbname37/OptionalJavaCompTestCase.java 2009-10-20 12:40:59 UTC (rev 95168)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jnp.server.test.jbname37;
+
+import static org.junit.Assert.fail;
+
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+
+import org.jnp.server.NamingBeanImpl;
+import org.junit.After;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class OptionalJavaCompTestCase
+{
+ private NamingBeanImpl naming;
+
+ @After
+ public void after()
+ {
+ if(naming != null)
+ naming.stop();
+ naming = null;
+ }
+
+ @Test
+ public void testWithJavaComp() throws Exception
+ {
+ naming = new NamingBeanImpl();
+ naming.start();
+
+ InitialContext ctx = new InitialContext();
+ ctx.lookup("java:comp");
+ }
+
+ @Test
+ public void testWithoutJavaComp() throws Exception
+ {
+ naming = new NamingBeanImpl();
+ naming.setInstallJavaComp(false);
+ naming.start();
+
+ InitialContext ctx = new InitialContext();
+ try
+ {
+ ctx.lookup("java:comp");
+ fail("java:comp should not exist");
+ }
+ catch(NameNotFoundException e)
+ {
+ // good
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list