improved debugging of JNDI. own logger
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2608 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
f5cb715b78
commit
2b43ae931c
|
@ -14,7 +14,9 @@
|
|||
package org.eclipse.jetty.jndi;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import javax.naming.Context;
|
||||
|
@ -25,7 +27,8 @@ import javax.naming.StringRefAddr;
|
|||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
|
||||
|
@ -55,25 +58,20 @@ import org.eclipse.jetty.util.log.Log;
|
|||
*/
|
||||
public class ContextFactory implements ObjectFactory
|
||||
{
|
||||
private static Logger __log = NamingUtil.__log;
|
||||
|
||||
/**
|
||||
* Map of classloaders to contexts.
|
||||
*/
|
||||
private static WeakHashMap _contextMap;
|
||||
private static final WeakHashMap __contextMap = new WeakHashMap();
|
||||
|
||||
/**
|
||||
* Threadlocal for injecting a context to use
|
||||
* instead of looking up the map.
|
||||
*/
|
||||
private static ThreadLocal _threadContext;
|
||||
private static final ThreadLocal __threadContext = new ThreadLocal();
|
||||
|
||||
static
|
||||
{
|
||||
_contextMap = new WeakHashMap();
|
||||
_threadContext = new ThreadLocal();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Find or create a context which pertains to a classloader.
|
||||
*
|
||||
|
@ -89,10 +87,10 @@ public class ContextFactory implements ObjectFactory
|
|||
throws Exception
|
||||
{
|
||||
//First, see if we have had a context injected into us to use.
|
||||
Context ctx = (Context)_threadContext.get();
|
||||
Context ctx = (Context)__threadContext.get();
|
||||
if (ctx != null)
|
||||
{
|
||||
if(Log.isDebugEnabled()) Log.debug("Using the Context that is bound on the thread");
|
||||
if(__log.isDebugEnabled()) __log.debug("Using the Context that is bound on the thread");
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
@ -107,18 +105,18 @@ public class ContextFactory implements ObjectFactory
|
|||
|
||||
if (loader != null)
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("Using classloader of current org.eclipse.jetty.server.handler.ContextHandler");
|
||||
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");
|
||||
if (__log.isDebugEnabled()) __log.debug("Using thread context classloader");
|
||||
}
|
||||
|
||||
//Get the context matching the classloader
|
||||
ctx = (Context)_contextMap.get(loader);
|
||||
ctx = (Context)__contextMap.get(loader);
|
||||
|
||||
//The map does not contain an entry for this classloader
|
||||
if (ctx == null)
|
||||
|
@ -139,8 +137,8 @@ public class ContextFactory implements ObjectFactory
|
|||
name.get(0),
|
||||
nameCtx,
|
||||
parser);
|
||||
if(Log.isDebugEnabled())Log.debug("No entry for classloader: "+loader);
|
||||
_contextMap.put (loader, ctx);
|
||||
if(__log.isDebugEnabled())__log.debug("No entry for classloader: "+loader);
|
||||
__contextMap.put (loader, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,7 +157,7 @@ public class ContextFactory implements ObjectFactory
|
|||
ClassLoader cl = loader;
|
||||
for (cl = cl.getParent(); (cl != null) && (ctx == null); cl = cl.getParent())
|
||||
{
|
||||
ctx = (Context)_contextMap.get(cl);
|
||||
ctx = (Context)__contextMap.get(cl);
|
||||
}
|
||||
|
||||
return ctx;
|
||||
|
@ -174,8 +172,8 @@ public class ContextFactory implements ObjectFactory
|
|||
*/
|
||||
public static Context setComponentContext(final Context ctx)
|
||||
{
|
||||
Context previous = (Context)_threadContext.get();
|
||||
_threadContext.set(ctx);
|
||||
Context previous = (Context)__threadContext.get();
|
||||
__threadContext.set(ctx);
|
||||
return previous;
|
||||
}
|
||||
|
||||
|
@ -186,7 +184,23 @@ public class ContextFactory implements ObjectFactory
|
|||
*/
|
||||
public static void resetComponentContext(final Context ctx)
|
||||
{
|
||||
_threadContext.set(ctx);
|
||||
__threadContext.set(ctx);
|
||||
}
|
||||
|
||||
public static void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
out.append("o.e.j.jndi.ContextFactory@").append(Long.toHexString(__contextMap.hashCode())).append("\n");
|
||||
int size=__contextMap.size();
|
||||
int i=0;
|
||||
for (Map.Entry<ClassLoader,NamingContext> entry : ((Map<ClassLoader,NamingContext>)__contextMap).entrySet())
|
||||
{
|
||||
boolean last=++i==size;
|
||||
ClassLoader loader=entry.getKey();
|
||||
out.append(indent).append(" +- ").append(loader.getClass().getSimpleName()).append("@").append(Long.toHexString(loader.hashCode())).append(": ");
|
||||
|
||||
NamingContext context = entry.getValue();
|
||||
context.dump(out,indent+(last?" ":" | "));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import javax.naming.NameParser;
|
|||
import javax.naming.NamingException;
|
||||
|
||||
import org.eclipse.jetty.jndi.local.localContextRoot;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
/*------------------------------------------------*/
|
||||
|
@ -39,6 +39,8 @@ import org.eclipse.jetty.util.log.Log;
|
|||
*/
|
||||
public class InitialContextFactory implements javax.naming.spi.InitialContextFactory
|
||||
{
|
||||
private static Logger __log = NamingUtil.__log;
|
||||
|
||||
public static class DefaultParser implements NameParser
|
||||
{
|
||||
static Properties syntax = new Properties();
|
||||
|
@ -69,10 +71,10 @@ public class InitialContextFactory implements javax.naming.spi.InitialContextFac
|
|||
*/
|
||||
public Context getInitialContext(Hashtable env)
|
||||
{
|
||||
Log.debug("InitialContextFactory.getInitialContext()");
|
||||
__log.debug("InitialContextFactory.getInitialContext()");
|
||||
|
||||
Context ctx = new localContextRoot(env);
|
||||
if(Log.isDebugEnabled())Log.debug("Created initial context delegate for local namespace:"+ctx);
|
||||
if(__log.isDebugEnabled())__log.debug("Created initial context delegate for local namespace:"+ctx);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,10 @@
|
|||
package org.eclipse.jetty.jndi;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.naming.Binding;
|
||||
|
@ -36,7 +38,7 @@ import javax.naming.Reference;
|
|||
import javax.naming.Referenceable;
|
||||
import javax.naming.spi.NamingManager;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
/*------------------------------------------------*/
|
||||
|
@ -59,7 +61,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
*/
|
||||
public class NamingContext implements Context, Cloneable
|
||||
{
|
||||
|
||||
private final static Logger __log=NamingUtil.__log;
|
||||
public static final String LOCK_PROPERTY = "org.eclipse.jndi.lock";
|
||||
public static final String UNLOCK_PROPERTY = "org.eclipse.jndi.unlock";
|
||||
|
||||
|
@ -350,7 +352,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
else
|
||||
{
|
||||
if(Log.isDebugEnabled())Log.debug("Checking for existing binding for name="+cname+" for first element of name="+cname.get(0));
|
||||
if(__log.isDebugEnabled())__log.debug("Checking for existing binding for name="+cname+" for first element of name="+cname.get(0));
|
||||
|
||||
//walk down the subcontext hierarchy
|
||||
//need to ignore trailing empty "" name components
|
||||
|
@ -383,7 +385,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("",e);
|
||||
__log.warn("",e);
|
||||
throw new NamingException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -475,7 +477,7 @@ public class NamingContext implements Context, Cloneable
|
|||
if (ctx instanceof Reference)
|
||||
{
|
||||
//deference the object
|
||||
if(Log.isDebugEnabled())Log.debug("Object bound at "+firstComponent +" is a Reference");
|
||||
if(__log.isDebugEnabled())__log.debug("Object bound at "+firstComponent +" is a Reference");
|
||||
try
|
||||
{
|
||||
ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
|
||||
|
@ -486,7 +488,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("",e);
|
||||
__log.warn("",e);
|
||||
throw new NamingException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -555,12 +557,12 @@ public class NamingContext implements Context, Cloneable
|
|||
public Object lookup(Name name)
|
||||
throws NamingException
|
||||
{
|
||||
if(Log.isDebugEnabled())Log.debug("Looking up name=\""+name+"\"");
|
||||
if(__log.isDebugEnabled())__log.debug("Looking up name=\""+name+"\"");
|
||||
Name cname = toCanonicalName(name);
|
||||
|
||||
if ((cname == null) || (cname.size() == 0))
|
||||
{
|
||||
Log.debug("Null or empty name, returning copy of this context");
|
||||
__log.debug("Null or empty name, returning copy of this context");
|
||||
NamingContext ctx = new NamingContext (_env, _name, _parent, _parser);
|
||||
ctx._bindings = _bindings;
|
||||
return ctx;
|
||||
|
@ -608,7 +610,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("",e);
|
||||
__log.warn("",e);
|
||||
throw new NamingException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -652,7 +654,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("",e);
|
||||
__log.warn("",e);
|
||||
throw new NamingException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -724,7 +726,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("",e);
|
||||
__log.warn("",e);
|
||||
throw new NamingException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -764,7 +766,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("",e);
|
||||
__log.warn("",e);
|
||||
throw new NamingException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -803,7 +805,7 @@ public class NamingContext implements Context, Cloneable
|
|||
public NamingEnumeration list(Name name)
|
||||
throws NamingException
|
||||
{
|
||||
if(Log.isDebugEnabled())Log.debug("list() on Context="+getName()+" for name="+name);
|
||||
if(__log.isDebugEnabled())__log.debug("list() on Context="+getName()+" for name="+name);
|
||||
Name cname = toCanonicalName(name);
|
||||
|
||||
|
||||
|
@ -838,7 +840,7 @@ public class NamingContext implements Context, Cloneable
|
|||
if (ctx instanceof Reference)
|
||||
{
|
||||
//deference the object
|
||||
if(Log.isDebugEnabled())Log.debug("Dereferencing Reference for "+name.get(0));
|
||||
if(__log.isDebugEnabled())__log.debug("Dereferencing Reference for "+name.get(0));
|
||||
try
|
||||
{
|
||||
ctx = NamingManager.getObjectInstance(ctx, getNameParser("").parse(firstComponent), this, _env);
|
||||
|
@ -849,7 +851,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("",e);
|
||||
__log.warn("",e);
|
||||
throw new NamingException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -933,7 +935,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("",e);
|
||||
__log.warn("",e);
|
||||
throw new NamingException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1000,7 +1002,7 @@ public class NamingContext implements Context, Cloneable
|
|||
else
|
||||
{
|
||||
//walk down the subcontext hierarchy
|
||||
if(Log.isDebugEnabled())Log.debug("Checking for existing binding for name="+cname+" for first element of name="+cname.get(0));
|
||||
if(__log.isDebugEnabled())__log.debug("Checking for existing binding for name="+cname+" for first element of name="+cname.get(0));
|
||||
|
||||
String firstComponent = cname.get(0);
|
||||
Object ctx = null;
|
||||
|
@ -1030,7 +1032,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("",e);
|
||||
__log.warn("",e);
|
||||
throw new NamingException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1108,7 +1110,7 @@ public class NamingContext implements Context, Cloneable
|
|||
else
|
||||
{
|
||||
//walk down the subcontext hierarchy
|
||||
if(Log.isDebugEnabled())Log.debug("Checking for existing binding for name="+cname+" for first element of name="+cname.get(0));
|
||||
if(__log.isDebugEnabled())__log.debug("Checking for existing binding for name="+cname+" for first element of name="+cname.get(0));
|
||||
|
||||
String firstComponent = cname.get(0);
|
||||
Object ctx = null;
|
||||
|
@ -1138,7 +1140,7 @@ public class NamingContext implements Context, Cloneable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn("",e);
|
||||
__log.warn("",e);
|
||||
throw new NamingException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1362,7 +1364,7 @@ public class NamingContext implements Context, Cloneable
|
|||
protected void addBinding (Name name, Object obj)
|
||||
{
|
||||
String key = name.toString();
|
||||
if(Log.isDebugEnabled())Log.debug("Adding binding with key="+key+" obj="+obj+" for context="+_name);
|
||||
if(__log.isDebugEnabled())__log.debug("Adding binding with key="+key+" obj="+obj+" for context="+_name);
|
||||
_bindings.put (key, new Binding (key, obj));
|
||||
}
|
||||
|
||||
|
@ -1375,7 +1377,7 @@ public class NamingContext implements Context, Cloneable
|
|||
*/
|
||||
protected Binding getBinding (Name name)
|
||||
{
|
||||
if(Log.isDebugEnabled())Log.debug("Looking up binding for "+name.toString()+" for context="+_name);
|
||||
if(__log.isDebugEnabled())__log.debug("Looking up binding for "+name.toString()+" for context="+_name);
|
||||
return (Binding) _bindings.get(name.toString());
|
||||
}
|
||||
|
||||
|
@ -1389,7 +1391,7 @@ public class NamingContext implements Context, Cloneable
|
|||
*/
|
||||
protected Binding getBinding (String name)
|
||||
{
|
||||
if(Log.isDebugEnabled())Log.debug("Looking up binding for "+name+" for context="+_name);
|
||||
if(__log.isDebugEnabled())__log.debug("Looking up binding for "+name+" for context="+_name);
|
||||
return (Binding) _bindings.get(name);
|
||||
}
|
||||
|
||||
|
@ -1397,7 +1399,7 @@ public class NamingContext implements Context, Cloneable
|
|||
protected void removeBinding (Name name)
|
||||
{
|
||||
String key = name.toString();
|
||||
if (Log.isDebugEnabled()) Log.debug("Removing binding with key="+key);
|
||||
if (__log.isDebugEnabled()) __log.debug("Removing binding with key="+key);
|
||||
_bindings.remove(key);
|
||||
}
|
||||
|
||||
|
@ -1443,4 +1445,48 @@ public class NamingContext implements Context, Cloneable
|
|||
return true;
|
||||
}
|
||||
|
||||
public String dump()
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
try
|
||||
{
|
||||
dump(buf,"");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
__log.warn(e);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void dump(Appendable out,String indent) throws IOException
|
||||
{
|
||||
out.append(this.getClass().getSimpleName()).append("@").append(Long.toHexString(this.hashCode())).append("\n");
|
||||
int size=_bindings.size();
|
||||
int i=0;
|
||||
for (Map.Entry<String,Binding> entry : ((Map<String,Binding>)_bindings).entrySet())
|
||||
{
|
||||
boolean last=++i==size;
|
||||
out.append(indent).append(" +- ").append(entry.getKey()).append(": ");
|
||||
|
||||
Binding binding = entry.getValue();
|
||||
Object value = binding.getObject();
|
||||
|
||||
|
||||
if ("comp".equals(entry.getKey()) && value instanceof Reference && "org.eclipse.jetty.jndi.ContextFactory".equals(((Reference)value).getFactoryClassName()))
|
||||
{
|
||||
ContextFactory.dump(out,indent+(last?" ":" | "));
|
||||
}
|
||||
else if (value instanceof NamingContext)
|
||||
((NamingContext)value).dump(out,indent+(last?" ":" | "));
|
||||
else
|
||||
{
|
||||
out.append(value.getClass().getSimpleName()).append("=");
|
||||
out.append(String.valueOf(value).replace('\n','|').replace('\r','|'));
|
||||
out.append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import javax.naming.NameParser;
|
|||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,8 @@ import org.eclipse.jetty.util.log.Log;
|
|||
*/
|
||||
public class NamingUtil
|
||||
{
|
||||
|
||||
public final static Logger __log=org.eclipse.jetty.util.log.Log.getLogger("jndi");
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Bind an object to a context ensuring all sub-contexts
|
||||
|
@ -66,22 +67,23 @@ public class NamingUtil
|
|||
try
|
||||
{
|
||||
subCtx = (Context)subCtx.lookup (name.get(i));
|
||||
if(Log.isDebugEnabled())Log.debug("Subcontext "+name.get(i)+" already exists");
|
||||
if(__log.isDebugEnabled())
|
||||
__log.debug("Subcontext "+name.get(i)+" already exists");
|
||||
}
|
||||
catch (NameNotFoundException e)
|
||||
{
|
||||
subCtx = subCtx.createSubcontext(name.get(i));
|
||||
if(Log.isDebugEnabled())Log.debug("Subcontext "+name.get(i)+" created");
|
||||
if(__log.isDebugEnabled())
|
||||
__log.debug("Subcontext "+name.get(i)+" created");
|
||||
}
|
||||
}
|
||||
|
||||
subCtx.rebind (name.get(name.size() - 1), obj);
|
||||
if(Log.isDebugEnabled())Log.debug("Bound object to "+name.get(name.size() - 1));
|
||||
if(__log.isDebugEnabled())
|
||||
__log.debug("Bound object to "+name.get(name.size() - 1));
|
||||
return subCtx;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void unbind (Context ctx)
|
||||
throws NamingException
|
||||
{
|
||||
|
|
|
@ -26,7 +26,8 @@ import javax.naming.StringRefAddr;
|
|||
|
||||
import org.eclipse.jetty.jndi.ContextFactory;
|
||||
import org.eclipse.jetty.jndi.NamingContext;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.jndi.NamingUtil;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
|
||||
|
@ -50,24 +51,26 @@ import org.eclipse.jetty.util.log.Log;
|
|||
*/
|
||||
public class javaRootURLContext implements Context
|
||||
{
|
||||
private static Logger __log = NamingUtil.__log;
|
||||
|
||||
public static final String URL_PREFIX = "java:";
|
||||
|
||||
protected Hashtable _env;
|
||||
|
||||
protected static NamingContext _nameRoot;
|
||||
protected static NamingContext __nameRoot;
|
||||
|
||||
protected static NameParser _javaNameParser;
|
||||
protected static NameParser __javaNameParser;
|
||||
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
_javaNameParser = new javaNameParser();
|
||||
_nameRoot = new NamingContext();
|
||||
_nameRoot.setNameParser(_javaNameParser);
|
||||
__javaNameParser = new javaNameParser();
|
||||
__nameRoot = new NamingContext();
|
||||
__nameRoot.setNameParser(__javaNameParser);
|
||||
|
||||
StringRefAddr parserAddr = new StringRefAddr("parser", _javaNameParser.getClass().getName());
|
||||
StringRefAddr parserAddr = new StringRefAddr("parser", __javaNameParser.getClass().getName());
|
||||
|
||||
Reference ref = new Reference ("javax.naming.Context",
|
||||
parserAddr,
|
||||
|
@ -75,11 +78,11 @@ public class javaRootURLContext implements Context
|
|||
(String)null);
|
||||
|
||||
//bind special object factory at comp
|
||||
_nameRoot.bind ("comp", ref);
|
||||
__nameRoot.bind ("comp", ref);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn(e);
|
||||
__log.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,13 +256,13 @@ public class javaRootURLContext implements Context
|
|||
public NameParser getNameParser (Name name)
|
||||
throws NamingException
|
||||
{
|
||||
return _javaNameParser;
|
||||
return __javaNameParser;
|
||||
}
|
||||
|
||||
public NameParser getNameParser (String name)
|
||||
throws NamingException
|
||||
{
|
||||
return _javaNameParser;
|
||||
return __javaNameParser;
|
||||
}
|
||||
|
||||
|
||||
|
@ -281,10 +284,9 @@ public class javaRootURLContext implements Context
|
|||
return _env;
|
||||
}
|
||||
|
||||
|
||||
protected NamingContext getRoot ()
|
||||
public static NamingContext getRoot ()
|
||||
{
|
||||
return _nameRoot;
|
||||
return __nameRoot;
|
||||
}
|
||||
|
||||
|
||||
|
@ -295,7 +297,7 @@ public class javaRootURLContext implements Context
|
|||
{
|
||||
String head = name.get(0);
|
||||
|
||||
if(Log.isDebugEnabled())Log.debug("Head element of name is: "+head);
|
||||
if(__log.isDebugEnabled())__log.debug("Head element of name is: "+head);
|
||||
|
||||
if (head.startsWith(URL_PREFIX))
|
||||
{
|
||||
|
@ -304,7 +306,7 @@ public class javaRootURLContext implements Context
|
|||
if (head.length() > 0)
|
||||
name.add(0, head);
|
||||
|
||||
if(Log.isDebugEnabled())Log.debug("name modified to "+name.toString());
|
||||
if(__log.isDebugEnabled())__log.debug("name modified to "+name.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,15 +35,14 @@ import org.eclipse.jetty.jndi.NamingContext;
|
|||
*/
|
||||
public class localContextRoot implements Context
|
||||
{
|
||||
private static final NamingContext _root;
|
||||
private static final NamingContext __root = new NamingContext();
|
||||
|
||||
private final Hashtable _env;
|
||||
|
||||
// make a root for the static namespace local:
|
||||
static
|
||||
{
|
||||
_root = new NamingContext();
|
||||
_root.setNameParser(new LocalNameParser());
|
||||
__root.setNameParser(new LocalNameParser());
|
||||
}
|
||||
|
||||
static class LocalNameParser implements NameParser
|
||||
|
@ -62,6 +61,11 @@ public class localContextRoot implements Context
|
|||
return new CompoundName(name, syntax);
|
||||
}
|
||||
}
|
||||
|
||||
public static NamingContext getRoot()
|
||||
{
|
||||
return __root;
|
||||
}
|
||||
|
||||
public localContextRoot(Hashtable env)
|
||||
{
|
||||
|
@ -95,9 +99,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public void destroySubcontext(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
_root.destroySubcontext(getSuffix(name));
|
||||
__root.destroySubcontext(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,9 +112,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public void unbind(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
_root.unbind(getSuffix(name));
|
||||
__root.unbind(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,9 +135,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public void destroySubcontext(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
_root.destroySubcontext(getSuffix(name));
|
||||
__root.destroySubcontext(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,9 +148,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public void unbind(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
_root.unbind(getSuffix(name));
|
||||
__root.unbind(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,9 +161,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public Object lookup(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
return _root.lookup(getSuffix(name));
|
||||
return __root.lookup(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,9 +174,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public Object lookupLink(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
return _root.lookupLink(getSuffix(name));
|
||||
return __root.lookupLink(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,9 +197,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public void bind(String name, Object obj) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
_root.bind(getSuffix(name), obj);
|
||||
__root.bind(getSuffix(name), obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,9 +210,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public void rebind(String name, Object obj) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
_root.rebind(getSuffix(name), obj);
|
||||
__root.rebind(getSuffix(name), obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,9 +223,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public Object lookup(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
return _root.lookup(getSuffix(name));
|
||||
return __root.lookup(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,9 +236,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public Object lookupLink(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
return _root.lookupLink(getSuffix(name));
|
||||
return __root.lookupLink(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,9 +249,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public void bind(Name name, Object obj) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
_root.bind(getSuffix(name), obj);
|
||||
__root.bind(getSuffix(name), obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -258,9 +262,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public void rebind(Name name, Object obj) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
_root.rebind(getSuffix(name), obj);
|
||||
__root.rebind(getSuffix(name), obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,9 +275,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public void rename(String oldName, String newName) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
_root.rename(getSuffix(oldName), getSuffix(newName));
|
||||
__root.rename(getSuffix(oldName), getSuffix(newName));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,9 +288,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public Context createSubcontext(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
return _root.createSubcontext(getSuffix(name));
|
||||
return __root.createSubcontext(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -297,9 +301,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public Context createSubcontext(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
return _root.createSubcontext(getSuffix(name));
|
||||
return __root.createSubcontext(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,9 +314,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public void rename(Name oldName, Name newName) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
_root.rename(getSuffix(oldName), getSuffix(newName));
|
||||
__root.rename(getSuffix(oldName), getSuffix(newName));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -323,7 +327,7 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public NameParser getNameParser(String name) throws NamingException
|
||||
{
|
||||
return _root.getNameParser(name);
|
||||
return __root.getNameParser(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -333,7 +337,7 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public NameParser getNameParser(Name name) throws NamingException
|
||||
{
|
||||
return _root.getNameParser(name);
|
||||
return __root.getNameParser(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -343,9 +347,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public NamingEnumeration list(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
return _root.list(getSuffix(name));
|
||||
return __root.list(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,9 +360,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public NamingEnumeration listBindings(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
return _root.listBindings(getSuffix(name));
|
||||
return __root.listBindings(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -369,9 +373,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public NamingEnumeration list(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
return _root.list(getSuffix(name));
|
||||
return __root.list(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -382,9 +386,9 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
synchronized (__root)
|
||||
{
|
||||
return _root.listBindings(getSuffix(name));
|
||||
return __root.listBindings(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,7 +412,7 @@ public class localContextRoot implements Context
|
|||
public String composeName(String name, String prefix)
|
||||
throws NamingException
|
||||
{
|
||||
return _root.composeName(name, prefix);
|
||||
return __root.composeName(name, prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -419,7 +423,7 @@ public class localContextRoot implements Context
|
|||
*/
|
||||
public Name composeName(Name name, Name prefix) throws NamingException
|
||||
{
|
||||
return _root.composeName(name, prefix);
|
||||
return __root.composeName(name, prefix);
|
||||
}
|
||||
|
||||
protected String getSuffix(String url) throws NamingException
|
||||
|
|
|
@ -31,6 +31,8 @@ import javax.naming.StringRefAddr;
|
|||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.eclipse.jetty.jndi.NamingContext;
|
||||
import org.eclipse.jetty.jndi.NamingUtil;
|
||||
import org.eclipse.jetty.jndi.local.localContextRoot;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -43,6 +45,11 @@ import static org.junit.Assert.fail;
|
|||
*/
|
||||
public class TestJNDI
|
||||
{
|
||||
static
|
||||
{
|
||||
// NamingUtil.__log.setDebugEnabled(true);
|
||||
}
|
||||
|
||||
public static class MyObjectFactory implements ObjectFactory
|
||||
{
|
||||
public static String myString = "xxx";
|
||||
|
@ -51,6 +58,7 @@ public class TestJNDI
|
|||
{
|
||||
return myString;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -239,6 +247,9 @@ public class TestJNDI
|
|||
//expected failure to modify immutable context
|
||||
}
|
||||
|
||||
System.err.println("java:"+javaRootURLContext.getRoot().dump());
|
||||
System.err.println("local:"+localContextRoot.getRoot().dump());
|
||||
|
||||
//test what happens when you close an initial context that was used
|
||||
initCtx.close();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import javax.naming.NameParser;
|
|||
import javax.naming.NamingException;
|
||||
|
||||
import org.eclipse.jetty.jndi.NamingUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
|
||||
|
@ -38,6 +38,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
*/
|
||||
public abstract class NamingEntry
|
||||
{
|
||||
private static Logger __log = NamingUtil.__log;
|
||||
public static final String __contextName = "__"; //all NamingEntries stored in context called "__"
|
||||
protected String jndiName; //the name representing the object associated with the NamingEntry
|
||||
protected Object objectToBind; //the object associated with the NamingEntry
|
||||
|
@ -45,7 +46,10 @@ public abstract class NamingEntry
|
|||
protected String objectNameString; //the name of the object relative to the context it is stored in
|
||||
|
||||
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return jndiName;
|
||||
}
|
||||
|
||||
|
||||
public NamingEntry (Object scope, String jndiName, Object object)
|
||||
|
@ -88,7 +92,7 @@ public abstract class NamingEntry
|
|||
//TODO - check on the whole overriding/non-overriding thing
|
||||
InitialContext ic = new InitialContext();
|
||||
Context env = (Context)ic.lookup("java:comp/env");
|
||||
Log.debug("Binding java:comp/env/"+localName+" to "+objectNameString);
|
||||
__log.debug("Binding java:comp/env/"+localName+" to "+objectNameString);
|
||||
NamingUtil.bind(env, localName, new LinkRef(objectNameString));
|
||||
}
|
||||
|
||||
|
@ -101,12 +105,12 @@ public abstract class NamingEntry
|
|||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
Context env = (Context)ic.lookup("java:comp/env");
|
||||
Log.debug("Unbinding java:comp/env/"+getJndiName());
|
||||
__log.debug("Unbinding java:comp/env/"+getJndiName());
|
||||
env.unbind(getJndiName());
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
Log.warn(e);
|
||||
__log.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,7 +131,7 @@ public abstract class NamingEntry
|
|||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
Log.warn(e);
|
||||
__log.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,6 +190,7 @@ public abstract class NamingEntry
|
|||
protected void save (Object scope)
|
||||
throws NamingException
|
||||
{
|
||||
__log.debug("SAVE {} in {}",this,scope);
|
||||
InitialContext ic = new InitialContext();
|
||||
NameParser parser = ic.getNameParser("");
|
||||
Name prefix = NamingEntryUtil.getNameForScope(scope);
|
||||
|
|
|
@ -28,12 +28,13 @@ import javax.naming.NameParser;
|
|||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.jndi.NamingUtil;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
public class NamingEntryUtil
|
||||
{
|
||||
|
||||
private static Logger __log = NamingUtil.__log;
|
||||
|
||||
/**
|
||||
* Link a name in a webapp's java:/comp/evn namespace to a pre-existing
|
||||
|
@ -176,7 +177,7 @@ public class NamingEntryUtil
|
|||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
Log.warn(e);
|
||||
__log.warn(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +229,7 @@ public class NamingEntryUtil
|
|||
}
|
||||
catch (NameNotFoundException e)
|
||||
{
|
||||
Log.debug("No entries of type "+clazz.getName()+" in context="+context);
|
||||
__log.debug("No entries of type "+clazz.getName()+" in context="+context);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
|
|
@ -21,7 +21,7 @@ import javax.naming.NamingException;
|
|||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.eclipse.jetty.jndi.NamingUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
/**
|
||||
* Transaction
|
||||
|
@ -30,6 +30,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
*/
|
||||
public class Transaction extends NamingEntry
|
||||
{
|
||||
private static Logger __log = NamingUtil.__log;
|
||||
public static final String USER_TRANSACTION = "UserTransaction";
|
||||
|
||||
|
||||
|
@ -68,7 +69,7 @@ public class Transaction extends NamingEntry
|
|||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
Context env = (Context)ic.lookup("java:comp/env");
|
||||
Log.debug("Binding java:comp/env"+getJndiName()+" to "+objectNameString);
|
||||
__log.debug("Binding java:comp/env"+getJndiName()+" to "+objectNameString);
|
||||
NamingUtil.bind(env, localName, new LinkRef(objectNameString));
|
||||
}
|
||||
|
||||
|
@ -82,7 +83,7 @@ public class Transaction extends NamingEntry
|
|||
//ignore the name, it is always bound to java:comp
|
||||
InitialContext ic = new InitialContext();
|
||||
Context env = (Context)ic.lookup("java:comp");
|
||||
Log.debug("Binding java:comp/"+getJndiName()+" to "+objectNameString);
|
||||
__log.debug("Binding java:comp/"+getJndiName()+" to "+objectNameString);
|
||||
NamingUtil.bind(env, getJndiName(), new LinkRef(objectNameString));
|
||||
}
|
||||
|
||||
|
@ -95,12 +96,12 @@ public class Transaction extends NamingEntry
|
|||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
Context env = (Context)ic.lookup("java:comp");
|
||||
Log.debug("Unbinding java:comp/"+getJndiName());
|
||||
__log.debug("Unbinding java:comp/"+getJndiName());
|
||||
env.unbind(getJndiName());
|
||||
}
|
||||
catch (NamingException e)
|
||||
{
|
||||
Log.warn(e);
|
||||
__log.warn(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -229,9 +229,9 @@ public class MultipartFilterTest
|
|||
|
||||
public static class DumpServlet extends HttpServlet
|
||||
{
|
||||
private static final long serialVersionUID = 201012011130L;
|
||||
private static final long serialVersionUID = 201012011130L;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue