Author: rmannibucau Date: Thu Apr 4 08:14:29 2013 New Revision: 1464348 URL: http://svn.apache.org/r1464348 Log: TOMEE-886 binding in ear global ejb names to jndi
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1464348&r1=1464347&r2=1464348&view=diff ============================================================================== --- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original) +++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Thu Apr 4 08:14:29 2013 @@ -845,22 +845,7 @@ public class Assembler extends Assembler } // bind all global values on global context - for (final Map.Entry<String, Object> value : appContext.getBindings().entrySet()) { - final String path = value.getKey(); - // keep only global bindings - if (path.startsWith("module/") || path.startsWith("app/") || path.startsWith("comp/") || path.equalsIgnoreCase("global/dummy")) { - continue; - } - - // a bit weird but just to be consistent if user doesn't lookup directly the resource - final Context lastContext = Contexts.createSubcontexts(containerSystemContext, path); - try { - lastContext.rebind(path.substring(path.lastIndexOf("/") + 1, path.length()), value.getValue()); - } catch (NameAlreadyBoundException nabe) { - nabe.printStackTrace(); - } - containerSystemContext.rebind(path, value.getValue()); - } + bindGlobals(appContext.getBindings()); // deploy MBeans for (final String mbean : appInfo.mbeans) { @@ -897,6 +882,26 @@ public class Assembler extends Assembler } } + public void bindGlobals(final Map<String, Object> bindings) throws NamingException { + final Context containerSystemContext = containerSystem.getJNDIContext(); + for (final Entry<String, Object> value : bindings.entrySet()) { + final String path = value.getKey(); + // keep only global bindings + if (path.startsWith("module/") || path.startsWith("app/") || path.startsWith("comp/") || path.equalsIgnoreCase("global/dummy")) { + continue; + } + + // a bit weird but just to be consistent if user doesn't lookup directly the resource + final Context lastContext = Contexts.createSubcontexts(containerSystemContext, path); + try { + lastContext.rebind(path.substring(path.lastIndexOf("/") + 1, path.length()), value.getValue()); + } catch (final NameAlreadyBoundException nabe) { + nabe.printStackTrace(); + } + containerSystemContext.rebind(path, value.getValue()); + } + } + private void propagateApplicationExceptions(final AppInfo appInfo, final ClassLoader classLoader, final List<BeanContext> allDeployments) { for (final BeanContext context : allDeployments) { if (BeanContext.Comp.class.equals(context.getBeanClass())) { Modified: tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java?rev=1464348&r1=1464347&r2=1464348&view=diff ============================================================================== --- tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java (original) +++ tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java Thu Apr 4 08:14:29 2013 @@ -250,7 +250,7 @@ public class TomcatJndiBuilder { if (root != null) { try { root.bind("global", SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup("global")); - } catch (NamingException e) { + } catch (final NamingException e) { // bind only global bindings if (webContext != null && webContext.getBindings() != null) { for (Map.Entry<String, Object> entry : webContext.getBindings().entrySet()) { Modified: tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1464348&r1=1464347&r2=1464348&view=diff ============================================================================== --- tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java (original) +++ tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java Thu Apr 4 08:14:29 2013 @@ -48,7 +48,6 @@ import org.apache.catalina.ha.tcp.Simple import org.apache.catalina.loader.VirtualWebappLoader; import org.apache.catalina.loader.WebappClassLoader; import org.apache.catalina.loader.WebappLoader; -import org.apache.catalina.session.StandardManager; import org.apache.catalina.startup.Constants; import org.apache.catalina.startup.ContextConfig; import org.apache.catalina.startup.HostConfig; @@ -1153,11 +1152,6 @@ public class TomcatWebAppBuilder impleme } injections.addAll(new InjectionBuilder(classLoader).buildInjections(webAppInfo.jndiEnc)); - // jndi bindings - final Map<String, Object> bindings = new HashMap<String, Object>(); - bindings.putAll(appContext.getBindings()); - bindings.putAll(getJndiBuilder(classLoader, webAppInfo, injections).buildBindings(JndiEncBuilder.JndiScope.comp)); - // merge OpenEJB jndi into Tomcat jndi final TomcatJndiBuilder jndiBuilder = new TomcatJndiBuilder(standardContext, webAppInfo, injections); NamingUtil.setCurrentContext(standardContext); @@ -1189,7 +1183,7 @@ public class TomcatWebAppBuilder impleme webContext.setId(webAppInfo.moduleId); webContext.setContextRoot(webAppInfo.contextRoot); webContext.setHost(webAppInfo.host); - webContext.setBindings(bindings); + webContext.setBindings(new HashMap<String, Object>()); webContext.getInjections().addAll(injections); appContext.getWebContexts().add(webContext); cs.addWebContext(webContext); @@ -1198,8 +1192,13 @@ public class TomcatWebAppBuilder impleme final List<BeanContext> beanContexts = assembler.initEjbs(classLoader, contextInfo.appInfo, appContext, injections, new ArrayList<BeanContext>(), webAppInfo.moduleId); new CdiBuilder().build(contextInfo.appInfo, appContext, beanContexts, webContext); assembler.startEjbs(true, beanContexts); + assembler.bindGlobals(appContext.getBindings()); } + // jndi bindings + webContext.getBindings().putAll(appContext.getBindings()); + webContext.getBindings().putAll(getJndiBuilder(classLoader, webAppInfo, injections).buildBindings(JndiEncBuilder.JndiScope.comp)); + standardContext.setInstanceManager(new JavaeeInstanceManager(webContext, standardContext)); standardContext.getServletContext().setAttribute(InstanceManager.class.getName(), standardContext.getInstanceManager());