recreating tag for openejb-4.0.0-beta-2

git-svn-id: https://svn.apache.org/repos/asf/openejb/tags/openejb-4.0.0-beta-2@1231619 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java b/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
index c96ca86..8c119e0 100644
--- a/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
+++ b/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
@@ -31,6 +31,8 @@
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
 import java.io.File;
 import java.io.OutputStream;
 import java.net.Socket;
@@ -100,19 +102,13 @@
             do { // be sure we don't override something existing
                 file = new File(tmpDir + File.separator + i++ + File.separator + archive.getName());
             } while (file.exists());
-            if (!file.getParentFile().mkdirs()) {
+            if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
                 LOGGER.warning("can't create " + file.getParent());
             }
 
             archive.as(ZipExporter.class).exportTo(file, true);
 
-            Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
-            properties.setProperty(Context.PROVIDER_URL, "http://" + LOCALHOST + ":" + configuration.getHttpPort() + "/openejb/ejb");
-            InitialContext context = new InitialContext(properties);
-
-            Deployer deployer = (Deployer) context.lookup("openejb/DeployerBusinessRemote");
-            deployer.deploy(file.getAbsolutePath());
+            deployer().deploy(file.getAbsolutePath());
 
             moduleIds.put(archive.getName(), file);
 
@@ -139,7 +135,18 @@
         }
     }
 
-    protected String getArchiveNameWithoutExtension(final Archive<?> archive) {
+    protected Deployer deployer() throws NamingException {
+        Properties properties = new Properties();
+        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
+        properties.setProperty(Context.PROVIDER_URL, "http://" + LOCALHOST + ":" + configuration.getHttpPort() + "/openejb/ejb");
+        InitialContext context = new InitialContext(properties);
+
+        Deployer deployer = (Deployer) context.lookup("openejb/DeployerBusinessRemote");
+
+		return deployer;
+	}
+
+	protected String getArchiveNameWithoutExtension(final Archive<?> archive) {
         final String archiveName = archive.getName();
         final int extensionOffset = archiveName.lastIndexOf('.');
         if (extensionOffset >= 0) {
diff --git a/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java b/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
index 3171272..26cfea7 100644
--- a/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
+++ b/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
@@ -19,10 +19,14 @@
 import org.apache.openejb.arquillian.common.FileUtils;
 import org.apache.openejb.arquillian.common.MavenCache;
 import org.apache.openejb.arquillian.common.TomEEContainer;
+import org.apache.openejb.assembler.Deployer;
 import org.apache.openejb.config.RemoteServer;
 import org.apache.tomee.installer.Installer;
 import org.apache.tomee.installer.Paths;
+import org.jboss.arquillian.container.spi.client.container.DeploymentException;
 import org.jboss.arquillian.container.spi.client.container.LifecycleException;
+import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData;
+import org.jboss.shrinkwrap.api.Archive;
 import org.sonatype.aether.artifact.Artifact;
 
 import java.io.BufferedReader;
@@ -41,6 +45,8 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import javax.naming.NamingException;
+
 /*
  * TODO: delete old embedded adapter, move the tests and set those up
  */
@@ -50,6 +56,16 @@
     private RemoteServer container;
     private boolean needsStart = false;
 
+    public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
+    	ProtocolMetaData pmd = super.deploy(archive);
+    	try { // TODO: maybe querying tomee to know if a webapp is completely deployed (for tomcat)
+			Thread.sleep(100); // maybe tomcat is still not started
+		} catch (InterruptedException e) {
+			// no-op
+		}
+    	return pmd;
+    }
+
     public void start() throws LifecycleException {
         if (System.getProperty("tomee.http.port") != null) {
             configuration.setHttpPort(Integer.parseInt(System.getProperty("tomee.http.port")));
diff --git a/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java b/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
index e00c241..237444a 100644
--- a/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
+++ b/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
@@ -40,7 +40,7 @@
     @Deployment
     public static WebArchive createDeployment() {
         return ShrinkWrap.create(WebArchive.class, "test.war").addClass(TestServlet.class).addClass(TestEjb.class).addClass(TomEEContainerTest.class)
-                .setWebXML(new StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class, "/Test").exportAsString()));
+                .setWebXML(new StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class, "/ejb").exportAsString()));
     }
 
     @EJB
@@ -53,7 +53,7 @@
 
     @Test
     public void testShouldBeAbleToAccessServletAndEjb() throws Exception {
-        InputStream is = new URL("http://localhost:" + System.getProperty("tomee.http.port", "10080") + "/test/Test").openStream();
+        InputStream is = new URL("http://127.0.0.1:" + System.getProperty("tomee.http.port", "10080") + "/test/ejb").openStream();
         ByteArrayOutputStream os = new ByteArrayOutputStream();
 
         int bytesRead = -1;
diff --git a/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java b/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
index 7b35fff..1f5d353 100644
--- a/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
+++ b/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
@@ -38,7 +38,7 @@
  *
  */
 @RunWith(Arquillian.class)
-    public class GetResourcesTest {
+public class GetResourcesTest {
     public static final String TEST_NAME = GetResourcesTest.class.getSimpleName();
 
     @Deployment(testable = false) public static WebArchive createDeployment() {
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java b/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
index e5308c0..a6e90a9 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
@@ -63,6 +63,10 @@
         return localUrlCache.isUrlCached(appId, url);
     }
 
+    public static URL getUrlKeyCached(String appId, File file) {
+    	return localUrlCache.getUrlKeyCached(appId, file);
+    }
+
     public static URLClassLoader createClassLoader(String appId, URL[] urls, ClassLoader parent) {
         urls = localUrlCache.cacheUrls(appId, urls);
         URLClassLoader classLoader = new URLClassLoader(urls, parent);
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java b/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
index afcaae0..7c2a07f 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
@@ -150,6 +150,29 @@
         return appCache.containsKey(url);
     }
 
+    public URL getUrlKeyCached(String appId, File file) {
+    	if (file == null) {
+    		return null;
+    	}
+        final Map<URL, File> appCache = getAppCache(appId);
+        for (Map.Entry<URL, File> entry : appCache.entrySet()) {
+        	if (entry.getValue().equals(file)) {
+        		return entry.getKey();
+        	}
+        }
+
+        final URL keyUrl;
+		try {
+			keyUrl = file.toURI().toURL();
+		} catch (MalformedURLException e) {
+			return null;
+		}
+        if (appCache.containsKey(keyUrl)) {
+        	return keyUrl;
+        }
+        return null;
+    }
+
     private synchronized File cacheUrl(String appId, URL url) {
         File sourceFile;
         if (!"file".equals(url.getProtocol())) {
diff --git a/examples/applicationexception/README.md b/examples/applicationexception/README.md
index 7832a6a..dbc73d3 100644
--- a/examples/applicationexception/README.md
+++ b/examples/applicationexception/README.md
@@ -48,7 +48,7 @@
         @Before
         public void setUp() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
 
             initialContext = new InitialContext(properties);
         }
diff --git a/examples/ear-testing/README.md b/examples/ear-testing/README.md
index 9dd0412..3c5e277 100644
--- a/examples/ear-testing/README.md
+++ b/examples/ear-testing/README.md
@@ -139,7 +139,7 @@
 
         public void test() throws Exception {
             Properties p = new Properties();
-            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
 
             p.put("openejb.deployments.classpath.ear", "true");
 
diff --git a/examples/helloworld-weblogic/README.md b/examples/helloworld-weblogic/README.md
index fe45282..965e1ad 100644
--- a/examples/helloworld-weblogic/README.md
+++ b/examples/helloworld-weblogic/README.md
@@ -81,7 +81,7 @@
     
         public void test() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             InitialContext initialContext = new InitialContext(properties);
     
             HelloEjbLocalHome localHome = (HelloEjbLocalHome) initialContext.lookup("MyHello");
diff --git a/examples/interceptors/README.md b/examples/interceptors/README.md
index d5a38ec..7319896 100644
--- a/examples/interceptors/README.md
+++ b/examples/interceptors/README.md
@@ -481,7 +481,7 @@
         @Before
         public void setUp() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             properties.setProperty("openejb.deployments.classpath.include", ".*interceptors/target/classes.*");
     
             initCtx = new InitialContext(properties);
@@ -560,7 +560,7 @@
         @Before
         public void setUp() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             properties.setProperty("openejb.deployments.classpath.include", ".*interceptors/target/classes.*");
     
             initCtx = new InitialContext(properties);
@@ -605,7 +605,7 @@
         @Before
         public void setUp() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             properties.setProperty("openejb.deployments.classpath.include", ".*interceptors/target/classes.*");
     
             initCtx = new InitialContext(properties);
@@ -654,7 +654,7 @@
         @Before
         public void setUp() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             properties.setProperty("openejb.deployments.classpath.include", ".*interceptors/target/classes.*");
     
             initCtx = new InitialContext(properties);
diff --git a/examples/quartz-app/README.md b/examples/quartz-app/README.md
index ba6ae36..393a75f 100644
--- a/examples/quartz-app/README.md
+++ b/examples/quartz-app/README.md
@@ -154,7 +154,7 @@
 
             if (null == initialContext) {
                 Properties properties = new Properties();
-                properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+                properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
 
                 initialContext = new InitialContext(properties);
             }
diff --git a/examples/simple-cmp2/README.md b/examples/simple-cmp2/README.md
index 304a208..54fdbc8 100644
--- a/examples/simple-cmp2/README.md
+++ b/examples/simple-cmp2/README.md
@@ -164,7 +164,7 @@
     
         public void test() throws Exception {
             Properties p = new Properties();
-            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             p.put("movieDatabase", "new://Resource?type=DataSource");
             p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
             p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
diff --git a/examples/simple-stateless-with-descriptor/README.md b/examples/simple-stateless-with-descriptor/README.md
index ac1e646..afb119a 100644
--- a/examples/simple-stateless-with-descriptor/README.md
+++ b/examples/simple-stateless-with-descriptor/README.md
@@ -96,7 +96,7 @@
     
         protected void setUp() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
     
             initialContext = new InitialContext(properties);
         }
diff --git a/examples/simple-webservice/README.md b/examples/simple-webservice/README.md
index b0e0d6e..7c53b08 100644
--- a/examples/simple-webservice/README.md
+++ b/examples/simple-webservice/README.md
@@ -189,7 +189,7 @@
     
         protected void setUp() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             properties.setProperty("openejb.embedded.remotable", "true");
     
             initialContext = new InitialContext(properties);
diff --git a/examples/spring-integration/README.md b/examples/spring-integration/README.md
index 3b11b70..ce92ecc 100644
--- a/examples/spring-integration/README.md
+++ b/examples/spring-integration/README.md
@@ -319,7 +319,7 @@
     
       <!--
       Loads the EJBs from the classpath just as when embedding OpenEJB via
-      the org.apache.openejb.localclient.LocalInitialContextFactory.  All the discovered
+      the org.apache.openejb.core.LocalInitialContextFactory.  All the discovered
       EJBs are imported into this context and available for injection here.
       -->
       <bean name="classPathApplication" class="org.apache.openejb.spring.ClassPathApplication"/>
diff --git a/examples/spring-integration/src/main/resources/movies.xml b/examples/spring-integration/src/main/resources/movies.xml
index 3b78aef..4fad6f4 100644
--- a/examples/spring-integration/src/main/resources/movies.xml
+++ b/examples/spring-integration/src/main/resources/movies.xml
@@ -54,7 +54,7 @@
 
   <!--
   Loads the EJBs from the classpath just as when embedding OpenEJB via
-  the org.apache.openejb.localclient.LocalInitialContextFactory.  All the discovered
+  the org.apache.openejb.core.LocalInitialContextFactory.  All the discovered
   EJBs are imported into this context and available for injection here.
   -->
   <bean name="classPathApplication" class="org.apache.openejb.spring.ClassPathApplication"/>
diff --git a/examples/telephone-stateful/README.md b/examples/telephone-stateful/README.md
index 427e6f3..9710984 100644
--- a/examples/telephone-stateful/README.md
+++ b/examples/telephone-stateful/README.md
@@ -100,7 +100,7 @@
     
         protected void setUp() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             properties.setProperty("openejb.embedded.remotable", "true");
             // Uncomment these properties to change the defaults
             //properties.setProperty("ejbd.port", "4202");
@@ -120,7 +120,7 @@
         public void testTalkOverLocalNetwork() throws Exception {
     
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             InitialContext localContext = new InitialContext(properties);
     
             Telephone telephone = (Telephone) localContext.lookup("TelephoneBeanRemote");
diff --git a/examples/testing-security-2/README.md b/examples/testing-security-2/README.md
index 189ceb1..7596eaf 100644
--- a/examples/testing-security-2/README.md
+++ b/examples/testing-security-2/README.md
@@ -141,7 +141,7 @@
     
         public void testAsManager() throws Exception {
             Properties p = new Properties();
-            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             p.put(Context.SECURITY_PRINCIPAL, "jane");
             p.put(Context.SECURITY_CREDENTIALS, "waterfall");
     
@@ -167,7 +167,7 @@
     
         public void testAsEmployee() throws Exception {
             Properties p = new Properties();
-            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             p.put(Context.SECURITY_PRINCIPAL, "joe");
             p.put(Context.SECURITY_CREDENTIALS, "cool");
     
diff --git a/examples/webapps/moviefun/README.md b/examples/webapps/moviefun/README.md
index 78de723..aefe03e 100644
--- a/examples/webapps/moviefun/README.md
+++ b/examples/webapps/moviefun/README.md
@@ -872,7 +872,7 @@
     
         public void setUp() throws Exception {
             Properties p = new Properties();
-            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             p.put("movieDatabase", "new://Resource?type=DataSource");
             p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
             p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
diff --git a/examples/webapps/struts/README.md b/examples/webapps/struts/README.md
index eeb5435..866c745 100644
--- a/examples/webapps/struts/README.md
+++ b/examples/webapps/struts/README.md
@@ -57,7 +57,7 @@
                 UserService service = null;
                 Properties props = new Properties();
                 props.put(Context.INITIAL_CONTEXT_FACTORY,
-                        "org.apache.openejb.localclient.LocalInitialContextFactory");
+                        "org.apache.openejb.core.LocalInitialContextFactory");
                 Context ctx = new InitialContext(props);
                 service = (UserService) ctx.lookup("UserServiceImplLocal");
                 service.add(new User(id, firstName, lastName));
@@ -124,7 +124,7 @@
                 UserService service = null;
                 Properties props = new Properties();
                 props.put(Context.INITIAL_CONTEXT_FACTORY,
-                        "org.apache.openejb.localclient.LocalInitialContextFactory");
+                        "org.apache.openejb.core.LocalInitialContextFactory");
                 Context ctx = new InitialContext(props);
                 service = (UserService) ctx.lookup("UserServiceImplLocal");
                 this.user = service.find(id);
@@ -192,7 +192,7 @@
                 UserService service = null;
                 Properties props = new Properties();
                 props.put(Context.INITIAL_CONTEXT_FACTORY,
-                        "org.apache.openejb.localclient.LocalInitialContextFactory");
+                        "org.apache.openejb.core.LocalInitialContextFactory");
                 Context ctx = new InitialContext(props);
                 service = (UserService) ctx.lookup("UserServiceImplLocal");
                 this.users = service.findAll();
diff --git a/examples/webservice-attachments/README.md b/examples/webservice-attachments/README.md
index ce71de7..15dbac9 100644
--- a/examples/webservice-attachments/README.md
+++ b/examples/webservice-attachments/README.md
@@ -111,7 +111,7 @@
         protected void setUp() throws Exception {
     
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             properties.setProperty("openejb.embedded.remotable", "true");
     
             initialContext = new InitialContext(properties);
diff --git a/examples/webservice-inheritance/README.md b/examples/webservice-inheritance/README.md
index ee0942d..79a5c1a 100644
--- a/examples/webservice-inheritance/README.md
+++ b/examples/webservice-inheritance/README.md
@@ -244,7 +244,7 @@
         protected void setUp() throws Exception {
     
             Properties p = new Properties();
-            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             p.put("wakeBoardDatabase", "new://Resource?type=DataSource");
             p.put("wakeBoardDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
             p.put("wakeBoardDatabase.JdbcUrl", "jdbc:hsqldb:mem:wakeBoarddb");
diff --git a/examples/webservice-security/README.md b/examples/webservice-security/README.md
index b66e5e6..8df1ec0 100644
--- a/examples/webservice-security/README.md
+++ b/examples/webservice-security/README.md
@@ -114,7 +114,7 @@
     
         protected void setUp() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             properties.setProperty("openejb.embedded.remotable", "true");
     
             initialContext = new InitialContext(properties);
diff --git a/examples/webservice-ws-security/README.md b/examples/webservice-ws-security/README.md
index 18399b1..0ba7656 100644
--- a/examples/webservice-ws-security/README.md
+++ b/examples/webservice-ws-security/README.md
@@ -315,7 +315,7 @@
         //START SNIPPET: setup
         protected void setUp() throws Exception {
             Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             properties.setProperty("openejb.embedded.remotable", "true");
     
             new InitialContext(properties);
diff --git a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
index 4ad0c7e..b0e7619 100644
--- a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
+++ b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
@@ -82,7 +82,7 @@
                 try {
                     return new URI(httpRequest.getRequestURI()).getRawPath();
                 } catch (URISyntaxException e) {
-                    return "/";
+                    return httpRequest.getRequestURI();
                 }
             }
         }, httpResponse);
diff --git a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
index 361e836..45c02b5 100644
--- a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
+++ b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
@@ -219,14 +219,22 @@
     private void deploySingleton(String contextRoot, Object o, Application appInstance, ClassLoader classLoader) {
         final String nopath = getAddress(contextRoot, o.getClass()) + "/.*";
         final RsHttpListener listener = createHttpListener();
-        final String address = rsRegistry.createRsHttpListener(listener, classLoader, nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
+        final RsRegistry.AddressInfo address = rsRegistry.createRsHttpListener(contextRoot, listener, classLoader, nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
 
-        services.add(address);
-        listener.deploySingleton(getFullContext(address, contextRoot), o, appInstance);
+        services.add(address.complete);
+        listener.deploySingleton(getFullContext(address.base, contextRoot), o, appInstance);
 
         LOGGER.info("deployed REST singleton: " + o);
     }
 
+    private static String baseAddress(final String address, final String contextRoot) {
+        if (contextRoot == null || contextRoot.isEmpty()) {
+            return address;
+        }
+        int idx = address.indexOf(contextRoot);
+        return address.substring(0, idx) + contextRoot;
+    }
+
     private void deployPojo(String contextRoot, Class<?> loadedClazz, Application app, ClassLoader classLoader, Collection<Injection> injections, Context context) {
         if (loadedClazz.isInterface()) {
             return;
@@ -234,10 +242,10 @@
 
         final String nopath = getAddress(contextRoot, loadedClazz) + "/.*";
         final RsHttpListener listener = createHttpListener();
-        final String address = rsRegistry.createRsHttpListener(listener, classLoader, nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
+        final RsRegistry.AddressInfo address = rsRegistry.createRsHttpListener(contextRoot, listener, classLoader, nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
 
-        services.add(address);
-        listener.deployPojo(getFullContext(address, contextRoot), loadedClazz, app, injections, context);
+        services.add(address.complete);
+        listener.deployPojo(getFullContext(address.base, contextRoot), loadedClazz, app, injections, context);
 
         LOGGER.info("deployed POJO class: " + loadedClazz.getName());
     }
@@ -245,10 +253,10 @@
     private void deployEJB(String context, BeanContext beanContext) {
         final String nopath = getAddress(context, beanContext.getBeanClass()) + "/.*";
         final RsHttpListener listener = createHttpListener();
-        final String address = rsRegistry.createRsHttpListener(listener, beanContext.getClassLoader(), nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
+        final RsRegistry.AddressInfo address = rsRegistry.createRsHttpListener(context, listener, beanContext.getClassLoader(), nopath.substring(NOPATH_PREFIX.length() - 1), virtualHost);
 
-        services.add(address);
-        listener.deployEJB(getFullContext(address, context), beanContext);
+        services.add(address.complete);
+        listener.deployEJB(getFullContext(address.base, context), beanContext);
 
         LOGGER.info("REST EJB deployed: " + beanContext.getBeanClass().getName());
     }
@@ -264,6 +272,9 @@
         if (context == null) {
             return address;
         }
+        if (context.isEmpty() && address.contains("/")) {
+            return address.substring(0, address.lastIndexOf("/"));
+        }
 
         int idx = address.indexOf(context);
         String base = address.substring(0, idx);
diff --git a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistry.java b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistry.java
index f63c8e1..6c9f381 100644
--- a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistry.java
+++ b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistry.java
@@ -22,6 +22,16 @@
 import java.util.List;
 
 public interface RsRegistry {
-    String createRsHttpListener(HttpListener listener, ClassLoader classLoader, String path, String virtualHost);
+    AddressInfo createRsHttpListener(String root, HttpListener listener, ClassLoader classLoader, String path, String virtualHost);
     HttpListener removeListener(String context);
+
+    public static class AddressInfo {
+        public String base;
+        public String complete;
+
+        public AddressInfo(String base, String complete) {
+            this.base = base;
+            this.complete = complete;
+        }
+    }
 }
diff --git a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java
index dfceae6..64a9c5f 100644
--- a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java
+++ b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RsRegistryImpl.java
@@ -27,11 +27,11 @@
 public class RsRegistryImpl extends OpenEJBHttpRegistry implements RsRegistry {
     private Map<String, String> addresses = new HashMap<String, String>();
 
-    @Override public String createRsHttpListener(HttpListener listener, ClassLoader classLoader, String path, String virtualHost) {
+    @Override public AddressInfo createRsHttpListener(String root, HttpListener listener, ClassLoader classLoader, String path, String virtualHost) {
         String address = HttpUtil.selectSingleAddress(getResolvedAddresses(path));
         addWrappedHttpListener(listener, classLoader, path);
         addresses.put(address, path);
-        return address;
+        return new AddressInfo(address, address);
     }
 
     @Override public HttpListener removeListener(String context) {
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
index 86f5f81..c322f8a 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
@@ -21,21 +21,29 @@
 import org.apache.catalina.loader.WebappClassLoader;
 import org.apache.catalina.loader.WebappLoader;
 import org.apache.naming.resources.DirContextURLStreamHandler;
+import org.apache.openejb.ClassLoaderUtil;
 import org.apache.openejb.util.ArrayEnumeration;
+import org.apache.openejb.util.URLs;
 import org.apache.tomcat.util.ExceptionUtils;
 
+import java.io.File;
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 public class TomEEWebappLoader extends WebappLoader {
     private ClassLoader appClassLoader;
     private ClassLoader tomEEClassLoader;
+    private String appPath;
 
-    public TomEEWebappLoader(final ClassLoader classLoader) {
+    public TomEEWebappLoader(final String appId, final ClassLoader classLoader) {
+    	this.appPath = appId;
         appClassLoader = classLoader;
     }
 
@@ -46,7 +54,7 @@
     @Override protected void startInternal() throws LifecycleException {
         super.startInternal();
         final ClassLoader webappCl = super.getClassLoader();
-        tomEEClassLoader = new TomEEClassLoader(appClassLoader, webappCl);
+        tomEEClassLoader = new TomEEClassLoader(appPath, appClassLoader, webappCl);
         try {
              DirContextURLStreamHandler.bind(tomEEClassLoader, getContainer().getResources());
         } catch (Throwable t) {
@@ -58,11 +66,13 @@
     public static class TomEEClassLoader extends ClassLoader {
         private ClassLoader app;
         private ClassLoader webapp;
+        private String appPath;
 
-        public TomEEClassLoader(final ClassLoader appCl, final ClassLoader webappCl) {
+        public TomEEClassLoader(final String appId, final ClassLoader appCl, final ClassLoader webappCl) {
             super(webappCl); // in fact this classloader = webappclassloader since we add nothing to this
-            app = appCl; // only used to manage resources since webapp.getParent() should be app
-            webapp = webappCl;
+            this.appPath = appId;
+            this.app = appCl; // only used to manage resources since webapp.getParent() should be app
+            this.webapp = webappCl;
         }
 
         /**
@@ -73,27 +83,72 @@
          * @throws IOException
          */
         @Override public Enumeration<URL> getResources(final String name) throws IOException {
-            List<URL> urls = new ArrayList<URL>();
+            // DMB: On inspection I was seeing three copies of the same resource
+            // due to the app.getResources and webapp.getResources call.
+            // Switching from a list to a form of set trims the duplicates
+            final Map<String, URL> urls = new HashMap<String, URL>();
+
 
             if (webapp instanceof WebappClassLoader && ((WebappClassLoader) webapp).isStarted() || webapp.getParent() == null) { // we set a parent so if it is null webapp was detroyed
-                addIfNotExist(urls, app.getResources(name), true);
-                addIfNotExist(urls, webapp.getResources(name), false);
-                return new ArrayEnumeration(urls);
+                add(urls, app.getResources(name));
+                add(urls, webapp.getResources(name));
+                return new ArrayEnumeration(clear(urls.values()));
             }
             return app.getResources(name);
         }
 
-        private static void addIfNotExist(Collection<URL> urls, Enumeration<URL> enumUrls, boolean force) {
+        private List<URL> clear(Iterable<URL> urls) { // take care of antiJarLocking
+        	final List<URL> clean = new ArrayList<URL>();
+        	for (URL url : urls) {
+	            final String urlStr = url.toExternalForm();
+	            URL jarUrl = null;
+	            if (urlStr.contains("!")) {
+	            	try {
+						jarUrl = new URL(urlStr.substring(0, urlStr.lastIndexOf('!'))  + "!/");
+					} catch (MalformedURLException e) {
+						// ignored
+					}
+	            }
+	
+	            if (jarUrl != null) {
+	            	final URL cachedFile = ClassLoaderUtil.getUrlKeyCached(appPath, file(jarUrl));
+	            	if (cachedFile != null) {
+	                	URL resource = null;
+						try {
+							resource = new URL("jar:file:" + cachedFile.getFile() + urlStr.substring(urlStr.lastIndexOf('!')));
+						} catch (MalformedURLException e) {
+							// ignored
+						}
+	                	if (resource != null && !clean.contains(resource)) {
+							clean.add(resource);
+	                	}
+	            	} else {
+                        // DMB: Unsure if this is the correct hanlding of the else case,
+                        // but in OSX the getUrlKeyCached returns null so the url was
+                        // being ignored
+                        clean.add(url);
+                    }
+
+	            } else if (!clean.contains(url)) {
+	                clean.add(url);
+	            }
+        	}
+			return clean;
+		}
+
+		private void add(Map<String, URL> urls, Enumeration<URL> enumUrls) {
             try {
                 while (enumUrls.hasMoreElements()) {
-                    URL url = enumUrls.nextElement();
-                    if (force || !urls.contains(url)) {
-                        urls.add(url);
-                    }
+                    final URL url = enumUrls.nextElement();
+                    urls.put(url.toExternalForm(), url);
                 }
             } catch (IllegalStateException ese) {
                 // ignored: if jars are already closed...shutdown for instance
             }
         }
+
+		private static File file(URL jarUrl) {
+            return URLs.toFile(jarUrl);
+		}
     }
 }
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
index 7d9f1e6..b89e312 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
@@ -333,7 +333,7 @@
                 // but here we have all the classloading logic
                 standardContext.setParentClassLoader(classLoader);
                 standardContext.setDelegate(true);
-                standardContext.setLoader(new TomEEWebappLoader(classLoader));
+                standardContext.setLoader(new TomEEWebappLoader(appInfo.path, classLoader));
                 standardContext.getLoader().setDelegate(true);
 
                 String host = webApp.host;
diff --git a/tomee/tomee-webapp/src/main/webapp/ejbref.html b/tomee/tomee-webapp/src/main/webapp/ejbref.html
index 7965024..ae006d3 100644
--- a/tomee/tomee-webapp/src/main/webapp/ejbref.html
+++ b/tomee/tomee-webapp/src/main/webapp/ejbref.html
@@ -99,7 +99,7 @@
             &lt;/parameter&gt;
             &lt;parameter&gt;
                 &lt;name&gt;openejb.naming.factory.initial&lt;/name&gt;
-                &lt;value&gt;org.openejb.localclient.LocalInitialContextFactory&lt;/value&gt;
+                &lt;value&gt;org.openejb.core.LocalInitialContextFactory&lt;/value&gt;
             &lt;/parameter&gt;
             &lt;parameter&gt;
                 &lt;name&gt;openejb.ejb-link&lt;/name&gt;
diff --git a/tomee/tomee-webapp/src/main/webapp/testejb.jsp b/tomee/tomee-webapp/src/main/webapp/testejb.jsp
index cb9f0f6..7ce8bbc 100644
--- a/tomee/tomee-webapp/src/main/webapp/testejb.jsp
+++ b/tomee/tomee-webapp/src/main/webapp/testejb.jsp
@@ -132,7 +132,7 @@
             myLoader = this.getClass().getClassLoader();
             Properties p = new Properties();
 
-            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             p.put("openejb.loader", "embed");
 
             ctx = new InitialContext(p);
diff --git a/tomee/tomee-webapp/src/main/webapp/testint.jsp b/tomee/tomee-webapp/src/main/webapp/testint.jsp
index c03123c..69b79a9 100644
--- a/tomee/tomee-webapp/src/main/webapp/testint.jsp
+++ b/tomee/tomee-webapp/src/main/webapp/testint.jsp
@@ -129,7 +129,7 @@
         try {
             Properties p = new Properties();
 
-            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             p.put("openejb.loader", "embed");
 
             ctx = new InitialContext(p);
diff --git a/tomee/tomee-webapp/src/main/webapp/viewejb.jsp b/tomee/tomee-webapp/src/main/webapp/viewejb.jsp
index f8636f2..6aadf59 100644
--- a/tomee/tomee-webapp/src/main/webapp/viewejb.jsp
+++ b/tomee/tomee-webapp/src/main/webapp/viewejb.jsp
@@ -196,7 +196,7 @@
         if(contextID == null){
         Properties p = new Properties();
 
-        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
         p.put("openejb.loader", "embed");
 
         ctx = new InitialContext(p);
diff --git a/tomee/tomee-webapp/src/main/webapp/viewjndi.jsp b/tomee/tomee-webapp/src/main/webapp/viewjndi.jsp
index c845766..661789e 100644
--- a/tomee/tomee-webapp/src/main/webapp/viewjndi.jsp
+++ b/tomee/tomee-webapp/src/main/webapp/viewjndi.jsp
@@ -89,7 +89,7 @@
 
         if (ctxID == null) {
             Properties p = new Properties();
-            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.localclient.LocalInitialContextFactory");
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
             p.put("openejb.loader", "embed");
             try {
                 ctx = new InitialContext( p );
diff --git a/tomee/tomee-webservices/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java b/tomee/tomee-webservices/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java
index c23afea..fe87050 100644
--- a/tomee/tomee-webservices/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java
+++ b/tomee/tomee-webservices/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java
@@ -31,13 +31,14 @@
 import org.apache.openejb.server.httpd.util.HttpUtil;
 import org.apache.openejb.server.rest.RsRegistry;
 import org.apache.openejb.server.rest.RsServlet;
-import org.apache.tomee.loader.TomcatHelper;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
+import org.apache.tomee.loader.TomcatHelper;
 
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
@@ -64,7 +65,7 @@
     }
 
     @Override
-    public String createRsHttpListener(HttpListener listener, ClassLoader classLoader, String completePath, String virtualHost) {
+    public AddressInfo createRsHttpListener(String root, HttpListener listener, ClassLoader classLoader, String completePath, String virtualHost) {
         String path = completePath;
         if (path == null) {
             throw new NullPointerException("contextRoot is null");
@@ -73,12 +74,16 @@
             throw new NullPointerException("listener is null");
         }
 
-        // assure context root with a leading slash
+        String realRoot = root;
+        if (!root.startsWith("/")) {
+            realRoot = "/" + root;
+        }
         if (!path.startsWith("/")) {
             path = "/" + path;
         }
-        String webContext = path.substring(0, path.substring(1).indexOf("/") + 1);
-        path = path.substring(webContext.length(), path.length());
+        if (!"/".equals(realRoot)) {
+            path = path.substring(realRoot.length(), path.length());
+        }
 
         // find the existing host (we do not auto-create hosts)
         if (virtualHost == null) virtualHost = engine.getDefaultHost();
@@ -88,7 +93,10 @@
         }
 
         // get the webapp context
-        Context context = (Context) host.findChild(webContext);
+        Context context = (Context) host.findChild(realRoot);
+        if (context == null && "/".equals(realRoot)) { // ROOT
+            context = (Context) host.findChild("");
+        }
         context.addLifecycleListener(new LifecycleListener() {
             public void lifecycleEvent(LifecycleEvent event) {
                 Context context = (Context) event.getLifecycle();
@@ -116,24 +124,27 @@
         wrapper.addInitParameter(HttpListener.class.getName(), listenerId);
         context.getServletContext().setAttribute(listenerId, listener);
 
-        // register wsdl locations for service-ref resolution
+        path = address(connectors, host.getName(), realRoot);
+        final String key = address(connectors, host.getName(), completePath);
+        contexts.put(key, context);
+        listeners.put(key, listener);
+
+        return new AddressInfo(path, key);
+    }
+
+    private static String address(final Collection<Connector> connectors, final String host, final String path) {
         List<String> addresses = new ArrayList<String>();
         for (Connector connector : connectors) {
             URI address;
             try {
-                address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), completePath, null, null);
+                address = new URI(connector.getScheme(), null, host, connector.getPort(), path, null, null);
             } catch (Exception e) { // just an URI problem normally...shouldn't occur
                 LOGGER.error("can't add container for path " + path, e);
                 continue;
             }
             addresses.add(address.toString());
         }
-
-        path = HttpUtil.selectSingleAddress(addresses);
-        contexts.put(path, context);
-        listeners.put(path, listener);
-
-        return path;
+        return HttpUtil.selectSingleAddress(addresses);
     }
 
     @Override