Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2013-07-19 04:02:23 -0400
committerJan Bartel2013-07-19 04:02:23 -0400
commitecd687db6d99728392f71f02b489964bae8c4a92 (patch)
tree0cfe55f01460c6fbf3c081af3143a1f2d540dacc
parentd65b511447b5788de1e2d0de2592eea2ac75cb03 (diff)
downloadorg.eclipse.jetty.project-ecd687db6d99728392f71f02b489964bae8c4a92.tar.gz
org.eclipse.jetty.project-ecd687db6d99728392f71f02b489964bae8c4a92.tar.xz
org.eclipse.jetty.project-ecd687db6d99728392f71f02b489964bae8c4a92.zip
413034 Multiple webapps redeploy returns NamingException with AppDynamics javaagent
-rw-r--r--jetty-jndi/src/main/java/org/eclipse/jetty/jndi/ContextFactory.java55
-rw-r--r--jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java9
2 files changed, 50 insertions, 14 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 b3c69074f8..c56b694a5b 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
@@ -75,7 +75,14 @@ public class ContextFactory implements ObjectFactory
* Threadlocal for injecting a context to use
* instead of looking up the map.
*/
- private static final ThreadLocal __threadContext = new ThreadLocal();
+ private static final ThreadLocal<Context> __threadContext = new ThreadLocal<Context>();
+
+ /**
+ * Threadlocal for setting a classloader which must be used
+ * when finding the comp context.
+ */
+ private static final ThreadLocal<ClassLoader> __threadClassLoader = new ThreadLocal<ClassLoader>();
+
/**
@@ -107,10 +114,25 @@ public class ContextFactory implements ObjectFactory
return ctx;
}
+ //See if there is a classloader to use for finding the comp context
+ //Don't use its parent hierarchy if set.
+ ClassLoader loader = (ClassLoader)__threadClassLoader.get();
+ if (loader != null)
+ {
+ if (__log.isDebugEnabled() && loader != null) __log.debug("Using threadlocal classloader");
+ ctx = getContextForClassLoader(loader);
+ if (ctx == null)
+ {
+ ctx = newNamingContext(obj, loader, env, name, nameCtx);
+ __contextMap.put (loader, ctx);
+ if(__log.isDebugEnabled())__log.debug("Made context "+name.get(0)+" for classloader: "+loader);
+ }
+ return ctx;
+ }
- ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- ClassLoader loader = tccl;
//If the thread context classloader is set, then try its hierarchy to find a matching context
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ loader = tccl;
if (loader != null)
{
if (__log.isDebugEnabled() && loader != null) __log.debug("Trying thread context classloader");
@@ -194,25 +216,34 @@ public class ContextFactory implements ObjectFactory
/**
* Associate the given Context with the current thread.
- * resetComponentContext method should be called to reset the context.
+ * disassociate method should be called to reset the context.
* @param ctx the context to associate to the current thread.
* @return the previous context associated on the thread (can be null)
*/
- public static Context setComponentContext(final Context ctx)
+ public static Context associateContext(final Context ctx)
{
Context previous = (Context)__threadContext.get();
__threadContext.set(ctx);
return previous;
}
- /**
- * Set back the context with the given value.
- * Don't return the previous context, use setComponentContext() method for this.
- * @param ctx the context to associate to the current thread.
- */
- public static void resetComponentContext(final Context ctx)
+ public static void disassociateContext(final Context ctx)
{
- __threadContext.set(ctx);
+ __threadContext.remove();
+ }
+
+
+ public static ClassLoader associateClassLoader(final ClassLoader loader)
+ {
+ ClassLoader prev = (ClassLoader)__threadClassLoader.get();
+ __threadClassLoader.set(loader);
+ return prev;
+ }
+
+
+ public static void disassociateClassLoader ()
+ {
+ __threadClassLoader.remove();
}
public static void dump(Appendable out, String indent) throws IOException
diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java
index 660231d9f2..26227f1555 100644
--- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java
+++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/EnvConfiguration.java
@@ -31,6 +31,7 @@ import javax.naming.Name;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
+import org.eclipse.jetty.jndi.ContextFactory;
import org.eclipse.jetty.jndi.NamingContext;
import org.eclipse.jetty.jndi.NamingUtil;
import org.eclipse.jetty.jndi.local.localContextRoot;
@@ -147,6 +148,7 @@ public class EnvConfiguration extends AbstractConfiguration
//get rid of any bindings for comp/env for webapp
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
+ ContextFactory.associateClassLoader(context.getClassLoader());
try
{
Context ic = new InitialContext();
@@ -170,6 +172,7 @@ public class EnvConfiguration extends AbstractConfiguration
}
finally
{
+ ContextFactory.disassociateClassLoader();
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
@@ -251,6 +254,7 @@ public class EnvConfiguration extends AbstractConfiguration
{
ClassLoader old_loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(wac.getClassLoader());
+ ContextFactory.associateClassLoader(wac.getClassLoader());
try
{
Context context = new InitialContext();
@@ -259,8 +263,9 @@ public class EnvConfiguration extends AbstractConfiguration
}
finally
{
- Thread.currentThread().setContextClassLoader(old_loader);
- }
+ ContextFactory.disassociateClassLoader();
+ Thread.currentThread().setContextClassLoader(old_loader);
+ }
}
private static class Bound

Back to the top