320073 reconsile configuration mechanism

Reconsiled the jetty-8 configuration mechanism with the capability to share the MetaData between instances

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2168 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-07-22 03:20:41 +00:00
parent 526cef3ab3
commit 0443786d8e
20 changed files with 247 additions and 182 deletions

View File

@ -58,7 +58,6 @@ public class MonitoredDirAppProviderStartupTest
public void testStartupContext()
{
// Check Server for Handlers
jetty.printHandlers(System.out);
jetty.assertWebAppContextsExists("/foo");
}
}

View File

@ -1,6 +1,7 @@
package org.eclipse.jetty.deploy.providers;
import java.io.File;
import java.util.Arrays;
import org.eclipse.jetty.deploy.test.XmlConfiguredJetty;
import org.junit.AfterClass;
@ -41,16 +42,17 @@ public class WebAppProviderTest
public void testStartupContext()
{
// Check Server for Handlers
jetty.printHandlers(System.out);
jetty.assertWebAppContextsExists("/foo");
File workDir = jetty.getJettyDir("workish");
System.err.println("workDir="+workDir);
// Test for regressions
assertDirNotExists("root of work directory",workDir,"webinf");
assertDirNotExists("root of work directory",workDir,"jsp");
// Test for correct behavior
// Test for correct behaviour
Assert.assertTrue("Should have generated directory in work directory: " + workDir,hasJettyGeneratedPath(workDir,"foo.war"));
}
@ -58,13 +60,14 @@ public class WebAppProviderTest
{
for (File path : basedir.listFiles())
{
if (path.exists() && path.isDirectory() && path.getName().startsWith("Jetty_") && path.getName().contains(expectedWarFilename))
if (path.exists() && path.isDirectory() && path.getName().startsWith("jetty-") && path.getName().contains(expectedWarFilename))
{
System.out.println("Found expected generated directory: " + path);
return true;
}
}
System.err.println("did not find "+expectedWarFilename+" in "+Arrays.asList(basedir.listFiles()));
return false;
}

View File

