Merge branch 'jetty-8' into release-8
This commit is contained in:
commit
994d8baa3f
31
VERSION.txt
31
VERSION.txt
|
@ -38,6 +38,37 @@ jetty-8.1.12.v20130726 - 26 July 2013
|
|||
+ 413684 Trailing slash shows JSP source
|
||||
+ 413812 Make RateTracker serializable
|
||||
|
||||
jetty-7.6.12.v20130726 - 26 July 2013
|
||||
+ 396706 CGI support parameters
|
||||
+ 397193 MongoSessionManager refresh updates last access time
|
||||
+ 407342 ReloadedSessionMissingClassTest uses class compiled with jdk7
|
||||
+ 408529 Etags set in 304 response
|
||||
+ 408600 set correct jetty.url in all pom files
|
||||
+ 408642 setContentType from addHeader
|
||||
+ 408662 In pax-web servlet services requests even if init() has not finished
|
||||
running
|
||||
+ 408909 GzipFilter setting of headers when reset and/or not compressed
|
||||
+ 409028 Jetty HttpClient does not work with proxy CONNECT method.
|
||||
+ 409133 Empty <welcome-file> causes StackOverflowError
|
||||
+ 409556 FileInputStream not closed in DirectNIOBuffer
|
||||
+ 410630 MongoSessionManager conflicting session update op
|
||||
+ 410750 NoSQLSessions: implement session context data persistence across
|
||||
server restarts
|
||||
+ 411135 HttpClient may send proxied https requests to the proxy instead of
|
||||
the target server.
|
||||
+ 411216 RequestLogHandler handles async completion
|
||||
+ 411458 MultiPartFilter getParameterMap doesn't preserve multivalued
|
||||
parameters 411459 MultiPartFilter.Wrapper getParameter should use charset
|
||||
encoding of part
|
||||
+ 411755 MultiPartInputStreamParser fails on base64 encoded content
|
||||
+ 411909 GzipFilter flushbuffer() results in erroneous finish() call
|
||||
+ 412712 HttpClient does not send the terminal chunk after partial writes.
|
||||
+ 412750 HttpClient close expired connections fix
|
||||
+ 413371 Default JSON.Converters for List and Set.
|
||||
+ 413372 JSON Enum uses name rather than toString()
|
||||
+ 413684 Trailing slash shows JSP source
|
||||
+ 413812 Make RateTracker serializable
|
||||
|
||||
jetty-8.1.11.v20130520 - 20 May 2013
|
||||
+ 402844 STOP.PORT & STOP.KEY behaviour has changed
|
||||
+ 403281 jetty.sh waits for started or failure before returning
|
||||
|
|
|
@ -43,6 +43,11 @@ public class DumpServlet extends HttpServlet
|
|||
response.getWriter().println("servletPath=" + request.getServletPath());
|
||||
response.getWriter().println("pathInfo=" + request.getPathInfo());
|
||||
response.getWriter().println("session=" + request.getSession(true).getId());
|
||||
|
||||
String r=request.getParameter("resource");
|
||||
if (r!=null)
|
||||
response.getWriter().println("resource("+r+")=" + getServletContext().getResource(r));
|
||||
|
||||
response.getWriter().println("</pre>");
|
||||
}
|
||||
}
|
|
@ -76,6 +76,11 @@
|
|||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-jndi</artifactId>
|
||||
|
|
|
@ -25,12 +25,9 @@ import java.net.URL;
|
|||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarEntry;
|
||||
|
||||
|
@ -733,10 +730,10 @@ public class AnnotationParser
|
|||
public void parse (Resource dir, ClassNameResolver resolver)
|
||||
throws Exception
|
||||
{
|
||||
if (!dir.isDirectory() || !dir.exists())
|
||||
if (!dir.isDirectory() || !dir.exists() || dir.getName().startsWith("."))
|
||||
return;
|
||||
|
||||
|
||||
|
||||
String[] files=dir.list();
|
||||
for (int f=0;files!=null && f<files.length;f++)
|
||||
{
|
||||
|
@ -745,15 +742,20 @@ public class AnnotationParser
|
|||
Resource res = dir.addPath(files[f]);
|
||||
if (res.isDirectory())
|
||||
parse(res, resolver);
|
||||
String name = res.getName();
|
||||
if (name.endsWith(".class"))
|
||||
else
|
||||
{
|
||||
if ((resolver == null)|| (!resolver.isExcluded(name) && (!isParsed(name) || resolver.shouldOverride(name))))
|
||||
String fullname = res.getName();
|
||||
String filename = res.getFile().getName();
|
||||
|
||||
if (isValidClassFileName(filename))
|
||||
{
|
||||
Resource r = Resource.newResource(res.getURL());
|
||||
scanClass(r.getInputStream());
|
||||
}
|
||||
if ((resolver == null)|| (!resolver.isExcluded(fullname) && (!isParsed(fullname) || resolver.shouldOverride(fullname))))
|
||||
{
|
||||
Resource r = Resource.newResource(res.getURL());
|
||||
scanClass(r.getInputStream());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -789,8 +791,12 @@ public class AnnotationParser
|
|||
{
|
||||
try
|
||||
{
|
||||
String name = entry.getName();
|
||||
if (name.toLowerCase(Locale.ENGLISH).endsWith(".class"))
|
||||
//skip directories
|
||||
if (entry.isDirectory())
|
||||
return;
|
||||
|
||||
String name = entry.getName();
|
||||
if (isValidClassFilePath(name) && isValidClassFileName(name))
|
||||
{
|
||||
String shortName = name.replace('/', '.').substring(0,name.length()-6);
|
||||
if ((resolver == null)
|
||||
|
@ -834,8 +840,12 @@ public class AnnotationParser
|
|||
{
|
||||
try
|
||||
{
|
||||
//skip directories
|
||||
if (entry.isDirectory())
|
||||
return;
|
||||
|
||||
String name = entry.getName();
|
||||
if (name.toLowerCase(Locale.ENGLISH).endsWith(".class"))
|
||||
if (isValidClassFilePath(name) && isValidClassFileName(name))
|
||||
{
|
||||
String shortName = name.replace('/', '.').substring(0,name.length()-6);
|
||||
|
||||
|
@ -873,7 +883,7 @@ public class AnnotationParser
|
|||
URI[] uris = {uri};
|
||||
parse(uris, resolver);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -888,5 +898,67 @@ public class AnnotationParser
|
|||
ClassReader reader = new ClassReader(is);
|
||||
reader.accept(new MyClassVisitor(), ClassReader.SKIP_CODE|ClassReader.SKIP_DEBUG|ClassReader.SKIP_FRAMES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the given path represents a valid class file name.
|
||||
* The check is fairly cursory, checking that:
|
||||
* <ul>
|
||||
* <li> the name ends with .class</li>
|
||||
* <li> it isn't a dot file or in a hidden directory </li>
|
||||
* <li> the name of the class at least begins with a valid identifier for a class name </li>
|
||||
* </ul>
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
private boolean isValidClassFileName (String name)
|
||||
{
|
||||
//no name cannot be valid
|
||||
if (name == null || name.length()==0)
|
||||
return false;
|
||||
|
||||
//skip anything that is not a class file
|
||||
if (!name.toLowerCase(Locale.ENGLISH).endsWith(".class"))
|
||||
{
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Not a class: {}",name);
|
||||
return false;
|
||||
}
|
||||
|
||||
//skip any classfiles that are not a valid java identifier
|
||||
int c0 = 0;
|
||||
int ldir = name.lastIndexOf('/', name.length()-6);
|
||||
c0 = (ldir > -1 ? ldir+1 : c0);
|
||||
if (!Character.isJavaIdentifierStart(name.charAt(c0)))
|
||||
{
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Not a java identifier: {}"+name);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check that the given path does not contain hidden directories
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
private boolean isValidClassFilePath (String path)
|
||||
{
|
||||
//no path is not valid
|
||||
if (path == null || path.length()==0)
|
||||
return false;
|
||||
|
||||
|
||||
//skip any classfiles that are in a hidden directory
|
||||
if (path.startsWith(".") || path.contains("/."))
|
||||
{
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Contains hidden dirs: {}"+path);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,25 @@
|
|||
|
||||
package org.eclipse.jetty.annotations;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
|
||||
import org.eclipse.jetty.annotations.AnnotationParser.Value;
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.TestingDir;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -31,6 +45,56 @@ import static org.junit.Assert.fail;
|
|||
|
||||
public class TestAnnotationParser
|
||||
{
|
||||
|
||||
@Rule
|
||||
public TestingDir testdir = new TestingDir();
|
||||
|
||||
|
||||
|
||||
public static class TrackingAnnotationHandler implements DiscoverableAnnotationHandler
|
||||
{
|
||||
|
||||
private final String annotationName;
|
||||
public final Set<String> foundClasses;
|
||||
|
||||
public TrackingAnnotationHandler(String annotationName)
|
||||
{
|
||||
this.annotationName = annotationName;
|
||||
this.foundClasses = new HashSet<String>();
|
||||
}
|
||||
|
||||
|
||||
public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation,
|
||||
List<Value> values)
|
||||
{
|
||||
foundClasses.add(className);
|
||||
}
|
||||
|
||||
|
||||
public void handleMethod(String className, String methodName, int access, String desc, String signature, String[] exceptions, String annotation,
|
||||
List<Value> values)
|
||||
{
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
|
||||
public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
|
||||
List<Value> values)
|
||||
{
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getAnnotationName()
|
||||
{
|
||||
return this.annotationName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testSampleAnnotation() throws Exception
|
||||
{
|
||||
|
@ -51,35 +115,20 @@ public class TestAnnotationParser
|
|||
}
|
||||
|
||||
public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
|
||||
List<Value> values)
|
||||
List<Value> values)
|
||||
{
|
||||
assertEquals ("m", fieldName);
|
||||
assertEquals (org.objectweb.asm.Type.OBJECT, org.objectweb.asm.Type.getType(fieldType).getSort());
|
||||
assertEquals (1, values.size());
|
||||
Value anv1 = values.get(0);
|
||||
assertEquals ("value", anv1.getName());
|
||||
assertEquals (7, anv1.getValue());
|
||||
assertEquals ("m", fieldName);
|
||||
assertEquals (org.objectweb.asm.Type.OBJECT, org.objectweb.asm.Type.getType(fieldType).getSort());
|
||||
assertEquals (1, values.size());
|
||||
Value anv1 = values.get(0);
|
||||
assertEquals ("value", anv1.getName());
|
||||
assertEquals (7, anv1.getValue());
|
||||
|
||||
}
|
||||
|
||||
public void handleMethod(String className, String methodName, int access, String desc, String signature, String[] exceptions, String annotation,
|
||||
List<Value> values)
|
||||
{
|
||||
System.err.println("Sample annotated method : classname="+className+" methodName="+methodName+" access="+access+" desc="+desc+" signature="+signature);
|
||||
|
||||
org.objectweb.asm.Type retType = org.objectweb.asm.Type.getReturnType(desc);
|
||||
System.err.println("REturn type = "+retType);
|
||||
org.objectweb.asm.Type[] params = org.objectweb.asm.Type.getArgumentTypes(desc);
|
||||
if (params == null)
|
||||
System.err.println("No params");
|
||||
else
|
||||
System.err.println(params.length+" params");
|
||||
|
||||
if (exceptions == null)
|
||||
System.err.println("No exceptions");
|
||||
else
|
||||
System.err.println(exceptions.length+" exceptions");
|
||||
|
||||
assertEquals("org.eclipse.jetty.annotations.ClassA", className);
|
||||
assertTrue(methods.contains(methodName));
|
||||
assertEquals("org.eclipse.jetty.annotations.Sample", annotation);
|
||||
|
@ -109,8 +158,7 @@ public class TestAnnotationParser
|
|||
|
||||
});
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
System.err.println("Time to parse class: "+((end-start)));
|
||||
//System.err.println("Time to parse class: "+((end-start)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -125,11 +173,6 @@ public class TestAnnotationParser
|
|||
List<Value> values)
|
||||
{
|
||||
assertTrue("org.eclipse.jetty.annotations.ClassB".equals(className));
|
||||
|
||||
for (Value anv: values)
|
||||
{
|
||||
System.err.println(anv.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
|
||||
|
@ -144,10 +187,6 @@ public class TestAnnotationParser
|
|||
{
|
||||
assertTrue("org.eclipse.jetty.annotations.ClassB".equals(className));
|
||||
assertTrue("a".equals(methodName));
|
||||
for (Value anv: values)
|
||||
{
|
||||
System.err.println(anv.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -162,4 +201,67 @@ public class TestAnnotationParser
|
|||
parser.registerHandler(new MultiAnnotationHandler());
|
||||
parser.parse(classNames, null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHiddenFilesInJar () throws Exception
|
||||
{
|
||||
File badClassesJar = MavenTestingUtils.getTestResourceFile("bad-classes.jar");
|
||||
AnnotationParser parser = new AnnotationParser();
|
||||
parser.parse(badClassesJar.toURI(), null);
|
||||
//only the valid classes inside bad-classes.jar should be parsed. If any invalid classes are parsed and exception would be thrown here
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasedirExclusion() throws Exception
|
||||
{
|
||||
// Build up basedir, which itself has a path segment that violates java package and classnaming.
|
||||
// The basedir should have no effect on annotation scanning.
|
||||
// Intentionally using a base director name that starts with a "."
|
||||
// This mimics what you see in jenkins, hudson, hadoop, solr, camel, and selenium for their
|
||||
// installed and/or managed webapps
|
||||
File basedir = testdir.getFile(".base/workspace/classes");
|
||||
FS.ensureEmpty(basedir);
|
||||
|
||||
// Copy in class that is known to have annotations.
|
||||
copyClass(ClassA.class,basedir);
|
||||
|
||||
// Setup Tracker
|
||||
TrackingAnnotationHandler tracker = new TrackingAnnotationHandler(Sample.class.getName());
|
||||
|
||||
// Setup annotation scanning
|
||||
AnnotationParser parser = new AnnotationParser();
|
||||
parser.registerHandler(tracker);
|
||||
|
||||
// Parse
|
||||
parser.parse(Resource.newResource(basedir),null);
|
||||
|
||||
// Validate
|
||||
assertTrue(tracker.foundClasses.contains(ClassA.class.getName()));
|
||||
}
|
||||
|
||||
private void copyClass(Class<?> clazz, File basedir) throws IOException
|
||||
{
|
||||
String classname = clazz.getName().replace('.',File.separatorChar) + ".class";
|
||||
URL url = this.getClass().getResource('/'+classname);
|
||||
assertTrue(url != null);
|
||||
|
||||
String classpath = classname.substring(0,classname.lastIndexOf(File.separatorChar));
|
||||
FS.ensureDirExists(new File(basedir,classpath));
|
||||
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try
|
||||
{
|
||||
in = url.openStream();
|
||||
out = new FileOutputStream(new File(basedir,classname));
|
||||
IO.copy(in,out);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IO.close(out);
|
||||
IO.close(in);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -27,6 +27,7 @@ import org.eclipse.jetty.deploy.ConfigurationManager;
|
|||
import org.eclipse.jetty.deploy.util.FileID;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
||||
/** Context directory App Provider.
|
||||
|
@ -37,6 +38,8 @@ import org.eclipse.jetty.xml.XmlConfiguration;
|
|||
public class ContextProvider extends ScanningAppProvider
|
||||
{
|
||||
private ConfigurationManager _configurationManager;
|
||||
private boolean _parentLoaderPriority = false;
|
||||
private String _defaultsDescriptor;
|
||||
|
||||
public ContextProvider()
|
||||
{
|
||||
|
@ -79,7 +82,22 @@ public class ContextProvider extends ScanningAppProvider
|
|||
|
||||
if (resource.exists() && FileID.isXmlFile(file))
|
||||
{
|
||||
XmlConfiguration xmlc = new XmlConfiguration(resource.getURL());
|
||||
XmlConfiguration xmlc = new XmlConfiguration(resource.getURL())
|
||||
{
|
||||
@Override
|
||||
public void initializeDefaults(Object context)
|
||||
{
|
||||
super.initializeDefaults(context);
|
||||
|
||||
if (context instanceof WebAppContext)
|
||||
{
|
||||
WebAppContext webapp = (WebAppContext)context;
|
||||
webapp.setParentLoaderPriority(_parentLoaderPriority);
|
||||
if (_defaultsDescriptor!=null)
|
||||
webapp.setDefaultsDescriptor(_defaultsDescriptor);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xmlc.getIdMap().put("Server",getDeploymentManager().getServer());
|
||||
if (getConfigurationManager() != null)
|
||||
|
@ -89,5 +107,44 @@ public class ContextProvider extends ScanningAppProvider
|
|||
|
||||
throw new IllegalStateException("App resouce does not exist "+resource);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the parentLoaderPriority.
|
||||
* @return the parentLoaderPriority
|
||||
*/
|
||||
public boolean isParentLoaderPriority()
|
||||
{
|
||||
return _parentLoaderPriority;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Set the parentLoaderPriority.
|
||||
* <p>If the context created is a WebAppContext, then set the
|
||||
* default value for {@link WebAppContext#setParentLoaderPriority(boolean)}.
|
||||
* @param parentLoaderPriority the parentLoaderPriority to set
|
||||
*/
|
||||
public void setParentLoaderPriority(boolean parentLoaderPriority)
|
||||
{
|
||||
_parentLoaderPriority = parentLoaderPriority;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get the defaultsDescriptor.
|
||||
* @return the defaultsDescriptor
|
||||
*/
|
||||
public String getDefaultsDescriptor()
|
||||
{
|
||||
return _defaultsDescriptor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Set the defaultsDescriptor.
|
||||
* <p>If the context created is a WebAppContext, then set the
|
||||
* default value for {@link WebAppContext#setDefaultsDescriptor(String)}
|
||||
* @param defaultsDescriptor the defaultsDescriptor to set
|
||||
*/
|
||||
public void setDefaultsDescriptor(String defaultsDescriptor)
|
||||
{
|
||||
_defaultsDescriptor = defaultsDescriptor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -414,6 +414,9 @@ public class PathMap extends HashMap implements Externalizable
|
|||
public static boolean match(String pathSpec, String path, boolean noDefault)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (pathSpec.length()==0)
|
||||
return "/".equals(path);
|
||||
|
||||
char c = pathSpec.charAt(0);
|
||||
if (c=='/')
|
||||
{
|
||||
|
|
|
@ -133,6 +133,8 @@ public class PathMapTest extends TestCase
|
|||
assertTrue("!match *.foo", !PathMap.match("*.foo", "anything.bar"));
|
||||
|
||||
assertEquals("match / with ''", "10", p.getMatch("/").getValue());
|
||||
|
||||
assertTrue("match \"\"", PathMap.match("", "/"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,16 +63,57 @@ public class NoSqlSession extends AbstractSession
|
|||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (_dirty==null)
|
||||
_dirty=new HashSet<String>();
|
||||
_dirty.add(name);
|
||||
Object old = super.doPutOrRemove(name,value);
|
||||
|
||||
if (_manager.getSavePeriod()==-2)
|
||||
{
|
||||
save(true);
|
||||
}
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, Object value)
|
||||
{
|
||||
if ( updateAttribute(name,value) )
|
||||
{
|
||||
if (_dirty==null)
|
||||
{
|
||||
_dirty=new HashSet<String>();
|
||||
}
|
||||
|
||||
_dirty.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* a boolean version of the setAttribute method that lets us manage the _dirty set
|
||||
*/
|
||||
protected boolean updateAttribute (String name, Object value)
|
||||
{
|
||||
Object old=null;
|
||||
synchronized (this)
|
||||
{
|
||||
checkValid();
|
||||
old=doPutOrRemove(name,value);
|
||||
}
|
||||
|
||||
if (value==null || !value.equals(old))
|
||||
{
|
||||
if (old!=null)
|
||||
unbindValue(name,old);
|
||||
if (value!=null)
|
||||
bindValue(name,value);
|
||||
|
||||
_manager.doSessionAttributeListeners(this,name,old,value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
protected void checkValid() throws IllegalStateException
|
||||
|
|
|
@ -20,11 +20,10 @@ package org.eclipse.jetty.plus.jaas.spi;
|
|||
|
||||
import java.security.Principal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.security.auth.Subject;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
|
@ -46,7 +45,7 @@ public class PropertyFileLoginModule extends AbstractLoginModule
|
|||
|
||||
private static final Logger LOG = Log.getLogger(PropertyFileLoginModule.class);
|
||||
|
||||
private static Map<String, PropertyUserStore> _propertyUserStores = new HashMap<String, PropertyUserStore>();
|
||||
private static ConcurrentHashMap<String, PropertyUserStore> _propertyUserStores = new ConcurrentHashMap<String, PropertyUserStore>();
|
||||
|
||||
private int _refreshInterval = 0;
|
||||
private String _filename = DEFAULT_FILENAME;
|
||||
|
@ -69,31 +68,35 @@ public class PropertyFileLoginModule extends AbstractLoginModule
|
|||
|
||||
private void setupPropertyUserStore(Map<String, ?> options)
|
||||
{
|
||||
parseConfig(options);
|
||||
|
||||
if (_propertyUserStores.get(_filename) == null)
|
||||
{
|
||||
parseConfig(options);
|
||||
PropertyUserStore propertyUserStore = new PropertyUserStore();
|
||||
propertyUserStore.setConfig(_filename);
|
||||
propertyUserStore.setRefreshInterval(_refreshInterval);
|
||||
|
||||
PropertyUserStore _propertyUserStore = new PropertyUserStore();
|
||||
_propertyUserStore.setConfig(_filename);
|
||||
_propertyUserStore.setRefreshInterval(_refreshInterval);
|
||||
LOG.debug("setupPropertyUserStore: Starting new PropertyUserStore. PropertiesFile: " + _filename + " refreshInterval: " + _refreshInterval);
|
||||
|
||||
try
|
||||
PropertyUserStore prev = _propertyUserStores.putIfAbsent(_filename, propertyUserStore);
|
||||
if (prev == null)
|
||||
{
|
||||
_propertyUserStore.start();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Exception while starting propertyUserStore: ",e);
|
||||
}
|
||||
LOG.debug("setupPropertyUserStore: Starting new PropertyUserStore. PropertiesFile: " + _filename + " refreshInterval: " + _refreshInterval);
|
||||
|
||||
_propertyUserStores.put(_filename,_propertyUserStore);
|
||||
try
|
||||
{
|
||||
propertyUserStore.start();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Exception while starting propertyUserStore: ",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseConfig(Map<String, ?> options)
|
||||
{
|
||||
_filename = (String)options.get("file") != null?(String)options.get("file"):DEFAULT_FILENAME;
|
||||
_filename = (String)options.get("file");
|
||||
_filename = (_filename == null? DEFAULT_FILENAME : _filename);
|
||||
String refreshIntervalString = (String)options.get("refreshInterval");
|
||||
_refreshInterval = refreshIntervalString == null?_refreshInterval:Integer.parseInt(refreshIntervalString);
|
||||
}
|
||||
|
|
|
@ -23,11 +23,13 @@ import java.io.PrintWriter;
|
|||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.SessionTrackingMode;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
@ -213,7 +215,7 @@ public class Response implements HttpServletResponse
|
|||
return null;
|
||||
|
||||
// should not encode if cookies in evidence
|
||||
if (request.isRequestedSessionIdFromCookie())
|
||||
if ((sessionManager.isUsingCookies() && request.isRequestedSessionIdFromCookie()) || !sessionManager.isUsingURLs())
|
||||
{
|
||||
int prefix=url.indexOf(sessionURLPrefix);
|
||||
if (prefix!=-1)
|
||||
|
|
|
@ -1579,7 +1579,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
|||
{
|
||||
path = URIUtil.canonicalPath(path);
|
||||
Resource resource = _baseResource.addPath(path);
|
||||
|
||||
|
||||
// Is the resource aliased?
|
||||
if (!_aliases && resource.getAlias() != null)
|
||||
{
|
||||
|
@ -2474,7 +2474,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -2498,8 +2497,13 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
|||
* Eg. a symbolic link from /foobar.html to /somewhere/wibble.html would be
|
||||
* approved because both the resource and alias end with ".html".
|
||||
*/
|
||||
@Deprecated
|
||||
public static class ApproveSameSuffixAliases implements AliasCheck
|
||||
{
|
||||
{
|
||||
LOG.warn("ApproveSameSuffixAlias is not safe for production");
|
||||
}
|
||||
|
||||
public boolean check(String path, Resource resource)
|
||||
{
|
||||
int dot = path.lastIndexOf('.');
|
||||
|
@ -2516,8 +2520,13 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
|||
* Eg. a symbolic link from /dirA/foobar.html to /dirB/foobar.html would be
|
||||
* approved because both the resource and alias end with "/foobar.html".
|
||||
*/
|
||||
@Deprecated
|
||||
public static class ApprovePathPrefixAliases implements AliasCheck
|
||||
{
|
||||
{
|
||||
LOG.warn("ApprovePathPrefixAliases is not safe for production");
|
||||
}
|
||||
|
||||
public boolean check(String path, Resource resource)
|
||||
{
|
||||
int slash = path.lastIndexOf('/');
|
||||
|
@ -2527,6 +2536,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
|||
return resource.toString().endsWith(suffix);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Approve Aliases of a non existent directory.
|
||||
* If a directory "/foobar/" does not exist, then the resource is
|
||||
|
@ -2536,11 +2546,17 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
|||
{
|
||||
public boolean check(String path, Resource resource)
|
||||
{
|
||||
int slash = path.lastIndexOf('/');
|
||||
if (slash<0 || resource.exists())
|
||||
if (resource.exists())
|
||||
return false;
|
||||
String suffix=path.substring(slash);
|
||||
return resource.getAlias().toString().endsWith(suffix);
|
||||
|
||||
String a=resource.getAlias().toString();
|
||||
String r=resource.getURL().toString();
|
||||
|
||||
if (a.length()>r.length())
|
||||
return a.startsWith(r) && a.length()==r.length()+1 && a.endsWith("/");
|
||||
else
|
||||
return r.startsWith(a) && r.length()==a.length()+1 && r.endsWith("/");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,25 +69,28 @@ public class RequestLogHandler extends HandlerWrapper
|
|||
}
|
||||
finally
|
||||
{
|
||||
if (continuation.isAsync())
|
||||
if (_requestLog != null && baseRequest.getDispatcherType().equals(DispatcherType.REQUEST))
|
||||
{
|
||||
if (continuation.isInitial())
|
||||
continuation.addContinuationListener(new ContinuationListener()
|
||||
{
|
||||
|
||||
public void onTimeout(Continuation continuation)
|
||||
if (continuation.isAsync())
|
||||
{
|
||||
if (continuation.isInitial())
|
||||
continuation.addContinuationListener(new ContinuationListener()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void onComplete(Continuation continuation)
|
||||
{
|
||||
_requestLog.log(baseRequest, (Response)response);
|
||||
}
|
||||
});
|
||||
|
||||
public void onTimeout(Continuation continuation)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void onComplete(Continuation continuation)
|
||||
{
|
||||
_requestLog.log(baseRequest, (Response)response);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
_requestLog.log(baseRequest, (Response)response);
|
||||
}
|
||||
else
|
||||
_requestLog.log(baseRequest, (Response)response);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -757,7 +757,39 @@ public class MultipartFilterTest
|
|||
assertTrue(response.getContent().contains("aaaa,bbbbb"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBufferOverflowNoCRLF () throws Exception
|
||||
{
|
||||
String boundary="XyXyXy";
|
||||
// generated and parsed test
|
||||
HttpTester request = new HttpTester();
|
||||
HttpTester response = new HttpTester();
|
||||
tester.addServlet(BoundaryServlet.class,"/testb");
|
||||
tester.setAttribute("fileName", "abc");
|
||||
tester.setAttribute("desc", "123");
|
||||
tester.setAttribute("title", "ttt");
|
||||
request.setMethod("POST");
|
||||
request.setVersion("HTTP/1.0");
|
||||
request.setHeader("Host","tester");
|
||||
request.setURI("/context/testb");
|
||||
request.setHeader("Content-Type","multipart/form-data; boundary="+boundary);
|
||||
|
||||
String content = "--XyXyXy";
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
baos.write(content.getBytes());
|
||||
|
||||
for (int i=0; i< 8500; i++) //create content that will overrun default buffer size of BufferedInputStream
|
||||
{
|
||||
baos.write('a');
|
||||
}
|
||||
request.setContent(baos.toString());
|
||||
|
||||
response.parse(tester.getResponses(request.generate()));
|
||||
assertTrue(response.getContent().contains("Buffer size exceeded"));
|
||||
assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, response.getStatus());
|
||||
}
|
||||
|
||||
/*
|
||||
* see the testParameterMap test
|
||||
*
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
<version>8.1.13-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spdy-core</artifactId>
|
||||
<name>Jetty :: SPDY :: Core</name>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spdy-core</artifactId>
|
||||
<name>Jetty :: SPDY :: Core</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -16,21 +16,21 @@
|
|||
<artifactId>jetty-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
|
|
|
@ -64,13 +64,13 @@
|
|||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
|
|
|
@ -486,7 +486,16 @@ public class MultiPartInputStream
|
|||
byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
|
||||
|
||||
// Get first boundary
|
||||
String line=((ReadLineInputStream)_in).readLine();
|
||||
String line = null;
|
||||
try
|
||||
{
|
||||
line=((ReadLineInputStream)_in).readLine();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOG.warn("Badly formatted multipart request");
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (line == null)
|
||||
throw new IOException("Missing content for multipart request");
|
||||
|
@ -723,7 +732,6 @@ public class MultiPartInputStream
|
|||
}
|
||||
finally
|
||||
{
|
||||
|
||||
part.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,10 @@ public class ReadLineInputStream extends BufferedInputStream
|
|||
while (true)
|
||||
{
|
||||
int b=super.read();
|
||||
|
||||
if (markpos < 0)
|
||||
throw new IOException("Buffer size exceeded: no line terminator");
|
||||
|
||||
if (b==-1)
|
||||
{
|
||||
int m=markpos;
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* This class can check for aliasing in the filesystem (eg case
|
||||
* insensitivity). By default this is turned on, or it can be controlled
|
||||
* by calling the static method @see FileResource#setCheckAliases(boolean)
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class FileResource extends URLResource
|
||||
|
@ -167,15 +166,16 @@ public class FileResource extends URLResource
|
|||
r=(URLResource)Resource.newResource(url);
|
||||
}
|
||||
|
||||
// Check for encoding aliases
|
||||
// The encoded path should be a suffix of the resource (give or take a directory / )
|
||||
String encoded=URIUtil.encodePath(path);
|
||||
int expected=r.toString().length()-encoded.length();
|
||||
int index = r._urlString.lastIndexOf(encoded, expected);
|
||||
|
||||
if (expected!=index && ((expected-1)!=index || path.endsWith("/") || !r.isDirectory()))
|
||||
{
|
||||
if (!(r instanceof BadResource))
|
||||
if (r instanceof FileResource)
|
||||
{
|
||||
((FileResource)r)._alias=new URL(url);
|
||||
((FileResource)r)._alias=((FileResource)r)._file.getCanonicalFile().toURI().toURL();
|
||||
((FileResource)r)._aliasChecked=true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -521,7 +521,35 @@ public class MultiPartInputStreamTest extends TestCase
|
|||
assertThat(baos.toString("UTF-8"), is("Other"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testBufferOverflowNoCRLF () throws Exception
|
||||
{
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
baos.write("--AaB03x".getBytes());
|
||||
for (int i=0; i< 8500; i++) //create content that will overrun default buffer size of BufferedInputStream
|
||||
{
|
||||
baos.write('a');
|
||||
}
|
||||
|
||||
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||
MultiPartInputStream mpis = new MultiPartInputStream(new ByteArrayInputStream(baos.toByteArray()),
|
||||
_contentType,
|
||||
config,
|
||||
_tmpDir);
|
||||
mpis.setDeleteOnExit(true);
|
||||
try
|
||||
{
|
||||
mpis.getParts();
|
||||
fail ("Multipart buffer overrun");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
assertTrue(e.getMessage().startsWith("Buffer size exceeded"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testCharsetEncoding () throws Exception
|
||||
{
|
||||
String contentType = "multipart/form-data; boundary=TheBoundary; charset=ISO-8859-1";
|
||||
|
|
|
@ -329,7 +329,9 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
if (jsp_file != null)
|
||||
{
|
||||
holder.setForcedPath(jsp_file);
|
||||
holder.setClassName(jspServletClass); //only use our default instance
|
||||
ServletHolder jsp=context.getServletHandler().getServlet("jsp");
|
||||
if (jsp!=null)
|
||||
holder.setClassName(jsp.getClassName());
|
||||
}
|
||||
|
||||
// handle load-on-startup
|
||||
|
@ -673,16 +675,43 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
|||
// <tracking-mode>
|
||||
// this is additive across web-fragments
|
||||
Iterator iter = node.iterator("tracking-mode");
|
||||
Set<SessionTrackingMode> modes = new HashSet<SessionTrackingMode>();
|
||||
modes.addAll(context.getSessionHandler().getSessionManager().getEffectiveSessionTrackingModes());
|
||||
while (iter.hasNext())
|
||||
{
|
||||
XmlParser.Node mNode = (XmlParser.Node) iter.next();
|
||||
String trackMode = mNode.toString(false, true);
|
||||
modes.add(SessionTrackingMode.valueOf(trackMode));
|
||||
if (iter.hasNext())
|
||||
{
|
||||
Set<SessionTrackingMode> modes = null;
|
||||
Origin o = context.getMetaData().getOrigin("session.tracking-mode");
|
||||
switch (o)
|
||||
{
|
||||
case NotSet://not previously set, starting fresh
|
||||
case WebDefaults://previously set in web defaults, allow this descriptor to start fresh
|
||||
{
|
||||
|
||||
modes = new HashSet<SessionTrackingMode>();
|
||||
context.getMetaData().setOrigin("session.tracking-mode", descriptor);
|
||||
break;
|
||||
}
|
||||
case WebXml:
|
||||
case WebFragment:
|
||||
case WebOverride:
|
||||
{
|
||||
//if setting from an override descriptor, start afresh, otherwise add-in tracking-modes
|
||||
if (descriptor instanceof OverrideDescriptor)
|
||||
modes = new HashSet<SessionTrackingMode>();
|
||||
else
|
||||
modes = new HashSet<SessionTrackingMode>(context.getSessionHandler().getSessionManager().getEffectiveSessionTrackingModes());
|
||||
context.getMetaData().setOrigin("session.tracking-mode", descriptor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
XmlParser.Node mNode = (XmlParser.Node) iter.next();
|
||||
String trackMode = mNode.toString(false, true);
|
||||
modes.add(SessionTrackingMode.valueOf(trackMode));
|
||||
}
|
||||
context.getSessionHandler().getSessionManager().setSessionTrackingModes(modes);
|
||||
}
|
||||
context.getSessionHandler().getSessionManager().setSessionTrackingModes(modes);
|
||||
|
||||
|
||||
|
||||
//Servlet Spec 3.0
|
||||
//<cookie-config>
|
||||
|
|
|
@ -87,7 +87,10 @@ public class WebInfConfiguration extends AbstractConfiguration
|
|||
context.getMetaData().addContainerJar(Resource.newResource(uri));
|
||||
}
|
||||
};
|
||||
ClassLoader loader = context.getClassLoader();
|
||||
ClassLoader loader = null;
|
||||
if (context.getClassLoader() != null)
|
||||
loader = context.getClassLoader().getParent();
|
||||
|
||||
while (loader != null && (loader instanceof URLClassLoader))
|
||||
{
|
||||
URL[] urls = ((URLClassLoader)loader).getURLs();
|
||||
|
|
|
@ -19,14 +19,16 @@
|
|||
package org.eclipse.jetty.websocket;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.eclipse.jetty.io.Buffer;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.io.EofException;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** WebSocketGenerator.
|
||||
/**
|
||||
* WebSocketGenerator.
|
||||
* This class generates websocket packets.
|
||||
* It is fully synchronized because it is likely that async
|
||||
* threads will call the addMessage methods while other
|
||||
|
@ -34,214 +36,263 @@ import org.eclipse.jetty.io.EofException;
|
|||
*/
|
||||
public class WebSocketGeneratorRFC6455 implements WebSocketGenerator
|
||||
{
|
||||
final private WebSocketBuffers _buffers;
|
||||
final private EndPoint _endp;
|
||||
private final Lock _lock = new ReentrantLock();
|
||||
private final WebSocketBuffers _buffers;
|
||||
private final EndPoint _endp;
|
||||
private final byte[] _mask = new byte[4];
|
||||
private final MaskGen _maskGen;
|
||||
private Buffer _buffer;
|
||||
private final byte[] _mask=new byte[4];
|
||||
private int _m;
|
||||
private boolean _opsent;
|
||||
private final MaskGen _maskGen;
|
||||
private boolean _closed;
|
||||
|
||||
public WebSocketGeneratorRFC6455(WebSocketBuffers buffers, EndPoint endp)
|
||||
{
|
||||
_buffers=buffers;
|
||||
_endp=endp;
|
||||
_maskGen=null;
|
||||
this(buffers, endp, null);
|
||||
}
|
||||
|
||||
public WebSocketGeneratorRFC6455(WebSocketBuffers buffers, EndPoint endp, MaskGen maskGen)
|
||||
{
|
||||
_buffers=buffers;
|
||||
_endp=endp;
|
||||
_maskGen=maskGen;
|
||||
_buffers = buffers;
|
||||
_endp = endp;
|
||||
_maskGen = maskGen;
|
||||
}
|
||||
|
||||
public synchronized Buffer getBuffer()
|
||||
public Buffer getBuffer()
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
public synchronized void addFrame(byte flags, byte opcode, byte[] content, int offset, int length) throws IOException
|
||||
{
|
||||
// System.err.printf("<< %s %s %s\n",TypeUtil.toHexString(flags),TypeUtil.toHexString(opcode),length);
|
||||
|
||||
if (_closed)
|
||||
throw new EofException("Closed");
|
||||
if (opcode==WebSocketConnectionRFC6455.OP_CLOSE)
|
||||
_closed=true;
|
||||
|
||||
boolean mask=_maskGen!=null;
|
||||
|
||||
if (_buffer==null)
|
||||
_buffer=mask?_buffers.getBuffer():_buffers.getDirectBuffer();
|
||||
|
||||
boolean last=WebSocketConnectionRFC6455.isLastFrame(flags);
|
||||
|
||||
int space=mask?14:10;
|
||||
|
||||
do
|
||||
_lock.lock();
|
||||
try
|
||||
{
|
||||
opcode = _opsent?WebSocketConnectionRFC6455.OP_CONTINUATION:opcode;
|
||||
opcode=(byte)(((0xf&flags)<<4)+(0xf&opcode));
|
||||
_opsent=true;
|
||||
return _buffer;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
int payload=length;
|
||||
if (payload+space>_buffer.capacity())
|
||||
{
|
||||
// We must fragement, so clear FIN bit
|
||||
opcode=(byte)(opcode&0x7F); // Clear the FIN bit
|
||||
payload=_buffer.capacity()-space;
|
||||
}
|
||||
else if (last)
|
||||
opcode= (byte)(opcode|0x80); // Set the FIN bit
|
||||
public void addFrame(byte flags, byte opcode, byte[] content, int offset, int length) throws IOException
|
||||
{
|
||||
_lock.lock();
|
||||
try
|
||||
{
|
||||
if (_closed)
|
||||
throw new EofException("Closed");
|
||||
if (opcode == WebSocketConnectionRFC6455.OP_CLOSE)
|
||||
_closed = true;
|
||||
|
||||
// ensure there is space for header
|
||||
if (_buffer.space() <= space)
|
||||
boolean mask = _maskGen != null;
|
||||
|
||||
if (_buffer == null)
|
||||
_buffer = mask ? _buffers.getBuffer() : _buffers.getDirectBuffer();
|
||||
|
||||
boolean last = WebSocketConnectionRFC6455.isLastFrame(flags);
|
||||
|
||||
int space = mask ? 14 : 10;
|
||||
|
||||
do
|
||||
{
|
||||
flushBuffer();
|
||||
opcode = _opsent ? WebSocketConnectionRFC6455.OP_CONTINUATION : opcode;
|
||||
opcode = (byte)(((0xf & flags) << 4) + (0xf & opcode));
|
||||
_opsent = true;
|
||||
|
||||
int payload = length;
|
||||
if (payload + space > _buffer.capacity())
|
||||
{
|
||||
// We must fragement, so clear FIN bit
|
||||
opcode = (byte)(opcode & 0x7F); // Clear the FIN bit
|
||||
payload = _buffer.capacity() - space;
|
||||
}
|
||||
else if (last)
|
||||
opcode = (byte)(opcode | 0x80); // Set the FIN bit
|
||||
|
||||
// ensure there is space for header
|
||||
if (_buffer.space() <= space)
|
||||
flush();
|
||||
}
|
||||
{
|
||||
flushBuffer();
|
||||
if (_buffer.space() <= space)
|
||||
flush();
|
||||
}
|
||||
|
||||
// write the opcode and length
|
||||
if (payload>0xffff)
|
||||
{
|
||||
_buffer.put(new byte[]{
|
||||
opcode,
|
||||
mask?(byte)0xff:(byte)0x7f,
|
||||
(byte)0,
|
||||
(byte)0,
|
||||
(byte)0,
|
||||
(byte)0,
|
||||
(byte)((payload>>24)&0xff),
|
||||
(byte)((payload>>16)&0xff),
|
||||
(byte)((payload>>8)&0xff),
|
||||
(byte)(payload&0xff)});
|
||||
}
|
||||
else if (payload >=0x7e)
|
||||
{
|
||||
_buffer.put(new byte[]{
|
||||
opcode,
|
||||
mask?(byte)0xfe:(byte)0x7e,
|
||||
(byte)(payload>>8),
|
||||
(byte)(payload&0xff)});
|
||||
}
|
||||
else
|
||||
{
|
||||
_buffer.put(new byte[]{
|
||||
opcode,
|
||||
(byte)(mask?(0x80|payload):payload)});
|
||||
}
|
||||
|
||||
// write mask
|
||||
if (mask)
|
||||
{
|
||||
_maskGen.genMask(_mask);
|
||||
_m=0;
|
||||
_buffer.put(_mask);
|
||||
}
|
||||
|
||||
// write payload
|
||||
int remaining = payload;
|
||||
while (remaining > 0)
|
||||
{
|
||||
_buffer.compact();
|
||||
int chunk = remaining < _buffer.space() ? remaining : _buffer.space();
|
||||
// write the opcode and length
|
||||
if (payload > 0xffff)
|
||||
{
|
||||
_buffer.put(new byte[]{
|
||||
opcode,
|
||||
mask ? (byte)0xff : (byte)0x7f,
|
||||
(byte)0,
|
||||
(byte)0,
|
||||
(byte)0,
|
||||
(byte)0,
|
||||
(byte)((payload >> 24) & 0xff),
|
||||
(byte)((payload >> 16) & 0xff),
|
||||
(byte)((payload >> 8) & 0xff),
|
||||
(byte)(payload & 0xff)});
|
||||
}
|
||||
else if (payload >= 0x7e)
|
||||
{
|
||||
_buffer.put(new byte[]{
|
||||
opcode,
|
||||
mask ? (byte)0xfe : (byte)0x7e,
|
||||
(byte)(payload >> 8),
|
||||
(byte)(payload & 0xff)});
|
||||
}
|
||||
else
|
||||
{
|
||||
_buffer.put(new byte[]{
|
||||
opcode,
|
||||
(byte)(mask ? (0x80 | payload) : payload)});
|
||||
}
|
||||
|
||||
// write mask
|
||||
if (mask)
|
||||
{
|
||||
for (int i=0;i<chunk;i++)
|
||||
_buffer.put((byte)(content[offset+ (payload-remaining)+i]^_mask[+_m++%4]));
|
||||
_maskGen.genMask(_mask);
|
||||
_m = 0;
|
||||
_buffer.put(_mask);
|
||||
}
|
||||
else
|
||||
_buffer.put(content, offset + (payload - remaining), chunk);
|
||||
|
||||
remaining -= chunk;
|
||||
if (_buffer.space() > 0)
|
||||
// write payload
|
||||
int remaining = payload;
|
||||
while (remaining > 0)
|
||||
{
|
||||
// Gently flush the data, issuing a non-blocking write
|
||||
flushBuffer();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Forcibly flush the data, issuing a blocking write
|
||||
flush();
|
||||
if (remaining == 0)
|
||||
_buffer.compact();
|
||||
int chunk = remaining < _buffer.space() ? remaining : _buffer.space();
|
||||
|
||||
if (mask)
|
||||
{
|
||||
for (int i = 0; i < chunk; i++)
|
||||
_buffer.put((byte)(content[offset + (payload - remaining) + i] ^ _mask[+_m++ % 4]));
|
||||
}
|
||||
else
|
||||
_buffer.put(content, offset + (payload - remaining), chunk);
|
||||
|
||||
remaining -= chunk;
|
||||
if (_buffer.space() > 0)
|
||||
{
|
||||
// Gently flush the data, issuing a non-blocking write
|
||||
flushBuffer();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Forcibly flush the data, issuing a blocking write
|
||||
flush();
|
||||
if (remaining == 0)
|
||||
{
|
||||
// Gently flush the data, issuing a non-blocking write
|
||||
flushBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
offset += payload;
|
||||
length -= payload;
|
||||
}
|
||||
offset+=payload;
|
||||
length-=payload;
|
||||
}
|
||||
while (length>0);
|
||||
_opsent=!last;
|
||||
while (length > 0);
|
||||
_opsent = !last;
|
||||
|
||||
if (_buffer!=null && _buffer.length()==0)
|
||||
{
|
||||
_buffers.returnBuffer(_buffer);
|
||||
_buffer=null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized int flushBuffer() throws IOException
|
||||
{
|
||||
if (!_endp.isOpen())
|
||||
throw new EofException();
|
||||
|
||||
if (_buffer!=null)
|
||||
{
|
||||
int flushed=_buffer.hasContent()?_endp.flush(_buffer):0;
|
||||
if (_closed&&_buffer.length()==0)
|
||||
_endp.shutdownOutput();
|
||||
return flushed;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public synchronized int flush() throws IOException
|
||||
{
|
||||
if (_buffer==null)
|
||||
return 0;
|
||||
int result = flushBuffer();
|
||||
|
||||
if (!_endp.isBlocking())
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
long end=now+_endp.getMaxIdleTime();
|
||||
while (_buffer.length()>0)
|
||||
if (_buffer != null && _buffer.length() == 0)
|
||||
{
|
||||
boolean ready = _endp.blockWritable(end-now);
|
||||
if (!ready)
|
||||
{
|
||||
now = System.currentTimeMillis();
|
||||
if (now<end)
|
||||
continue;
|
||||
throw new IOException("Write timeout");
|
||||
}
|
||||
|
||||
result += flushBuffer();
|
||||
_buffers.returnBuffer(_buffer);
|
||||
_buffer = null;
|
||||
}
|
||||
}
|
||||
_buffer.compact();
|
||||
return result;
|
||||
}
|
||||
|
||||
public synchronized boolean isBufferEmpty()
|
||||
{
|
||||
return _buffer==null || _buffer.length()==0;
|
||||
}
|
||||
|
||||
public synchronized void returnBuffer()
|
||||
{
|
||||
if (_buffer!=null && _buffer.length()==0)
|
||||
finally
|
||||
{
|
||||
_buffers.returnBuffer(_buffer);
|
||||
_buffer=null;
|
||||
_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public int flushBuffer() throws IOException
|
||||
{
|
||||
if (!_lock.tryLock())
|
||||
return 0;
|
||||
|
||||
try
|
||||
{
|
||||
if (!_endp.isOpen())
|
||||
throw new EofException();
|
||||
|
||||
if (_buffer != null)
|
||||
{
|
||||
int flushed = _buffer.hasContent() ? _endp.flush(_buffer) : 0;
|
||||
if (_closed && _buffer.length() == 0)
|
||||
_endp.shutdownOutput();
|
||||
return flushed;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public int flush() throws IOException
|
||||
{
|
||||
if (!_lock.tryLock())
|
||||
return 0;
|
||||
|
||||
try
|
||||
{
|
||||
if (_buffer == null)
|
||||
return 0;
|
||||
|
||||
int result = flushBuffer();
|
||||
if (!_endp.isBlocking())
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
long end = now + _endp.getMaxIdleTime();
|
||||
while (_buffer.length() > 0)
|
||||
{
|
||||
boolean ready = _endp.blockWritable(end - now);
|
||||
if (!ready)
|
||||
{
|
||||
now = System.currentTimeMillis();
|
||||
if (now < end)
|
||||
continue;
|
||||
throw new IOException("Write timeout");
|
||||
}
|
||||
|
||||
result += flushBuffer();
|
||||
}
|
||||
}
|
||||
_buffer.compact();
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBufferEmpty()
|
||||
{
|
||||
_lock.lock();
|
||||
try
|
||||
{
|
||||
return _buffer == null || _buffer.length() == 0;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void returnBuffer()
|
||||
{
|
||||
_lock.lock();
|
||||
try
|
||||
{
|
||||
if (_buffer != null && _buffer.length() == 0)
|
||||
{
|
||||
_buffers.returnBuffer(_buffer);
|
||||
_buffer = null;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.eclipse.jetty.xml;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A ConfigurationProcessor for non XmlConfiguration format files.
|
||||
|
@ -32,7 +31,7 @@ import java.util.Map;
|
|||
*/
|
||||
public interface ConfigurationProcessor
|
||||
{
|
||||
public void init(URL url, XmlParser.Node config, Map<String, Object> idMap, Map<String, String> properties);
|
||||
public void init(URL url, XmlParser.Node root, XmlConfiguration configuration);
|
||||
|
||||
public Object configure( Object obj) throws Exception;
|
||||
public Object configure() throws Exception;
|
||||
|
|
|
@ -227,7 +227,7 @@ public class XmlConfiguration
|
|||
{
|
||||
throw new IllegalArgumentException("Unknown XML tag:"+config.getTag());
|
||||
}
|
||||
_processor.init(_url,config,_idMap, _propertyMap);
|
||||
_processor.init(_url,config,this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -295,52 +295,64 @@ public class XmlConfiguration
|
|||
{
|
||||
return _processor.configure();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Initialize a new Object defaults.
|
||||
* <p>This method must be called by any {@link ConfigurationProcessor} when it
|
||||
* creates a new instance of an object before configuring it, so that a derived
|
||||
* XmlConfiguration class may inject default values.
|
||||
* @param object
|
||||
*/
|
||||
public void initializeDefaults(Object object)
|
||||
{
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
private static class JettyXmlConfiguration implements ConfigurationProcessor
|
||||
{
|
||||
XmlParser.Node _config;
|
||||
Map<String, Object> _idMap;
|
||||
Map<String, String> _propertyMap;
|
||||
XmlParser.Node _root;
|
||||
XmlConfiguration _configuration;
|
||||
|
||||
public void init(URL url, XmlParser.Node config, Map<String, Object> idMap, Map<String, String> properties)
|
||||
public void init(URL url, XmlParser.Node root, XmlConfiguration configuration)
|
||||
{
|
||||
_config=config;
|
||||
_idMap=idMap;
|
||||
_propertyMap=properties;
|
||||
_root=root;
|
||||
_configuration=configuration;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Object configure(Object obj) throws Exception
|
||||
{
|
||||
// Check the class of the object
|
||||
Class<?> oClass = nodeClass(_config);
|
||||
Class<?> oClass = nodeClass(_root);
|
||||
if (oClass != null && !oClass.isInstance(obj))
|
||||
{
|
||||
String loaders = (oClass.getClassLoader()==obj.getClass().getClassLoader())?"":"Object Class and type Class are from different loaders.";
|
||||
throw new IllegalArgumentException("Object of class '"+obj.getClass().getCanonicalName()+"' is not of type '" + oClass.getCanonicalName()+"'. "+loaders);
|
||||
}
|
||||
configure(obj,_config,0);
|
||||
configure(obj,_root,0);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Object configure() throws Exception
|
||||
{
|
||||
Class<?> oClass = nodeClass(_config);
|
||||
Class<?> oClass = nodeClass(_root);
|
||||
|
||||
String id = _config.getAttribute("id");
|
||||
Object obj = id == null?null:_idMap.get(id);
|
||||
String id = _root.getAttribute("id");
|
||||
Object obj = id == null?null:_configuration.getIdMap().get(id);
|
||||
|
||||
if (obj == null && oClass != null)
|
||||
{
|
||||
obj = oClass.newInstance();
|
||||
_configuration.initializeDefaults(obj);
|
||||
}
|
||||
|
||||
if (oClass != null && !oClass.isInstance(obj))
|
||||
throw new ClassCastException(oClass.toString());
|
||||
|
||||
configure(obj,_config,0);
|
||||
configure(obj,_root,0);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -368,7 +380,7 @@ public class XmlConfiguration
|
|||
{
|
||||
String id = cfg.getAttribute("id");
|
||||
if (id != null)
|
||||
_idMap.put(id,obj);
|
||||
_configuration.getIdMap().put(id,obj);
|
||||
|
||||
for (; i < cfg.size(); i++)
|
||||
{
|
||||
|
@ -558,6 +570,7 @@ public class XmlConfiguration
|
|||
}
|
||||
Constructor<?> cons = sClass.getConstructor(vClass);
|
||||
arg[0] = cons.newInstance(arg);
|
||||
_configuration.initializeDefaults(arg[0]);
|
||||
set.invoke(obj,arg);
|
||||
return;
|
||||
}
|
||||
|
@ -675,7 +688,7 @@ public class XmlConfiguration
|
|||
}
|
||||
}
|
||||
if (id != null)
|
||||
_idMap.put(id,obj);
|
||||
_configuration.getIdMap().put(id,obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -730,7 +743,7 @@ public class XmlConfiguration
|
|||
{
|
||||
Object n= TypeUtil.call(oClass,method,obj,arg);
|
||||
if (id != null)
|
||||
_idMap.put(id,n);
|
||||
_configuration.getIdMap().put(id,n);
|
||||
configure(n,node,argi);
|
||||
return n;
|
||||
}
|
||||
|
@ -792,6 +805,7 @@ public class XmlConfiguration
|
|||
try
|
||||
{
|
||||
n = constructors[c].newInstance(arg);
|
||||
_configuration.initializeDefaults(n);
|
||||
called = true;
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
|
@ -809,7 +823,7 @@ public class XmlConfiguration
|
|||
if (called)
|
||||
{
|
||||
if (id != null)
|
||||
_idMap.put(id,n);
|
||||
_configuration.getIdMap().put(id,n);
|
||||
configure(n,node,argi);
|
||||
return n;
|
||||
}
|
||||
|
@ -827,7 +841,7 @@ public class XmlConfiguration
|
|||
private Object refObj(Object obj, XmlParser.Node node) throws Exception
|
||||
{
|
||||
String id = node.getAttribute("id");
|
||||
obj = _idMap.get(id);
|
||||
obj = _configuration.getIdMap().get(id);
|
||||
if (obj == null)
|
||||
throw new IllegalStateException("No object for id=" + id);
|
||||
configure(obj,node,0);
|
||||
|
@ -870,12 +884,12 @@ public class XmlConfiguration
|
|||
Object v = value(obj,item);
|
||||
al = LazyList.add(al,(v == null && aClass.isPrimitive())?0:v);
|
||||
if (nid != null)
|
||||
_idMap.put(nid,v);
|
||||
_configuration.getIdMap().put(nid,v);
|
||||
}
|
||||
|
||||
Object array = LazyList.toArray(al,aClass);
|
||||
if (id != null)
|
||||
_idMap.put(id,array);
|
||||
_configuration.getIdMap().put(id,array);
|
||||
return array;
|
||||
}
|
||||
|
||||
|
@ -889,7 +903,7 @@ public class XmlConfiguration
|
|||
|
||||
Map<Object, Object> map = new HashMap<Object, Object>();
|
||||
if (id != null)
|
||||
_idMap.put(id,map);
|
||||
_configuration.getIdMap().put(id,map);
|
||||
|
||||
for (Object o : node)
|
||||
{
|
||||
|
@ -925,9 +939,9 @@ public class XmlConfiguration
|
|||
map.put(k,v);
|
||||
|
||||
if (kid != null)
|
||||
_idMap.put(kid,k);
|
||||
_configuration.getIdMap().put(kid,k);
|
||||
if (vid != null)
|
||||
_idMap.put(vid,v);
|
||||
_configuration.getIdMap().put(vid,v);
|
||||
}
|
||||
|
||||
return map;
|
||||
|
@ -947,12 +961,13 @@ public class XmlConfiguration
|
|||
String name = node.getAttribute("name");
|
||||
String defaultValue = node.getAttribute("default");
|
||||
Object prop;
|
||||
if (_propertyMap != null && _propertyMap.containsKey(name))
|
||||
prop = _propertyMap.get(name);
|
||||
Map<String,String> property_map=_configuration.getProperties();
|
||||
if (property_map != null && property_map.containsKey(name))
|
||||
prop = property_map.get(name);
|
||||
else
|
||||
prop = defaultValue;
|
||||
if (id != null)
|
||||
_idMap.put(id,prop);
|
||||
_configuration.getIdMap().put(id,prop);
|
||||
if (prop != null)
|
||||
configure(prop,node,0);
|
||||
return prop;
|
||||
|
@ -975,7 +990,7 @@ public class XmlConfiguration
|
|||
String ref = node.getAttribute("ref");
|
||||
if (ref != null)
|
||||
{
|
||||
value = _idMap.get(ref);
|
||||
value = _configuration.getIdMap().get(ref);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -34,6 +34,7 @@ public class TestConfiguration extends HashMap<String,Object>
|
|||
public static int VALUE=77;
|
||||
|
||||
public TestConfiguration nested;
|
||||
public String testString="default";
|
||||
public Object testObject;
|
||||
public int testInt;
|
||||
public URL url;
|
||||
|
@ -65,6 +66,25 @@ public class TestConfiguration extends HashMap<String,Object>
|
|||
propValue=value;
|
||||
}
|
||||
|
||||
public TestConfiguration getNested()
|
||||
{
|
||||
return nested;
|
||||
}
|
||||
|
||||
public void setNested(TestConfiguration nested)
|
||||
{
|
||||
this.nested = nested;
|
||||
}
|
||||
|
||||
public String getTestString()
|
||||
{
|
||||
return testString;
|
||||
}
|
||||
|
||||
public void setTestString(String testString)
|
||||
{
|
||||
this.testString = testString;
|
||||
}
|
||||
|
||||
public void call()
|
||||
{
|
||||
|
@ -73,7 +93,6 @@ public class TestConfiguration extends HashMap<String,Object>
|
|||
|
||||
public TestConfiguration call(Boolean b)
|
||||
{
|
||||
nested=new TestConfiguration();
|
||||
nested.put("Arg",b);
|
||||
return nested;
|
||||
}
|
||||
|
|
|
@ -21,11 +21,12 @@ package org.eclipse.jetty.xml;
|
|||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
|
@ -127,10 +128,28 @@ public class XmlConfigurationTest
|
|||
properties.put("whatever", "xxx");
|
||||
|
||||
URL url = XmlConfigurationTest.class.getClassLoader().getResource(_configure);
|
||||
XmlConfiguration configuration = new XmlConfiguration(url);
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
XmlConfiguration configuration = new XmlConfiguration(url)
|
||||
{
|
||||
@Override
|
||||
public void initializeDefaults(Object object)
|
||||
{
|
||||
if (object instanceof TestConfiguration)
|
||||
{
|
||||
count.incrementAndGet();
|
||||
((TestConfiguration)object).setNested(null);
|
||||
((TestConfiguration)object).setTestString("NEW DEFAULT");
|
||||
}
|
||||
}
|
||||
};
|
||||
configuration.getProperties().putAll(properties);
|
||||
TestConfiguration tc = (TestConfiguration)configuration.configure();
|
||||
|
||||
assertEquals(3,count.get());
|
||||
assertEquals("NEW DEFAULT",tc.getTestString());
|
||||
assertEquals("nested",tc.getNested().getTestString());
|
||||
assertEquals("NEW DEFAULT",tc.getNested().getNested().getTestString());
|
||||
|
||||
assertEquals("Set String","SetValue",tc.testObject);
|
||||
assertEquals("Set Type",2,tc.testInt);
|
||||
|
||||
|
|
|
@ -83,6 +83,16 @@
|
|||
<Put name="Float" type="Float">2.3</Put>
|
||||
<Put name="Env"><Env name="HOME"/></Put>
|
||||
|
||||
<Set name="nested">
|
||||
<New class="org.eclipse.jetty.xml.TestConfiguration">
|
||||
<Set name="testString">nested</Set>
|
||||
<Set name="nested">
|
||||
<New class="org.eclipse.jetty.xml.TestConfiguration">
|
||||
</New>
|
||||
</Set>
|
||||
</New>
|
||||
</Set>
|
||||
|
||||
<Call name="call">
|
||||
</Call>
|
||||
|
||||
|
|
17
pom.xml
17
pom.xml
|
@ -510,7 +510,7 @@
|
|||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
@ -530,17 +530,22 @@
|
|||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<version>4.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.1</version>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>1.8.5</version>
|
||||
<version>1.9.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
|
|
@ -28,19 +28,6 @@ detected.
|
|||
<Set name="copyWebDir">false</Set>
|
||||
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
|
||||
<Set name="overrideDescriptor"><SystemProperty name="jetty.home" default="."/>/contexts/test.d/override-web.xml</Set>
|
||||
|
||||
<!-- Allow directory symbolic links -->
|
||||
<Call name="addAliasCheck">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.handler.ContextHandler$ApprovePathPrefixAliases"/>
|
||||
</Arg>
|
||||
</Call>
|
||||
<!-- Allow file symbolic links -->
|
||||
<Call name="addAliasCheck">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.handler.ContextHandler$ApproveSameSuffixAliases"/>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
<!-- virtual hosts
|
||||
<Set name="virtualHosts">
|
||||
|
|
|
@ -18,21 +18,18 @@
|
|||
|
||||
package org.eclipse.jetty.test.monitor;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
|
||||
import org.eclipse.jetty.client.ContentExchange;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.http.HttpMethods;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.monitor.JMXMonitor;
|
||||
import org.eclipse.jetty.toolchain.jmx.JmxServiceConnection;
|
||||
import org.eclipse.jetty.toolchain.test.JettyDistro;
|
||||
import org.eclipse.jetty.test.support.JettyDistro;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
|
|
@ -18,15 +18,13 @@
|
|||
|
||||
package org.eclipse.jetty.test.monitor;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.management.MBeanServerConnection;
|
||||
|
||||
import org.eclipse.jetty.client.ContentExchange;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.http.HttpMethods;
|
||||
|
@ -40,8 +38,7 @@ import org.eclipse.jetty.monitor.jmx.MonitorAction;
|
|||
import org.eclipse.jetty.monitor.triggers.GreaterThanAttrEventTrigger;
|
||||
import org.eclipse.jetty.monitor.triggers.LessThanOrEqualToAttrEventTrigger;
|
||||
import org.eclipse.jetty.monitor.triggers.OrEventTrigger;
|
||||
import org.eclipse.jetty.toolchain.jmx.JmxServiceConnection;
|
||||
import org.eclipse.jetty.toolchain.test.JettyDistro;
|
||||
import org.eclipse.jetty.test.support.JettyDistro;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.thread.ExecutorThreadPool;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
package org.eclipse.jetty.test.monitor;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
@ -30,7 +30,7 @@ import org.eclipse.jetty.client.HttpClient;
|
|||
import org.eclipse.jetty.http.HttpMethods;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.monitor.JMXMonitor;
|
||||
import org.eclipse.jetty.toolchain.test.JettyDistro;
|
||||
import org.eclipse.jetty.test.support.JettyDistro;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
|
|
@ -0,0 +1,874 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.support;
|
||||
//
|
||||
//========================================================================
|
||||
//------------------------------------------------------------------------
|
||||
//All rights reserved. This program and the accompanying materials
|
||||
//are made available under the terms of the Eclipse Public License v1.0
|
||||
//and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
//You may elect to redistribute this code under either of these licenses.
|
||||
//========================================================================
|
||||
//
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.IO;
|
||||
import org.eclipse.jetty.toolchain.test.JAR;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.toolchain.test.OS;
|
||||
import org.eclipse.jetty.toolchain.test.PathAssert;
|
||||
import org.eclipse.jetty.toolchain.test.TestingDir;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* Basic process based executor for using the Jetty Distribution along with custom configurations to perform basic
|
||||
* <p>
|
||||
* Allows for a test specific directory, that is a copied jetty-distribution, and then modified for the test specific testing required.
|
||||
* <p>
|
||||
* Requires that you setup the maven-dependency-plugin appropriately for the base distribution you want to use, along with any other dependencies (wars, libs,
|
||||
* etc..) that you may need from other maven projects.
|
||||
* <p>
|
||||
* Maven Dependency Plugin Setup:
|
||||
*
|
||||
* <pre>
|
||||
* <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
* xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
*
|
||||
* <!-- Common Destination Directories -->
|
||||
*
|
||||
* <properties>
|
||||
* <test-wars-dir>${project.build.directory}/test-wars</test-wars-dir>
|
||||
* <test-libs-dir>${project.build.directory}/test-libs</test-libs-dir>
|
||||
* <test-distro-dir>${project.build.directory}/test-dist</test-distro-dir>
|
||||
* </properties>
|
||||
*
|
||||
* <build>
|
||||
* <plugins>
|
||||
* <plugin>
|
||||
* <groupId>org.apache.maven.plugins</groupId>
|
||||
* <artifactId>maven-dependency-plugin</artifactId>
|
||||
* <version>2.1</version>
|
||||
* <executions>
|
||||
*
|
||||
* <!-- Copy LIB and WAR dependencies into place that JettyDistro can use them -->
|
||||
*
|
||||
* <execution>
|
||||
* <id>test-lib-war-copy</id>
|
||||
* <phase>process-test-resources</phase>
|
||||
* <goals>
|
||||
* <goal>copy</goal>
|
||||
* </goals>
|
||||
* <configuration>
|
||||
* <artifactItems>
|
||||
* <artifactItem>
|
||||
* <groupId>org.mortbay.jetty.testwars</groupId>
|
||||
* <artifactId>test-war-java_util_logging</artifactId>
|
||||
* <version>7.3.0</version>
|
||||
* <type>war</type>
|
||||
* <outputDirectory>${test-wars-dir}</outputDirectory>
|
||||
* </artifactItem>
|
||||
* <artifactItem>
|
||||
* <groupId>org.mortbay.jetty</groupId>
|
||||
* <artifactId>jetty-aspect-servlet-api-2.5</artifactId>
|
||||
* <version>7.3.0</version>
|
||||
* <type>jar</type>
|
||||
* <outputDirectory>${test-libs-dir}</outputDirectory>
|
||||
* </artifactItem>
|
||||
* </artifactItems>
|
||||
* <overWriteIfNewer>true</overWriteIfNewer>
|
||||
* <overWrite>true</overWrite>
|
||||
* <stripVersion>true</stripVersion>
|
||||
* </configuration>
|
||||
* </execution>
|
||||
*
|
||||
* <!-- Extract Jetty DISTRIBUTION into place that JettyDistro can use it -->
|
||||
*
|
||||
* <execution>
|
||||
* <id>unpack-test-dist</id>
|
||||
* <phase>process-test-resources</phase>
|
||||
* <goals>
|
||||
* <goal>unpack</goal>
|
||||
* </goals>
|
||||
* <configuration>
|
||||
* <artifactItems>
|
||||
* <artifactItem>
|
||||
* <groupId>org.eclipse.jetty</groupId>
|
||||
* <artifactId>jetty-distribution</artifactId>
|
||||
* <version>7.3.0</version>
|
||||
* <type>zip</type>
|
||||
* <overWrite>true</overWrite>
|
||||
* </artifactItem>
|
||||
* </artifactItems>
|
||||
* <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename>
|
||||
* <outputDirectory>${test-distro-dir}</outputDirectory>
|
||||
* <overWriteSnapshots>true</overWriteSnapshots>
|
||||
* <overWriteIfNewer>true</overWriteIfNewer>
|
||||
* </configuration>
|
||||
* </execution>
|
||||
* </executions>
|
||||
* </plugin>
|
||||
* </plugins>
|
||||
* </build>
|
||||
*
|
||||
* </project>
|
||||
* </pre>
|
||||
* <p>
|
||||
* If you have a specific configuration you want to setup, you'll want to prepare this configuration in an overlay directory underneath the
|
||||
* <code>src/test/resources/</code> directory. <br>
|
||||
* Notes:
|
||||
* <ol>
|
||||
* <li>The {@link JettyDistro} sets up a unique test directory (based on the constructor {@link #JettyDistro(Class)} or {@link #JettyDistro(TestingDir)}), by
|
||||
* ensuring the directory is empty, then copying the <code>target/test-dist</code> directory into this new testing directory prior to the test specific changes
|
||||
* to the configuration.<br>
|
||||
* Note: this testing directory is a complete jetty distribution, suitable for executing via the command line for additional testing needs.</li>
|
||||
* <li>The directory name you choose in <code>src/test/resources</code> will be the name you use in the {@link #overlayConfig(String)} method to provide
|
||||
* replacement configurations for the Jetty Distribution.</li>
|
||||
* <li>You'll want to {@link #delete(String)} any files and/or directories from the standard distribution prior to using the {@link #overlayConfig(String)}
|
||||
* method.</li>
|
||||
* <li>Use the {@link #copyLib(String, String)} method to copy JAR files from the <code>target/test-libs</code> directory (created and managed above using the
|
||||
* <code>maven-dependency-plugin</code>) to copy the lib into the test specific.</li>
|
||||
* <li>Use the {@link #copyTestWar(String)} method to copy WAR files from the <code>target/test-wars</code> directory (created and managed above using the
|
||||
* <code>maven-dependency-plugin</code>) to copy the WAR into the test specific directory.</li>
|
||||
* </ol>
|
||||
* <p>
|
||||
* Next you'll want to use Junit 4.8+ and the <code>@BeforeClass</code> and <code>@AfterClass</code> annotations to setup the <code>JettyDistro</code>
|
||||
* class for setting up your testing configuration.
|
||||
* <p>
|
||||
* Example Test Case using {@link JettyDistro} class
|
||||
*
|
||||
* <pre>
|
||||
* public class MySampleTest
|
||||
* {
|
||||
* private static JettyDistro jetty;
|
||||
*
|
||||
* @BeforeClass
|
||||
* public static void initJetty() throws Exception
|
||||
* {
|
||||
* jetty = new JettyDistro(MySampleTest.class);
|
||||
*
|
||||
* jetty.copyTestWar("test-war-java_util_logging.war");
|
||||
* jetty.copyTestWar("test-war-policy.war");
|
||||
*
|
||||
* jetty.delete("webapps/test.war");
|
||||
* jetty.delete("contexts/test.d");
|
||||
* jetty.delete("contexts/javadoc.xml");
|
||||
* jetty.delete("contexts/test.xml");
|
||||
*
|
||||
* jetty.overlayConfig("no_security");
|
||||
*
|
||||
* jetty.setDebug(true);
|
||||
*
|
||||
* jetty.start();
|
||||
* }
|
||||
*
|
||||
* @AfterClass
|
||||
* public static void shutdownJetty() throws Exception
|
||||
* {
|
||||
* if (jetty != null)
|
||||
* {
|
||||
* jetty.stop();
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @Test
|
||||
* public void testRequest() throws Exception
|
||||
* {
|
||||
* SimpleRequest request = new SimpleRequest(jetty.getBaseUri());
|
||||
* String path = "/test-war-policy/security/PRACTICAL/testFilsystem");
|
||||
* String response = request.getString(path);
|
||||
* Assert.assertEquals("Success", response);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public class JettyDistro
|
||||
{
|
||||
private String artifactName = "jetty-distribution";
|
||||
private long startTime = 60;
|
||||
private TimeUnit timeUnit = TimeUnit.SECONDS;
|
||||
|
||||
private File jettyHomeDir;
|
||||
private Process pid;
|
||||
private URI baseUri;
|
||||
|
||||
private String jmxUrl;
|
||||
|
||||
private boolean _debug = false;
|
||||
|
||||
/**
|
||||
* Setup the JettyHome as belonging in a testing directory associated with a testing clazz.
|
||||
*
|
||||
* @param clazz
|
||||
* the testing class using this JettyDistro
|
||||
* @throws IOException
|
||||
* if unable to copy unpacked distribution into place for the provided testing directory
|
||||
*/
|
||||
public JettyDistro(Class<?> clazz) throws IOException
|
||||
{
|
||||
this(clazz,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the JettyHome as belonging in a testing directory associated with a testing clazz.
|
||||
*
|
||||
* @param clazz
|
||||
* the testing class using this JettyDistro
|
||||
* @param artifact
|
||||
* name of jetty distribution artifact
|
||||
* @throws IOException
|
||||
* if unable to copy unpacked distribution into place for the provided testing directory
|
||||
*/
|
||||
public JettyDistro(Class<?> clazz, String artifact) throws IOException
|
||||
{
|
||||
this.jettyHomeDir = MavenTestingUtils.getTargetTestingDir(clazz,"jettyHome");
|
||||
if (artifact != null)
|
||||
{
|
||||
this.artifactName = artifact;
|
||||
}
|
||||
|
||||
copyBaseDistro();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the JettyHome as belonging to a specific testing method directory
|
||||
*
|
||||
* @param testdir
|
||||
* the testing directory to use as the JettyHome for this JettyDistro
|
||||
* @throws IOException
|
||||
* if unable to copy unpacked distribution into place for the provided testing directory
|
||||
*/
|
||||
public JettyDistro(TestingDir testdir) throws IOException
|
||||
{
|
||||
this.jettyHomeDir = testdir.getDir();
|
||||
copyBaseDistro();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the JettyHome as belonging to a specific testing method directory
|
||||
*
|
||||
* @param testdir
|
||||
* the testing directory to use as the JettyHome for this JettyDistro
|
||||
* @param artifact
|
||||
* name of jetty distribution artifact
|
||||
* @throws IOException
|
||||
* if unable to copy unpacked distribution into place for the provided testing directory
|
||||
*/
|
||||
public JettyDistro(TestingDir testdir, String artifact) throws IOException
|
||||
{
|
||||
this.jettyHomeDir = testdir.getDir();
|
||||
if (artifact != null)
|
||||
{
|
||||
this.artifactName = artifact;
|
||||
}
|
||||
|
||||
copyBaseDistro();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws IOException
|
||||
* if unable to copy unpacked distribution into place for the provided testing directory
|
||||
*/
|
||||
private void copyBaseDistro() throws IOException
|
||||
{
|
||||
// The outputDirectory for the maven side dependency:unpack goal.
|
||||
File distroUnpackDir = MavenTestingUtils.getTargetFile("test-dist");
|
||||
PathAssert.assertDirExists(artifactName + " dependency:unpack",distroUnpackDir);
|
||||
|
||||
// The actual jetty-distribution-${version} directory is under this directory.
|
||||
// Lets find it.
|
||||
File subdirs[] = distroUnpackDir.listFiles(new FileFilter()
|
||||
{
|
||||
public boolean accept(File path)
|
||||
{
|
||||
if (!path.isDirectory())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return path.getName().startsWith(artifactName + "-");
|
||||
}
|
||||
});
|
||||
|
||||
if (subdirs.length == 0)
|
||||
{
|
||||
// No jetty-distribution found.
|
||||
StringBuilder err = new StringBuilder();
|
||||
err.append("No target/test-dist/");
|
||||
err.append(artifactName);
|
||||
err.append("-${version} directory found.");
|
||||
err.append("\n To fix this, run 'mvn process-test-resources' to create the directory.");
|
||||
throw new IOException(err.toString());
|
||||
}
|
||||
|
||||
if (subdirs.length != 1)
|
||||
{
|
||||
// Too many jetty-distributions found.
|
||||
StringBuilder err = new StringBuilder();
|
||||
err.append("Too many target/test-dist/");
|
||||
err.append(artifactName);
|
||||
err.append("-${version} directories found.");
|
||||
for (File dir : subdirs)
|
||||
{
|
||||
err.append("\n ").append(dir.getAbsolutePath());
|
||||
}
|
||||
err.append("\n To fix this, run 'mvn clean process-test-resources' to recreate the target/test-dist directory.");
|
||||
throw new IOException(err.toString());
|
||||
}
|
||||
|
||||
File distroSrcDir = subdirs[0];
|
||||
FS.ensureEmpty(jettyHomeDir);
|
||||
System.out.printf("Copying Jetty Distribution: %s%n",distroSrcDir.getAbsolutePath());
|
||||
System.out.printf(" To Testing Dir: %s%n",jettyHomeDir.getAbsolutePath());
|
||||
IO.copyDir(distroSrcDir,jettyHomeDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the $(jetty.home) directory being used for this JettyDistro
|
||||
*
|
||||
* @return the jetty.home directory being used
|
||||
*/
|
||||
public File getJettyHomeDir()
|
||||
{
|
||||
return this.jettyHomeDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a war file from ${project.basedir}/target/test-wars/${testWarFilename} into the ${jetty.home}/webapps/ directory
|
||||
*
|
||||
* @param testWarFilename
|
||||
* the war file to copy (must exist)
|
||||
* @throws IOException
|
||||
* if unable to copy the war file.
|
||||
*/
|
||||
public void copyTestWar(String testWarFilename) throws IOException
|
||||
{
|
||||
File srcWar = MavenTestingUtils.getTargetFile("test-wars/" + testWarFilename);
|
||||
File destWar = new File(jettyHomeDir,OS.separators("webapps/" + testWarFilename));
|
||||
FS.ensureDirExists(destWar.getParentFile());
|
||||
IO.copyFile(srcWar,destWar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy an arbitrary file from <code>src/test/resources/${resourcePath}</code> to the testing directory.
|
||||
*
|
||||
* @param resourcePath
|
||||
* the relative path for file content within the <code>src/test/resources</code> directory.
|
||||
* @param outputPath
|
||||
* the testing directory relative output path for the file output (will result in a file with the outputPath name being created)
|
||||
* @throws IOException
|
||||
* if unable to copy resource file
|
||||
*/
|
||||
public void copyResource(String resourcePath, String outputPath) throws IOException
|
||||
{
|
||||
File srcFile = MavenTestingUtils.getTestResourceFile(resourcePath);
|
||||
File destFile = new File(jettyHomeDir,OS.separators(outputPath));
|
||||
FS.ensureDirExists(destFile.getParentFile());
|
||||
IO.copyFile(srcFile,destFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy an arbitrary file from <code>target/test-libs/${libFilename}</code> to the testing directory.
|
||||
*
|
||||
* @param libFilename
|
||||
* the <code>target/test-libs/${libFilename}</code> to copy
|
||||
* @param outputPath
|
||||
* the destination testing directory relative output path for the lib. (will result in a file with the outputPath name being created)
|
||||
* @throws IOException
|
||||
* if unable to copy lib
|
||||
*/
|
||||
public void copyLib(String libFilename, String outputPath) throws IOException
|
||||
{
|
||||
File srcLib = MavenTestingUtils.getTargetFile("test-libs/" + libFilename);
|
||||
File destLib = new File(jettyHomeDir,OS.separators(outputPath));
|
||||
FS.ensureDirExists(destLib.getParentFile());
|
||||
IO.copyFile(srcLib,destLib);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the <code>${project.basedir}/src/main/config/</code> tree into the testing directory.
|
||||
*
|
||||
* @throws IOException
|
||||
* if unable to copy the directory tree
|
||||
*/
|
||||
public void copyProjectMainConfig() throws IOException
|
||||
{
|
||||
File srcDir = MavenTestingUtils.getProjectDir("src/main/config");
|
||||
IO.copyDir(srcDir,jettyHomeDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>${jetty.home}/lib/self/${jarFilename}</code> jar file from the content in the <code>${project.basedir}/target/classes/</code> directory.
|
||||
*
|
||||
* @throws IOException
|
||||
* if unable to copy the directory tree
|
||||
*/
|
||||
public void createProjectLib(String jarFilename) throws IOException
|
||||
{
|
||||
File srcDir = MavenTestingUtils.getTargetFile("classes");
|
||||
File libSelfDir = new File(jettyHomeDir,OS.separators("lib/self"));
|
||||
FS.ensureDirExists(libSelfDir);
|
||||
File jarFile = new File(libSelfDir,jarFilename);
|
||||
JAR.create(srcDir,jarFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack an arbitrary config from <code>target/test-configs/${configFilename}</code> to the testing directory.
|
||||
*
|
||||
* @param configFilename
|
||||
* the <code>target/test-configs/${configFilename}</code> to copy
|
||||
* @throws IOException
|
||||
* if unable to unpack config file
|
||||
*/
|
||||
public void unpackConfig(String configFilename) throws IOException
|
||||
{
|
||||
File srcConfig = MavenTestingUtils.getTargetFile("test-configs/" + configFilename);
|
||||
JAR.unpack(srcConfig,jettyHomeDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a File or Directory found in the ${jetty.home} directory.
|
||||
*
|
||||
* @param path
|
||||
* the path to delete. (can be a file or directory)
|
||||
*/
|
||||
public void delete(String path)
|
||||
{
|
||||
File jettyPath = new File(jettyHomeDir,OS.separators(path));
|
||||
FS.delete(jettyPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the baseUri being used for this Jetty Process Instance.
|
||||
*
|
||||
* @return the base URI for this Jetty Process Instance.
|
||||
*/
|
||||
public URI getBaseUri()
|
||||
{
|
||||
return this.baseUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JMX URL being used for this Jetty Process Instance.
|
||||
*
|
||||
* @return the JMX URL for this Jetty Process Instance.
|
||||
*/
|
||||
public String getJmxUrl()
|
||||
{
|
||||
return this.jmxUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the directory contents from ${project.basedir}/src/test/resources/${testConfigName}/ and copy it over whatever happens to be at ${jetty.home}
|
||||
*
|
||||
* @param testConfigName
|
||||
* the src/test/resources/ directory name to use as the source diretory for the configuration we are interested in.
|
||||
* @throws IOException
|
||||
* if unable to copy directory.
|
||||
*/
|
||||
public void overlayConfig(String testConfigName) throws IOException
|
||||
{
|
||||
File srcDir = MavenTestingUtils.getTestResourceDir(testConfigName);
|
||||
IO.copyDir(srcDir,jettyHomeDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the jetty server
|
||||
*
|
||||
* @throws IOException
|
||||
* if unable to start the server.
|
||||
*/
|
||||
public void start() throws IOException
|
||||
{
|
||||
List<String> commands = new ArrayList<String>();
|
||||
commands.add(getJavaBin());
|
||||
|
||||
commands.add("-Djetty.home=" + jettyHomeDir.getAbsolutePath());
|
||||
|
||||
// Do a dry run first to get the exact command line for Jetty process
|
||||
commands.add("-jar");
|
||||
commands.add("start.jar");
|
||||
commands.add("jetty.port=0");
|
||||
if (_debug)
|
||||
{
|
||||
commands.add("-D.DEBUG=true");
|
||||
}
|
||||
commands.add("--dry-run");
|
||||
|
||||
ProcessBuilder pbCmd = new ProcessBuilder(commands);
|
||||
pbCmd.directory(jettyHomeDir);
|
||||
|
||||
String cmdLine = null;
|
||||
Process pidCmd = pbCmd.start();
|
||||
try
|
||||
{
|
||||
cmdLine = readOutputLine(pidCmd);
|
||||
}
|
||||
finally
|
||||
{
|
||||
pidCmd.destroy();
|
||||
}
|
||||
|
||||
if (cmdLine == null || !cmdLine.contains("XmlConfiguration"))
|
||||
{
|
||||
Assert.fail("Unable to get Jetty command line");
|
||||
}
|
||||
|
||||
// Need to breakdown commandline into parts, as spaces in command line will cause failures.
|
||||
List<String> execCommands = splitAndUnescapeCommandLine(cmdLine);
|
||||
|
||||
System.out.printf("Executing: %s%n",cmdLine);
|
||||
System.out.printf("Working Dir: %s%n",jettyHomeDir.getAbsolutePath());
|
||||
|
||||
pbCmd = new ProcessBuilder(execCommands);
|
||||
pid = pbCmd.start();
|
||||
|
||||
ConsoleParser parser = new ConsoleParser();
|
||||
List<String[]> jmxList = parser.newPattern("JMX Remote URL: (.*)",0);
|
||||
List<String[]> connList = parser.newPattern("Started [A-Za-z]*Connector@([0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*):([0-9]*)",1);
|
||||
// DISABLED: This is what exists in Jetty 9+
|
||||
// List<String[]> connList = parser.newPattern("Started [A-Za-z]*Connector@.*[\\({]([0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*):([0-9]*)[\\)}].*",1);
|
||||
|
||||
startPump("STDOUT",parser,this.pid.getInputStream());
|
||||
startPump("STDERR",parser,this.pid.getErrorStream());
|
||||
|
||||
try
|
||||
{
|
||||
parser.waitForDone(this.startTime,this.timeUnit);
|
||||
|
||||
if (!jmxList.isEmpty())
|
||||
{
|
||||
this.jmxUrl = jmxList.get(0)[0];
|
||||
System.out.printf("## Found JMX connector at %s%n",this.jmxUrl);
|
||||
}
|
||||
|
||||
if (!connList.isEmpty())
|
||||
{
|
||||
String[] params = connList.get(0);
|
||||
if (params.length == 2)
|
||||
{
|
||||
this.baseUri = URI.create("http://localhost:" + params[1] + "/");
|
||||
}
|
||||
System.out.printf("## Found Jetty connector at host: %s port: %s%n",(Object[])params);
|
||||
}
|
||||
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
pid.destroy();
|
||||
Assert.fail("Unable to get required information within time limit");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> splitAndUnescapeCommandLine(CharSequence rawCmdLine)
|
||||
{
|
||||
List<String> cmds = new ArrayList<String>();
|
||||
|
||||
int len = rawCmdLine.length();
|
||||
StringBuilder arg = new StringBuilder();
|
||||
boolean escaped = false;
|
||||
boolean inQuote = false;
|
||||
char c;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
c = rawCmdLine.charAt(i);
|
||||
if (escaped)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'r':
|
||||
arg.append('\r');
|
||||
break;
|
||||
case 'f':
|
||||
arg.append('\f');
|
||||
break;
|
||||
case 't':
|
||||
arg.append('\t');
|
||||
break;
|
||||
case 'n':
|
||||
arg.append('\n');
|
||||
break;
|
||||
case 'b':
|
||||
arg.append('\b');
|
||||
break;
|
||||
default:
|
||||
arg.append(c);
|
||||
break;
|
||||
}
|
||||
escaped = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\\')
|
||||
{
|
||||
escaped = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((c == ' ') && (!inQuote))
|
||||
{
|
||||
// the delim!
|
||||
cmds.add(String.valueOf(arg.toString()));
|
||||
arg.setLength(0);
|
||||
}
|
||||
else if (c == '"')
|
||||
{
|
||||
inQuote = !inQuote;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
cmds.add(String.valueOf(arg.toString()));
|
||||
|
||||
return cmds;
|
||||
}
|
||||
|
||||
private String readOutputLine(Process pidCmd) throws IOException
|
||||
{
|
||||
InputStream in = null;
|
||||
InputStreamReader reader = null;
|
||||
BufferedReader buf = null;
|
||||
try
|
||||
{
|
||||
in = pidCmd.getInputStream();
|
||||
reader = new InputStreamReader(in);
|
||||
buf = new BufferedReader(reader);
|
||||
return buf.readLine();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IO.close(buf);
|
||||
IO.close(reader);
|
||||
IO.close(in);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConsoleParser
|
||||
{
|
||||
private List<ConsolePattern> patterns = new ArrayList<ConsolePattern>();
|
||||
private CountDownLatch latch;
|
||||
private int count;
|
||||
|
||||
public List<String[]> newPattern(String exp, int cnt)
|
||||
{
|
||||
ConsolePattern pat = new ConsolePattern(exp,cnt);
|
||||
patterns.add(pat);
|
||||
count += cnt;
|
||||
|
||||
return pat.getMatches();
|
||||
}
|
||||
|
||||
public void parse(String line)
|
||||
{
|
||||
for (ConsolePattern pat : patterns)
|
||||
{
|
||||
Matcher mat = pat.getMatcher(line);
|
||||
if (mat.find())
|
||||
{
|
||||
int num = 0, count = mat.groupCount();
|
||||
String[] match = new String[count];
|
||||
while (num++ < count)
|
||||
{
|
||||
match[num - 1] = mat.group(num);
|
||||
}
|
||||
pat.getMatches().add(match);
|
||||
|
||||
if (pat.getCount() > 0)
|
||||
{
|
||||
getLatch().countDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void waitForDone(long timeout, TimeUnit unit) throws InterruptedException
|
||||
{
|
||||
getLatch().await(timeout,unit);
|
||||
}
|
||||
|
||||
private CountDownLatch getLatch()
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (latch == null)
|
||||
{
|
||||
latch = new CountDownLatch(count);
|
||||
}
|
||||
}
|
||||
|
||||
return latch;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConsolePattern
|
||||
{
|
||||
private Pattern pattern;
|
||||
private List<String[]> matches;
|
||||
private int count;
|
||||
|
||||
ConsolePattern(String exp, int cnt)
|
||||
{
|
||||
pattern = Pattern.compile(exp);
|
||||
matches = new ArrayList<String[]>();
|
||||
count = cnt;
|
||||
}
|
||||
|
||||
public Matcher getMatcher(String line)
|
||||
{
|
||||
return pattern.matcher(line);
|
||||
}
|
||||
|
||||
public List<String[]> getMatches()
|
||||
{
|
||||
return matches;
|
||||
}
|
||||
|
||||
public int getCount()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
private void startPump(String mode, ConsoleParser parser, InputStream inputStream)
|
||||
{
|
||||
ConsoleStreamer pump = new ConsoleStreamer(mode,inputStream);
|
||||
pump.setParser(parser);
|
||||
Thread thread = new Thread(pump,"ConsoleStreamer/" + mode);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* enable debug on the jetty process
|
||||
*
|
||||
* @param debug
|
||||
*/
|
||||
public void setDebug(boolean debug)
|
||||
{
|
||||
_debug = debug;
|
||||
}
|
||||
|
||||
private String getJavaBin()
|
||||
{
|
||||
String javaexes[] = new String[]
|
||||
{ "java", "java.exe" };
|
||||
|
||||
File javaHomeDir = new File(System.getProperty("java.home"));
|
||||
for (String javaexe : javaexes)
|
||||
{
|
||||
File javabin = new File(javaHomeDir,OS.separators("bin/" + javaexe));
|
||||
if (javabin.exists() && javabin.isFile())
|
||||
{
|
||||
return javabin.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
Assert.fail("Unable to find java bin");
|
||||
return "java";
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the jetty server
|
||||
*/
|
||||
public void stop()
|
||||
{
|
||||
System.out.println("Stopping JettyDistro ...");
|
||||
if (pid != null)
|
||||
{
|
||||
// TODO: maybe issue a STOP instead?
|
||||
pid.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple streamer for the console output from a Process
|
||||
*/
|
||||
private static class ConsoleStreamer implements Runnable
|
||||
{
|
||||
private String mode;
|
||||
private BufferedReader reader;
|
||||
private ConsoleParser parser;
|
||||
|
||||
public ConsoleStreamer(String mode, InputStream is)
|
||||
{
|
||||
this.mode = mode;
|
||||
this.reader = new BufferedReader(new InputStreamReader(is));
|
||||
}
|
||||
|
||||
public void setParser(ConsoleParser connector)
|
||||
{
|
||||
this.parser = connector;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
String line;
|
||||
// System.out.printf("ConsoleStreamer/%s initiated%n",mode);
|
||||
try
|
||||
{
|
||||
while ((line = reader.readLine()) != (null))
|
||||
{
|
||||
if (parser != null)
|
||||
{
|
||||
parser.parse(line);
|
||||
}
|
||||
System.out.println("[" + mode + "] " + line);
|
||||
}
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
/* ignore */
|
||||
}
|
||||
finally
|
||||
{
|
||||
IO.close(reader);
|
||||
}
|
||||
// System.out.printf("ConsoleStreamer/%s finished%n",mode);
|
||||
}
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime, TimeUnit timeUnit)
|
||||
{
|
||||
this.startTime = startTime;
|
||||
this.timeUnit = timeUnit;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue