diff options
Diffstat (limited to 'jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java')
-rw-r--r-- | jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java | 69 |
1 files changed, 18 insertions, 51 deletions
diff --git a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java index 68452d755a..5b54fa1f76 100644 --- a/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java +++ b/jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java @@ -97,25 +97,15 @@ public class ContextFactory implements ObjectFactory return ctx; } - // Next, see if we are in a webapp context, if we are, use - // the classloader of the webapp to find the right jndi comp context ClassLoader loader = null; - if (ContextHandler.getCurrentContext() != null) - { - loader = ContextHandler.getCurrentContext().getContextHandler().getClassLoader(); - } + loader = Thread.currentThread().getContextClassLoader(); + if (__log.isDebugEnabled() && loader != null) __log.debug("Using thread context classloader"); - if (loader != null) + if (loader == null && ContextHandler.getCurrentContext() != null) { - if (__log.isDebugEnabled()) __log.debug("Using classloader of current org.eclipse.jetty.server.handler.ContextHandler"); - } - else - { - //Not already in a webapp context, in that case, we try the - //curren't thread's classloader instead - loader = Thread.currentThread().getContextClassLoader(); - if (__log.isDebugEnabled()) __log.debug("Using thread context classloader"); + loader = ContextHandler.getCurrentContext().getContextHandler().getClassLoader(); + if (__log.isDebugEnabled() && loader != null) __log.debug("Using classloader of current org.eclipse.jetty.server.handler.ContextHandler"); } //Get the context matching the classloader @@ -124,47 +114,24 @@ public class ContextFactory implements ObjectFactory //The map does not contain an entry for this classloader if (ctx == null) { - //Check if a parent classloader has created the context - ctx = getParentClassLoaderContext(loader); - - //Didn't find a context to match any of the ancestors - //of the classloader, so make a context - if (ctx == null) - { - Reference ref = (Reference)obj; - StringRefAddr parserAddr = (StringRefAddr)ref.get("parser"); - String parserClassName = (parserAddr==null?null:(String)parserAddr.getContent()); - NameParser parser = (NameParser)(parserClassName==null?null:loader.loadClass(parserClassName).newInstance()); - - ctx = new NamingContext (env, - name.get(0), - (NamingContext)nameCtx, - parser); - if(__log.isDebugEnabled())__log.debug("No entry for classloader: "+loader); - __contextMap.put (loader, ctx); - } + //Didn't find a context to match, make one + Reference ref = (Reference)obj; + StringRefAddr parserAddr = (StringRefAddr)ref.get("parser"); + String parserClassName = (parserAddr==null?null:(String)parserAddr.getContent()); + NameParser parser = (NameParser)(parserClassName==null?null:loader.loadClass(parserClassName).newInstance()); + + ctx = new NamingContext (env, + name.get(0), + (NamingContext)nameCtx, + parser); + if(__log.isDebugEnabled())__log.debug("Made context "+name.get(0)+" for classloader: "+loader); + __contextMap.put (loader, ctx); } return ctx; } - /** - * Keep trying ancestors of the given classloader to find one to which - * the context is bound. - * @param loader - * @return the context from the parent class loader - */ - public Context getParentClassLoaderContext (ClassLoader loader) - { - Context ctx = null; - ClassLoader cl = loader; - for (cl = cl.getParent(); (cl != null) && (ctx == null); cl = cl.getParent()) - { - ctx = (Context)__contextMap.get(cl); - } - - return ctx; - } + /** |