@ -152,7 +152,7 @@ public class XmlConfiguredJetty
{
for (WebAppContext context : contexts)
{
System.out.println("WebAppContext should not exist:\n" + toString(context));
System.out.println("WebAppContext should not exist:\n" + context);
}
Assert.assertEquals("Contexts.size",0,contexts.size());
}
@ -381,12 +381,6 @@ public class XmlConfiguredJetty
}
public void printHandlers(PrintStream out)
{
Handler handler = server.getHandler();
out.println(toString(handler));
}
public void removeContext(String name)
{
File destDir = new File(jettyHome,"contexts");
@ -438,20 +432,6 @@ public class XmlConfiguredJetty
server.stop();
}
public String toString(Handler handler)
{
if (handler instanceof HandlerCollection)
{
return ((HandlerCollection)handler).dump();
}
if (handler instanceof AbstractHandler)
{
return ((AbstractHandler)handler).dump();
}
return handler.toString();
}
public void waitForDirectoryScan()
{

View File

@ -228,7 +228,6 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
{
if (_idleTimestamp!=0 && _maxIdleTime!=0 && now>(_idleTimestamp+_maxIdleTime))
{
System.err.println("IDLE "+this);
idleExpired();
}
}

View File

@ -29,14 +29,6 @@ import static org.junit.Assert.assertNotNull;
public class TestConfiguration
{
public class MyWebAppContext extends WebAppContext
{
public String toString()
{
return this.getClass().getName()+"@"+super.hashCode();
}
}
@Test
public void testIt () throws Exception
{
@ -48,7 +40,7 @@ public class TestConfiguration
Server server = new Server();
WebAppContext wac = new MyWebAppContext();
WebAppContext wac = new WebAppContext();
wac.setServer(server);
wac.setClassLoader(new WebAppClassLoader(Thread.currentThread().getContextClassLoader(), wac));

View File

@ -431,13 +431,14 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
@Override
protected void dump(Appendable out,String indent) throws IOException
{
super.dump(out,indent);
out.append(indent).append(" +=roles=").append(String.valueOf(_roles)).append('\n');
out.append(toString()).append(isStarted()?" started":" STOPPED").append('\n');
out.append(indent).append(" +-").append(String.valueOf(_roles)).append('\n');
for (Object path : _constraintMap.keySet())
{
Object constraint = _constraintMap.get(path);
out.append(indent).append(" +=").append(String.valueOf(path)).append('=').append(String.valueOf(constraint)).append('\n');
out.append(indent).append(" +-").append(String.valueOf(path)).append('=').append(String.valueOf(constraint)).append('\n');
}
dumpHandlers(out,indent);
}
}

View File

@ -50,7 +50,7 @@ public class ResourceCache
private final ResourceFactory _factory;
private final MimeTypes _mimeTypes;
private int _maxCachedFileSize =1024*1024;
private int _maxCachedFileSize =4*1024*1024;
private int _maxCachedFiles=2048;
private int _maxCacheSize =32*1024*1024;

View File

@ -128,9 +128,7 @@ public abstract class AbstractHandler extends AbstractLifeCycle implements Handl
/* ------------------------------------------------------------ */
protected void dump(Appendable out,String indent) throws IOException
{
out.append(toString());
out.append(isStarted()?" started":" STOPPED");
out.append('\n');
out.append(toString()).append(isStarted()?" started":" STOPPED").append('\n');
}
}

View File

@ -92,6 +92,7 @@ public abstract class AbstractHandlerContainer extends AbstractHandler implement
dumpHandlers(out,indent);
}
/* ------------------------------------------------------------ */
protected void dumpHandlers(Appendable out,String indent) throws IOException
{
Handler[] handlers = getHandlers();

View File

@ -185,6 +185,16 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
((HandlerCollection)parent).addHandler(this);
}
/* ------------------------------------------------------------ */
@Override
protected void dump(Appendable out,String indent) throws IOException
{
out.append(toString()).append(isStarted()?" started":" STOPPED").append('\n');
out.append(indent).append(" +-").append(String.valueOf(_attributes)).append('\n');
out.append(indent).append(" +-").append(String.valueOf(_contextAttributes)).append('\n');
dumpHandlers(out,indent);
}
/* ------------------------------------------------------------ */
public Context getServletContext()
{
@ -548,7 +558,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
_contextAttributes.clearAttributes();
try
{
// Set the classloader
if (_classLoader!=null)
{
@ -556,8 +565,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
old_classloader=current_thread.getContextClassLoader();
current_thread.setContextClassLoader(_classLoader);
}
if (_mimeTypes==null)
_mimeTypes=new MimeTypes();

View File

@ -216,7 +216,7 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
if (resourceCache!=null)
{
if (max_cache_size!=-1 || max_cached_file_size!= -2 || max_cached_files!=-2)
_servletContext.log("ignoring resource cache configuration, using resourceCache attribute");
Log.debug("ignoring resource cache configuration, using resourceCache attribute");
if (_relativeResourceBase!=null || _resourceBase!=null)
throw new UnavailableException("resourceCache specified with resource bases");
_cache=(ResourceCache)_servletContext.getAttribute(resourceCache);

View File

@ -129,8 +129,7 @@ public class ServletContextHandler extends ContextHandler
else if (parent instanceof HandlerCollection)
((HandlerCollection)parent).addHandler(this);
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.server.handler.ContextHandler#doStop()

View File

@ -131,7 +131,7 @@
</init-param>
<init-param>
<param-name>maxCachedFiles</param-name>
<param-value>1000</param-value>
<param-value>2048</param-value>
</init-param>
<init-param>
<param-name>cacheType</param-name>

View File

@ -230,10 +230,10 @@ public class ClasspathPattern
if (_entries != null)
{
int startIdx = 0;
name = name.replace('/','.');
name = name.replaceFirst("^[.]+","");
name = name.replaceAll("\\$.*$","");
for (Entry entry : _entries)
{
if (entry != null)

View File

@ -24,6 +24,8 @@ public interface Configuration
/* ------------------------------------------------------------------------------- */
/** Set up for configuration.
* <p>
* Typically this step discovers configuration resources
* @throws Exception
*/
public void preConfigure (WebAppContext context) throws Exception;
@ -31,6 +33,9 @@ public interface Configuration
/* ------------------------------------------------------------------------------- */
/** Configure WebApp.
* <p>
* Typically this step applies the discovered configuration resources to
* either the {@link WebAppContext} or the associated {@link MetaData}.
* @throws Exception
*/
public void configure (WebAppContext context) throws Exception;

View File

@ -301,6 +301,7 @@ public class MetaData
a.apply();
}
}
}
public boolean isDistributable ()

View File

@ -0,0 +1,38 @@
package org.eclipse.jetty.webapp;
import java.io.File;
import java.util.Enumeration;
public class MetaDataConfiguration implements Configuration
{
final WebAppContext _template;
MetaDataConfiguration(WebAppContext template)
{
_template=template;
}
public void preConfigure(WebAppContext context) throws Exception
{
File tmpDir=File.createTempFile(WebInfConfiguration.getCanonicalNameForWebAppTmpDir(context),"",_template.getTempDirectory().getParentFile());
if (tmpDir.exists())
tmpDir.delete();
tmpDir.mkdir();
tmpDir.deleteOnExit();
context.setTempDirectory(tmpDir);
}
public void configure(WebAppContext context) throws Exception
{
}
public void postConfigure(WebAppContext context) throws Exception
{
}
public void deconfigure(WebAppContext context) throws Exception
{
// TODO delete temp dir?
// TODO other stuff from other configuration deconfigures?
}
}

View File

@ -18,6 +18,7 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.PermissionCollection;
import java.util.Enumeration;
import java.util.EventListener;
import java.util.HashMap;
import java.util.Map;
@ -81,7 +82,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
// System classes are classes that cannot be replaced by
// the web application, and they are *always* loaded via
// system classloader.
private final static String[] __dftSystemClasses =
public final static String[] __dftSystemClasses =
{
"java.", // Java SE classes (per servlet spec v2.5 / SRV.9.7.2)
"javax.", // Java SE classes (per servlet spec v2.5 / SRV.9.7.2)
@ -99,14 +100,14 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
// loaded by the web application using system classloader,
// so if web application needs to load any of such classes,
// it has to include them in its distribution.
private final static String[] __dftServerClasses =
public final static String[] __dftServerClasses =
{
"-org.eclipse.jetty.continuation.", // don't hide continuation classes
"-org.eclipse.jetty.jndi.", // don't hide naming classes
"-org.eclipse.jetty.plus.jaas.", // don't hide jaas classes
"-org.eclipse.jetty.websocket.", // don't hide websocket extension
"-org.eclipse.jetty.servlet.DefaultServlet", // don't hide default servlet
"org.eclipse.jetty." // hide other jetty classes
"-org.eclipse.jetty.continuation.", // don't hide continuation classes
"-org.eclipse.jetty.jndi.", // don't hide naming classes
"-org.eclipse.jetty.plus.jaas.", // don't hide jaas classes
"-org.eclipse.jetty.websocket.", // don't hide websocket extension
"-org.eclipse.jetty.servlet.DefaultServlet", // don't hide default servlet
"org.eclipse.jetty." // hide other jetty classes
} ;
private String[] _configurationClasses = __dftConfigurationClasses;
@ -158,6 +159,38 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
//Make a new MetaData to hold descriptor and annotation metadata
_metadata = new MetaData();
}
/* ------------------------------------------------------------ */
public WebAppContext(WebAppContext template) throws IOException
{
super(SESSIONS|SECURITY);
if (template.isStarted())
throw new IllegalArgumentException("template is started");
_scontext=new Context();
setErrorHandler(new ErrorPageErrorHandler());
//Make a new MetaData to hold descriptor and annotation metadata
_metadata = template.getMetaData();
_configurations = new Configuration[]{new MetaDataConfiguration(template)};
System.err.println("webapp "+getContextPath()+" @ "+hashCode());
setAliases(template.isAliases());
setBaseResource(template.getBaseResource());
setClassLoader(template.getClassLoader()); // TODO maybe not share classloader?
setContextPath(template.getContextPath());
setCompactPath(template.isCompactPath());
setDisplayName(template.getDisplayName());
setLogger(template.getLogger()); // TODO maybe not shared ???
setMaxFormContentSize(template.getMaxFormContentSize());
Enumeration names=template.getAttributeNames();
while(names.hasMoreElements())
{
String name = (String)names.nextElement();
Object val = template.getAttribute(name);
if (!name.startsWith("javax.servlet."))
setAttribute(name,val);
}
}
/* ------------------------------------------------------------ */
/**
@ -191,18 +224,6 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
_metadata = new MetaData();
}
/* ------------------------------------------------------------ */
/**
*/
public WebAppContext(SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
{
super(null,sessionHandler,securityHandler,servletHandler,errorHandler);
_scontext=new Context();
setErrorHandler(errorHandler!=null?errorHandler:new ErrorPageErrorHandler());
//Make a new MetaData to hold descriptor and annotation metadata
_metadata = new MetaData();
}
/* ------------------------------------------------------------ */
/**
* @param servletContextName The servletContextName to set.
@ -339,7 +360,75 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
{
_configurationDiscovered = discovered;
}
/* ------------------------------------------------------------ */
/** Pre configure the web application.
* <p>
* The method is normally called from {@link #start()}. It performs
* the discovery of the configurations to be applied to this context,
* specifically:<ul>
* <li>Instantiate the {@link Configuration} instances with a call to {@link #loadConfigurations()}.
* <li>Setup the default System classes by calling {@link #loadSystemClasses()}
* <li>Setup the default Server classes by calling {@link #loadServerClasses()}
* <li>Instantiates a classload (if one is not already set)
* <li>Calls the {@link Configuration#preConfigure(WebAppContext)} method of all
* Configuration instances.
* </ul>
* @throws Exception
*/
public void preConfigure() throws Exception
{
// Setup configurations
loadConfigurations();
// Setup system classes
loadSystemClasses();
// Setup server classes
loadServerClasses();
// Configure classloader
_ownClassLoader=false;
if (getClassLoader()==null)
{
WebAppClassLoader classLoader = new WebAppClassLoader(this);
setClassLoader(classLoader);
_ownClassLoader=true;
}
if (Log.isDebugEnabled())
{
ClassLoader loader = getClassLoader();
Log.debug("Thread Context class loader is: " + loader);
loader=loader.getParent();
while(loader!=null)
{
Log.debug("Parent class loader is: " + loader);
loader=loader.getParent();
}
}
// Prepare for configuration
for (int i=0;i<_configurations.length;i++)
_configurations[i].preConfigure(this);
}
/* ------------------------------------------------------------ */
public void configure() throws Exception
{
// Configure webapp
for (int i=0;i<_configurations.length;i++)
_configurations[i].configure(this);
}
/* ------------------------------------------------------------ */
public void postConfigure() throws Exception
{
// Clean up after configuration
for (int i=0;i<_configurations.length;i++)
_configurations[i].postConfigure(this);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.thread.AbstractLifeCycle#doStart()
@ -349,49 +438,9 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
{
try
{
// Setup configurations
loadConfigurations();
// Setup system classes
loadSystemClasses();
// Setup server classes
loadServerClasses();
// Configure classloader
_ownClassLoader=false;
if (getClassLoader()==null)
{
WebAppClassLoader classLoader = new WebAppClassLoader(this);
setClassLoader(classLoader);
_ownClassLoader=true;
}
if (Log.isDebugEnabled())
{
ClassLoader loader = getClassLoader();
Log.debug("Thread Context class loader is: " + loader);
loader=loader.getParent();
while(loader!=null)
{
Log.debug("Parent class loader is: " + loader);
loader=loader.getParent();
}
}
// Prepare for configuration
for (int i=0;i<_configurations.length;i++)
_configurations[i].preConfigure(this);
preConfigure();
super.doStart();
// Clean up after configuration
for (int i=0;i<_configurations.length;i++)
_configurations[i].postConfigure(this);
postConfigure();
if (isLogUrlOnStart())
dumpUrl();
@ -557,8 +606,9 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
return _systemClasses.match(name);
}
private void loadSystemClasses()
/* ------------------------------------------------------------ */
protected void loadSystemClasses()
{
if (_systemClasses != null)
return;
@ -577,6 +627,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
_systemClasses = ClasspathPattern.fromArray(__dftSystemClasses);
}
/* ------------------------------------------------------------ */
private void loadServerClasses()
{
if (_serverClasses != null)
@ -920,6 +971,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
setAttribute(TEMPDIR,_tmpDir);
}
/* ------------------------------------------------------------ */
public File getTempDirectory ()
{
return _tmpDir;
@ -997,10 +1049,8 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
protected void startContext()
throws Exception
{
// Configure webapp
for (int i=0;i<_configurations.length;i++)
_configurations[i].configure(this);
configure();
//resolve the metadata
_metadata.resolve(this);

View File

@ -10,6 +10,7 @@ import java.util.List;
import java.util.regex.Pattern;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.PatternMatcher;
import org.eclipse.jetty.util.URIUtil;
@ -20,7 +21,7 @@ import org.eclipse.jetty.util.resource.ResourceCollection;
public class WebInfConfiguration implements Configuration
{
public static final String TEMPDIR_CREATED = "org.eclipse.jetty.tmpdirCreated";
public static final String TEMPDIR_CONFIGURED = "org.eclipse.jetty.tmpdirConfigured";
public static final String CONTAINER_JAR_PATTERN = "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern";
public static final String WEBINF_JAR_PATTERN = "org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern";
@ -37,15 +38,17 @@ public class WebInfConfiguration implements Configuration
public void preConfigure(final WebAppContext context) throws Exception
{
// Look for a work directory
File work = findWorkDirectory(context);
if (work != null)
makeTempDirectory(work, context, false);
//Make a temp directory for the webapp if one is not already set
resolveTempDirectory(context);
//Extract webapp if necessary
unpack (context);
File work = findWorkDirectory(context);
if (work != null)
makeTempDirectory(work, context, false);
//Apply an initial ordering to the jars which governs which will be scanned for META-INF
//info and annotations. The ordering is based on inclusion patterns.
@ -154,26 +157,20 @@ public class WebInfConfiguration implements Configuration
public void deconfigure(WebAppContext context) throws Exception
{
// delete temp directory if we had to create it or if it isn't called work
Boolean containerCreated = (Boolean)context.getAttribute(TEMPDIR_CREATED);
Boolean tmpdirConfigured = (Boolean)context.getAttribute(TEMPDIR_CONFIGURED);
if (context.getTempDirectory()!=null && (containerCreated != null && containerCreated.booleanValue()) && !isTempWorkDirectory(context.getTempDirectory()))
if (context.getTempDirectory()!=null && (tmpdirConfigured == null || !tmpdirConfigured.booleanValue()) && !isTempWorkDirectory(context.getTempDirectory()))
{
IO.delete(context.getTempDirectory());
setTempDirectory(null, context);
context.setTempDirectory(null);
}
context.setAttribute(TEMPDIR_CREATED, null);
context.setAttribute(TEMPDIR_CONFIGURED, null);
context.setAttribute(context.TEMPDIR, null);
//reset the base resource back to what it was before we did any unpacking of resources
context.setBaseResource(_preUnpackBaseResource);
}
/* ------------------------------------------------------------ */
/**
@ -213,10 +210,11 @@ public class WebInfConfiguration implements Configuration
*/
public void resolveTempDirectory (WebAppContext context)
{
//If a tmp directory is already set, we're done
//If a tmp directory is already set, we're done
File tmpDir = context.getTempDirectory();
if (tmpDir != null && tmpDir.isDirectory() && tmpDir.canWrite())
{
context.setAttribute(TEMPDIR_CONFIGURED, Boolean.TRUE);
return; // Already have a suitable tmp dir configured
}
@ -275,7 +273,7 @@ public class WebInfConfiguration implements Configuration
tmpDir.delete();
tmpDir.mkdir();
tmpDir.deleteOnExit();
setTempDirectory(tmpDir, context);
context.setTempDirectory(tmpDir);
}
catch(IOException e)
{
@ -347,17 +345,11 @@ public class WebInfConfiguration implements Configuration
if(!sentinel.exists())
sentinel.mkdir();
}
setTempDirectory(tmpDir, context);
}
}
public void setTempDirectory (File tmpDir, WebAppContext context)
{
context.setAttribute(TEMPDIR_CREATED, Boolean.TRUE);
context.setAttribute(context.TEMPDIR,tmpDir);
context.setTempDirectory(tmpDir);
if(Log.isDebugEnabled())Log.debug("Set temp dir "+tmpDir);
if(Log.isDebugEnabled())
Log.debug("Set temp dir "+tmpDir);
context.setTempDirectory(tmpDir);
}
}
@ -527,8 +519,6 @@ public class WebInfConfiguration implements Configuration
return null;
}
/**
* Check if the tmpDir itself is called "work", or if the tmpDir
@ -557,35 +547,40 @@ public class WebInfConfiguration implements Configuration
* context and virtual host uniquely identify the webapp
* @return the canonical name for the webapp temp directory
*/
public String getCanonicalNameForWebAppTmpDir (WebAppContext context)
public static String getCanonicalNameForWebAppTmpDir (WebAppContext context)
{
StringBuffer canonicalName = new StringBuffer();
canonicalName.append("Jetty");
canonicalName.append("jetty-");
//get the host and the port from the first connector
Connector[] connectors = context.getServer().getConnectors();
//Get the host
canonicalName.append("_");
String host = (connectors==null||connectors[0]==null?"":connectors[0].getHost());
if (host == null)
host = "0.0.0.0";
canonicalName.append(host.replace('.', '_'));
//Get the port
canonicalName.append("_");
//try getting the real port being listened on
int port = (connectors==null||connectors[0]==null?0:connectors[0].getLocalPort());
//if not available (eg no connectors or connector not started),
//try getting one that was configured.
if (port < 0)
port = connectors[0].getPort();
canonicalName.append(port);
Server server=context.getServer();
if (server!=null)
{
Connector[] connectors = context.getServer().getConnectors();
if (connectors.length>0)
{
//Get the host
String host = (connectors==null||connectors[0]==null?"":connectors[0].getHost());
if (host == null)
host = "0.0.0.0";
canonicalName.append(host);
//Get the port
canonicalName.append("-");
//try getting the real port being listened on
int port = (connectors==null||connectors[0]==null?0:connectors[0].getLocalPort());
//if not available (eg no connectors or connector not started),
//try getting one that was configured.
if (port < 0)
port = connectors[0].getPort();
canonicalName.append(port);
canonicalName.append("-");
}
}
//Resource base
canonicalName.append("_");
try
{
Resource resource = context.getBaseResource();
@ -606,6 +601,7 @@ public class WebInfConfiguration implements Configuration
//get just the last part which is the filename
int i = tmp.lastIndexOf("/");
canonicalName.append(tmp.substring(i+1, tmp.length()));
canonicalName.append("-");
}
catch (Exception e)
{
@ -613,33 +609,28 @@ public class WebInfConfiguration implements Configuration
}
//Context name
canonicalName.append("_");
String contextPath = context.getContextPath();
contextPath=contextPath.replace('/','_');
contextPath=contextPath.replace('\\','_');
canonicalName.append(contextPath);
//Virtual host (if there is one)
canonicalName.append("_");
canonicalName.append("-");
String[] vhosts = context.getVirtualHosts();
if (vhosts == null || vhosts.length <= 0)
canonicalName.append("");
canonicalName.append("any");
else
canonicalName.append(vhosts[0]);
//base36 hash of the whole string for uniqueness
String hash = Integer.toString(canonicalName.toString().hashCode(),36);
canonicalName.append("_");
canonicalName.append(hash);
// sanitize
for (int i=0;i<canonicalName.length();i++)
{
char c=canonicalName.charAt(i);
if (!Character.isJavaIdentifierPart(c))
if (!Character.isJavaIdentifierPart(c) && "-.".indexOf(c)<0)
canonicalName.setCharAt(i,'.');
}
canonicalName.append("-");
return canonicalName.toString();
}

View File

@ -69,10 +69,10 @@ public class TestFilter implements Filter
String from = request.getRemoteHost();
String to = request.getServerName();
String path=((HttpServletRequest)request).getServletPath();
if (!_remote && !_allowed.contains(path) && (
!from.equals("localhost") && !from.startsWith("127.") ||
!to.equals("localhost")&&!to.startsWith("127.0.0.")))
!from.equals("localhost") && !from.startsWith("127.") && from.indexOf(":1")<0 ||
!to.equals("localhost")&&!to.startsWith("127.0.0.") && to.indexOf(":1")<0))
{
if ("/".equals(path))
_context.getRequestDispatcher("/remote.html").forward(request,response);