Merged branch 'jetty-9.1' into 'http_client_connection_factories'.

This commit is contained in:
Simone Bordet 2013-10-08 15:08:07 +02:00
commit 3886cc2dc5
36 changed files with 375 additions and 130 deletions

View File

@ -278,24 +278,18 @@ public class AnnotationConfiguration extends AbstractConfiguration
throws Exception
{
AnnotationParser parser = createAnnotationParser();
boolean multiThreadedScan = isUseMultiThreading(context);
int maxScanWait = 0;
if (multiThreadedScan)
{
_parserTasks = new ArrayList<ParserTask>();
maxScanWait = getMaxScanWait(context);
}
_parserTasks = new ArrayList<ParserTask>();
long start = 0;
if (LOG.isDebugEnabled())
{
start = System.nanoTime();
LOG.debug("Scanning for annotations: webxml={}, metadatacomplete={}, configurationDiscovered={}, multiThreaded={}",
LOG.debug("Scanning for annotations: webxml={}, metadatacomplete={}, configurationDiscovered={}, multiThreaded={}, maxScanWait={}",
context.getServletContext().getEffectiveMajorVersion(),
context.getMetaData().isMetaDataComplete(),
context.isConfigurationDiscovered(),
multiThreadedScan);
isUseMultiThreading(context),
getMaxScanWait(context));
}
parseContainerPath(context, parser);
@ -307,23 +301,15 @@ public class AnnotationConfiguration extends AbstractConfiguration
parseWebInfClasses(context, parser);
parseWebInfLib (context, parser);
if (!multiThreadedScan)
{
if (LOG.isDebugEnabled())
{
long end = System.nanoTime();
LOG.debug("Annotation parsing millisec={}",(TimeUnit.MILLISECONDS.convert(end-start, TimeUnit.NANOSECONDS)));
}
return;
}
if (LOG.isDebugEnabled())
start = System.nanoTime();
//execute scan asynchronously using jetty's thread pool
//execute scan, either effectively synchronously (1 thread only), or asychronously (limited by number of processors available)
final Semaphore task_limit = (isUseMultiThreading(context)? new Semaphore(Runtime.getRuntime().availableProcessors()):new Semaphore(1));
final CountDownLatch latch = new CountDownLatch(_parserTasks.size());
final MultiException me = new MultiException();
final Semaphore task_limit=new Semaphore(Runtime.getRuntime().availableProcessors());
for (final ParserTask p:_parserTasks)
{
task_limit.acquire();
@ -349,13 +335,10 @@ public class AnnotationConfiguration extends AbstractConfiguration
});
}
boolean timeout = !latch.await(maxScanWait, TimeUnit.SECONDS);
boolean timeout = !latch.await(getMaxScanWait(context), TimeUnit.SECONDS);
if (LOG.isDebugEnabled())
{
long end = System.nanoTime();
LOG.debug("Annotation parsing millisec={}",(TimeUnit.MILLISECONDS.convert(end-start, TimeUnit.NANOSECONDS)));
}
LOG.debug("Annotation parsing millisec={}",(TimeUnit.MILLISECONDS.convert(System.nanoTime()-start, TimeUnit.NANOSECONDS)));
if (timeout)
me.add(new Exception("Timeout scanning annotations"));
@ -607,9 +590,6 @@ public class AnnotationConfiguration extends AbstractConfiguration
//queue it up for scanning if using multithreaded mode
if (_parserTasks != null)
_parserTasks.add(new ParserTask(parser, handlers, r, _containerClassNameResolver));
else
//just scan it now
parser.parse(handlers, r, _containerClassNameResolver);
}
}
@ -664,8 +644,6 @@ public class AnnotationConfiguration extends AbstractConfiguration
if (_parserTasks != null)
_parserTasks.add (new ParserTask(parser, handlers,r, _webAppClassNameResolver));
else
parser.parse(handlers, r, _webAppClassNameResolver);
}
}
@ -694,8 +672,6 @@ public class AnnotationConfiguration extends AbstractConfiguration
{
if (_parserTasks != null)
_parserTasks.add(new ParserTask(parser, handlers, dir, _webAppClassNameResolver));
else
parser.parse(handlers, dir, _webAppClassNameResolver);
}
}

View File

@ -39,6 +39,7 @@ import java.util.jar.JarInputStream;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.MultiException;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
@ -370,15 +371,6 @@ public class AnnotationParser
final MethodInfo _mi;
final Set<? extends Handler> _handlers;
/**
* @param classname
* @param access
* @param name
* @param methodDesc
* @param signature
* @param exceptions
*/
public MyMethodVisitor(final Set<? extends Handler> handlers,
final ClassInfo classInfo,
final int access,
@ -423,9 +415,6 @@ public class AnnotationParser
final Set<? extends Handler> _handlers;
/**
* @param classname
*/
public MyFieldVisitor(final Set<? extends Handler> handlers,
final ClassInfo classInfo,
final int access,
@ -614,6 +603,7 @@ public class AnnotationParser
}
}
}
if (visitSuperClasses)
cz = cz.getSuperclass();
else
@ -650,19 +640,29 @@ public class AnnotationParser
public void parse (Set<? extends Handler> handlers, List<String> classNames, ClassNameResolver resolver)
throws Exception
{
MultiException me = new MultiException();
for (String s:classNames)
{
if ((resolver == null) || (!resolver.isExcluded(s) && (!isParsed(s) || resolver.shouldOverride(s))))
try
{
s = s.replace('.', '/')+".class";
URL resource = Loader.getResource(this.getClass(), s);
if (resource!= null)
if ((resolver == null) || (!resolver.isExcluded(s) && (!isParsed(s) || resolver.shouldOverride(s))))
{
Resource r = Resource.newResource(resource);
scanClass(handlers, null, r.getInputStream());
s = s.replace('.', '/')+".class";
URL resource = Loader.getResource(this.getClass(), s);
if (resource!= null)
{
Resource r = Resource.newResource(resource);
scanClass(handlers, null, r.getInputStream());
}
}
}
catch (Exception e)
{
me.add(new RuntimeException("Error scanning class "+s, e));
}
}
me.ifExceptionThrow();
}
@ -682,25 +682,27 @@ public class AnnotationParser
if (LOG.isDebugEnabled()) {LOG.debug("Scanning dir {}", dir);};
MultiException me = new MultiException();
String[] files=dir.list();
for (int f=0;files!=null && f<files.length;f++)
{
try
Resource res = dir.addPath(files[f]);
if (res.isDirectory())
parseDir(handlers, res, resolver);
else
{
Resource res = dir.addPath(files[f]);
if (res.isDirectory())
parseDir(handlers, res, resolver);
//we've already verified the directories, so just verify the class file name
boolean valid = true;
File file = res.getFile();
if (file == null)
LOG.warn("Unable to validate class file name for {}", res);
else
valid = isValidClassFileName(file.getName());
if (valid)
{
//we've already verified the directories, so just verify the class file name
boolean valid = true;
File file = res.getFile();
if (file == null)
LOG.warn("Unable to validate class file name for {}", res);
else
valid = isValidClassFileName(file.getName());
if (valid)
try
{
String name = res.getName();
if ((resolver == null)|| (!resolver.isExcluded(name) && (!isParsed(name) || resolver.shouldOverride(name))))
@ -709,15 +711,16 @@ public class AnnotationParser
if (LOG.isDebugEnabled()) {LOG.debug("Scanning class {}", r);};
scanClass(handlers, dir, r.getInputStream());
}
}
catch (Exception ex)
{
me.add(new RuntimeException("Error scanning file "+files[f],ex));
}
}
}
catch (Exception ex)
{
LOG.warn(Log.EXCEPTION,ex);
}
}
me.ifExceptionThrow();
}
@ -740,6 +743,8 @@ public class AnnotationParser
if (!(loader instanceof URLClassLoader))
return; //can't extract classes?
final MultiException me = new MultiException();
JarScanner scanner = new JarScanner()
{
@Override
@ -751,13 +756,14 @@ public class AnnotationParser
}
catch (Exception e)
{
LOG.warn("Problem parsing jar entry: {}", entry.getName());
me.add(new RuntimeException("Error parsing entry "+entry.getName()+" from jar "+ jarUri, e));
}
}
};
scanner.scan(null, loader, nullInclusive, visitParents);
me.ifExceptionThrow();
}
@ -774,6 +780,8 @@ public class AnnotationParser
if (uris==null)
return;
MultiException me = new MultiException();
for (URI uri:uris)
{
try
@ -782,10 +790,10 @@ public class AnnotationParser
}
catch (Exception e)
{
LOG.warn("Problem parsing classes from {}", uri);
me.add(new RuntimeException("Problem parsing classes from "+ uri, e));
}
}
me.ifExceptionThrow();
}
/**
@ -801,8 +809,6 @@ public class AnnotationParser
return;
parse (handlers, Resource.newResource(uri), resolver);
}
@ -895,13 +901,22 @@ public class AnnotationParser
if (in==null)
return;
MultiException me = new MultiException();
JarInputStream jar_in = new JarInputStream(in);
try
{
JarEntry entry = jar_in.getNextJarEntry();
while (entry!=null)
{
parseJarEntry(handlers, jarResource, entry, resolver);
try
{
parseJarEntry(handlers, jarResource, entry, resolver);
}
catch (Exception e)
{
me.add(new RuntimeException("Error scanning entry "+entry.getName()+" from jar "+jarResource, e));
}
entry = jar_in.getNextJarEntry();
}
}
@ -909,7 +924,8 @@ public class AnnotationParser
{
jar_in.close();
}
}
me.ifExceptionThrow();
}
}
/**

View File

@ -50,8 +50,9 @@ public class ContainerInitializerAnnotationHandler extends AbstractHandler
/**
* Handle finding a class that is annotated with the annotation we were constructed with.
* @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handle(ClassInfo)
* */
*
* @see org.eclipse.jetty.annotations.AnnotationParser.Handler#handle(ClassInfo, String)
*/
public void handle(ClassInfo info, String annotationName)
{
if (annotationName == null || !_annotation.getName().equals(annotationName))
@ -63,7 +64,7 @@ public class ContainerInitializerAnnotationHandler extends AbstractHandler
/**
* Handle finding a field that is annotated with the annotation we were constructed with.
*
* @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handle(org.eclipse.jetty.annotations.AnnotationParser.FieldAnnotationInfo)
* @see org.eclipse.jetty.annotations.AnnotationParser.Handler#handle(FieldInfo, String)
*/
public void handle(FieldInfo info, String annotationName)
{
@ -75,7 +76,7 @@ public class ContainerInitializerAnnotationHandler extends AbstractHandler
/**
* Handle finding a method that is annotated with the annotation we were constructed with.
*
* @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handle(org.eclipse.jetty.annotations.AnnotationParser.MethodAnnotationInfo)
* @see org.eclipse.jetty.annotations.AnnotationParser.Handler#handle(MethodInfo, String)
*/
public void handle(MethodInfo info, String annotationName)
{

View File

@ -36,7 +36,7 @@ public class WebListenerAnnotationHandler extends AbstractDiscoverableAnnotation
/**
* @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handle(ClassAnnotationInfo)
* @see org.eclipse.jetty.annotations.AnnotationParser.Handler#handle(ClassInfo, String)
*/
public void handle(ClassInfo info, String annotationName)
{

View File

@ -18,14 +18,11 @@
package org.eclipse.jetty.annotations;
import java.util.List;
import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo;
import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo;
import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.webapp.DiscoveredAnnotation;
import org.eclipse.jetty.webapp.WebAppContext;
/**
@ -47,8 +44,7 @@ public class WebServletAnnotationHandler extends AbstractDiscoverableAnnotationH
/**
* Handle discovering a WebServlet annotation.
*
*
* @see org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler#handleClass(java.lang.String, int, int, java.lang.String, java.lang.String, java.lang.String[], java.lang.String, java.util.List)
* @see org.eclipse.jetty.annotations.AnnotationParser.Handler#handle(ClassInfo, String)
*/
@Override
public void handle(ClassInfo info, String annotationName)

View File

@ -502,7 +502,7 @@
<arguments>
<argument>jetty.home=${assembly-directory}</argument>
<argument>jetty.base=${assembly-directory}/demo-base</argument>
<argument>--add-to-start=server,deploy,jsp,ext,resources,client,annotations,jndi</argument>
<argument>--add-to-start=server,continuation,deploy,jsp,ext,resources,client,annotations,jndi</argument>
<argument>--add-to-startd-ini=http,https</argument>
</arguments>
</configuration>

View File

@ -25,7 +25,6 @@ import java.util.Set;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.annotations.AnnotationParser;
import org.eclipse.jetty.annotations.AnnotationParser.Handler;
import org.eclipse.jetty.annotations.ClassNameResolver;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
@ -86,8 +85,6 @@ public class MavenAnnotationConfiguration extends AnnotationConfiguration
throws Exception
{
if (_parserTasks != null)
_parserTasks.add(new ParserTask(parser, handlers, resource, _webAppClassNameResolver));
else
parser.parse(handlers, resource, _webAppClassNameResolver);
_parserTasks.add(new ParserTask(parser, handlers, resource, _webAppClassNameResolver));
}
}

View File

@ -179,8 +179,6 @@ public class AnnotationConfiguration extends org.eclipse.jetty.annotations.Annot
ClassNameResolver classNameResolver = createClassNameResolver(context);
if (_parserTasks != null)
_parserTasks.add(new BundleParserTask(parser, handlers, bundleRes, classNameResolver));
else
parser.parse(handlers, bundle, classNameResolver);
}
/**

View File

@ -33,7 +33,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.servlet.AsyncContext;
import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServlet;
@ -62,7 +64,7 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
* <p/>
* To facilitate JMX monitoring, the {@link HttpClient} instance is set as context attribute,
* prefixed with the servlet's name and exposed by the mechanism provided by
* {@link ContextHandler#MANAGED_ATTRIBUTES}.
* {@link ServletContext#setAttribute(String, Object)}.
* <p/>
* The following init parameters may be used to configure the servlet:
* <ul>

View File

@ -261,7 +261,7 @@ public class JDBCLoginService extends MappedLoginService
roles.add(rs2.getString(_roleTableRoleField));
}
}
return putUser(username, Credential.getCredential(credentials),roles.toArray(new String[roles.size()]));
return putUser(username, credentials, roles.toArray(new String[roles.size()]));
}
}
}
@ -273,6 +273,13 @@ public class JDBCLoginService extends MappedLoginService
}
return null;
}
/* ------------------------------------------------------------ */
protected UserIdentity putUser (String username, String credentials, String[] roles)
{
return putUser(username, Credential.getCredential(credentials),roles);
}
/**
* Close an existing connection

View File

@ -0,0 +1,4 @@
# Module to add Continuation jar to classpath
[lib]
lib/jetty-continuation-${jetty.version}.jar

View File

@ -1,2 +1,6 @@
#
# Module to add resources directory to classpath
#
[lib]
resources

View File

@ -12,7 +12,6 @@ resources
lib/servlet-api-3.1.jar
lib/jetty-schemas-3.1.jar
lib/jetty-http-${jetty.version}.jar
lib/jetty-continuation-${jetty.version}.jar
lib/jetty-server-${jetty.version}.jar
lib/jetty-xml-${jetty.version}.jar
lib/jetty-util-${jetty.version}.jar

View File

@ -1,5 +1,5 @@
#
# Stats module
# Xinetd module
#
[depend]

View File

@ -216,6 +216,8 @@ public class Holder<T> extends AbstractLifeCycle implements Dumpable
{
_className = className;
_class=null;
if (_name==null)
_name=className+"-"+Integer.toHexString(this.hashCode());
}
/* ------------------------------------------------------------ */
@ -229,7 +231,7 @@ public class Holder<T> extends AbstractLifeCycle implements Dumpable
{
_className=held.getName();
if (_name==null)
_name=held.getName()+"-"+this.hashCode();
_name=held.getName()+"-"+Integer.toHexString(this.hashCode());
}
}

View File

@ -843,7 +843,6 @@ public class ServletHandler extends ScopedHandler
public ServletHolder addServletWithMapping (String className,String pathSpec)
{
ServletHolder holder = newServletHolder(Holder.Source.EMBEDDED);
holder.setName(className+"-"+(_servlets==null?0:_servlets.length));
holder.setClassName(className);
addServletWithMapping(holder,pathSpec);
return holder;
@ -959,7 +958,6 @@ public class ServletHandler extends ScopedHandler
public FilterHolder addFilterWithMapping (String className,String pathSpec,EnumSet<DispatcherType> dispatches)
{
FilterHolder holder = newFilterHolder(Holder.Source.EMBEDDED);
holder.setName(className+"-"+_filters.length);
holder.setClassName(className);
addFilterWithMapping(holder,pathSpec,dispatches);
@ -1028,7 +1026,6 @@ public class ServletHandler extends ScopedHandler
public FilterHolder addFilterWithMapping (String className,String pathSpec,int dispatches)
{
FilterHolder holder = newFilterHolder(Holder.Source.EMBEDDED);
holder.setName(className+"-"+_filters.length);
holder.setClassName(className);
addFilterWithMapping(holder,pathSpec,dispatches);

View File

@ -199,8 +199,6 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
int c=(_className!=null && sh._className!=null)?_className.compareTo(sh._className):0;
if (c==0)
c=_name.compareTo(sh._name);
if (c==0)
c=this.hashCode()>sh.hashCode()?1:-1;
return c;
}

View File

@ -91,7 +91,7 @@ public class ErrorPageTest
assertThat(response,Matchers.containsString("ERROR_CODE: 599"));
assertThat(response,Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response,Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response,Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-1"));
assertThat(response,Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-"));
assertThat(response,Matchers.containsString("ERROR_REQUEST_URI: /fail/code"));
}
@ -104,7 +104,7 @@ public class ErrorPageTest
assertThat(response,Matchers.containsString("ERROR_CODE: 500"));
assertThat(response,Matchers.containsString("ERROR_EXCEPTION: javax.servlet.ServletException: java.lang.IllegalStateException"));
assertThat(response,Matchers.containsString("ERROR_EXCEPTION_TYPE: class javax.servlet.ServletException"));
assertThat(response,Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-1"));
assertThat(response,Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-"));
assertThat(response,Matchers.containsString("ERROR_REQUEST_URI: /fail/exception"));
}
@ -117,7 +117,7 @@ public class ErrorPageTest
assertThat(response,Matchers.containsString("ERROR_CODE: 598"));
assertThat(response,Matchers.containsString("ERROR_EXCEPTION: null"));
assertThat(response,Matchers.containsString("ERROR_EXCEPTION_TYPE: null"));
assertThat(response,Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-1"));
assertThat(response,Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-"));
assertThat(response,Matchers.containsString("ERROR_REQUEST_URI: /fail/global"));
}
@ -130,7 +130,7 @@ public class ErrorPageTest
assertThat(response,Matchers.containsString("ERROR_CODE: 500"));
assertThat(response,Matchers.containsString("ERROR_EXCEPTION: java.lang.NumberFormatException: For input string: \"NAN\""));
assertThat(response,Matchers.containsString("ERROR_EXCEPTION_TYPE: class java.lang.NumberFormatException"));
assertThat(response,Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-1"));
assertThat(response,Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-"));
assertThat(response,Matchers.containsString("ERROR_REQUEST_URI: /fail/global"));
}

View File

@ -49,7 +49,7 @@ import org.junit.Test;
public class SynDataReplyDataLoadTest extends AbstractTest
{
@Test
@Test(timeout=60000)
public void testSynDataReplyDataLoad() throws Exception
{
ServerSessionFrameListener serverSessionFrameListener = new ServerSessionFrameListener.Adapter()

View File

@ -79,7 +79,7 @@ public class StartArgs
private List<String> jvmArgs = new ArrayList<>();
private List<String> moduleStartdIni = new ArrayList<>();
private List<String> moduleStartIni = new ArrayList<>();
private Map<String,String> propertySource = new HashMap<>();
private Map<String, String> propertySource = new HashMap<>();
private String moduleGraphFilename;
private Modules allModules;
@ -207,7 +207,7 @@ public class StartArgs
System.out.println(" (no properties specified)");
return;
}
List<String> sortedKeys = new ArrayList<>();
@SuppressWarnings("unchecked")
Enumeration<String> keyEnum = (Enumeration<String>)properties.propertyNames();
@ -215,10 +215,10 @@ public class StartArgs
{
sortedKeys.add(keyEnum.nextElement());
}
Collections.sort(sortedKeys);
for(String key: sortedKeys)
for (String key : sortedKeys)
{
String value = properties.getProperty(key);
System.out.printf(" %s = %s%n",key,value);
@ -236,7 +236,7 @@ public class StartArgs
System.out.println(" (no system properties specified)");
return;
}
List<String> sortedKeys = new ArrayList<>();
sortedKeys.addAll(systemPropertyKeys);
Collections.sort(sortedKeys);
@ -680,10 +680,10 @@ public class StartArgs
exec = true;
return;
}
// Arbitrary Libraries
if(arg.startsWith("--lib="))
if (arg.startsWith("--lib="))
{
String cp = getValue(arg);
classpath.addClasspath(cp);
@ -779,13 +779,27 @@ public class StartArgs
{
String key = arg.substring(0,idx);
String value = arg.substring(idx + 1);
if (source!=CMD_LINE_SOURCE)
if (source != CMD_LINE_SOURCE)
{
if (propertySource.containsKey(key))
{
throw new UsageException(ERR_BAD_ARG,"Property %s in %s already set in %s",key,source,propertySource.get(key));
}
propertySource.put(key,source);
}
if ("OPTION".equals(key) || "OPTIONS".equals(key))
{
StringBuilder warn = new StringBuilder();
warn.append("The behavior of the argument ");
warn.append(arg).append(" (seen in ").append(source);
warn.append(") has changed, and is now considered a normal property. ");
warn.append(key).append(" no longer controls what libraries are on your classpath,");
warn.append(" use --module instead. See --help for details.");
StartLog.warn(warn.toString());
}
properties.setProperty(key,value);
return;
}

View File

@ -60,12 +60,12 @@ public class StartLog
public static void info(String format, Object... args)
{
System.err.printf(format + "%n",args);
System.err.printf("WARNING: " + format + "%n",args);
}
public static void warn(String format, Object... args)
{
System.err.printf(format + "%n",args);
System.err.printf("WARNING: " + format + "%n",args);
}
public static void warn(Throwable t)

View File

@ -293,7 +293,7 @@ public class WebInfConfiguration extends AbstractConfiguration
try
{
// Put the tmp dir in the work directory if we had one
File work = new File(System.getProperty("jetty.home"),"work");
File work = new File(System.getProperty("jetty.base"),"work");
if (work.exists() && work.canWrite() && work.isDirectory())
{
makeTempDirectory(work, context, false); //make a tmp dir inside work, don't delete if it exists

View File

@ -64,8 +64,8 @@ public class AnnotatedEndpointScanner<T extends Annotation, C extends EndpointCo
paramsOnError.add(JsrParamIdOnError.INSTANCE);
metadata.customizeParamsOnMessage(paramsOnMessage);
paramsOnMessage.add(JsrParamIdBinary.INSTANCE);
paramsOnMessage.add(JsrParamIdText.INSTANCE);
paramsOnMessage.add(JsrParamIdBinary.INSTANCE);
paramsOnMessage.add(JsrParamIdPong.INSTANCE);
}

View File

@ -27,6 +27,7 @@ import org.eclipse.jetty.websocket.common.events.annotated.InvalidSignatureExcep
import org.eclipse.jetty.websocket.jsr356.annotations.Param.Role;
import org.eclipse.jetty.websocket.jsr356.decoders.ByteArrayDecoder;
import org.eclipse.jetty.websocket.jsr356.decoders.ByteBufferDecoder;
import org.eclipse.jetty.websocket.jsr356.decoders.InputStreamDecoder;
/**
* Param handling for static Binary &#064;{@link OnMessage} parameters.
@ -63,7 +64,7 @@ public class JsrParamIdBinary extends JsrParamIdOnMessage implements IJsrParamId
{
assertPartialMessageSupportDisabled(param,callable);
param.bind(Role.MESSAGE_BINARY_STREAM);
// Streaming have no decoder
callable.setDecoderClass(InputStreamDecoder.class);
return true;
}

View File

@ -144,12 +144,37 @@ public abstract class CoderMetadataSet<T, M extends CoderMetadata<T>> implements
{
Integer idx = typeMap.get(type);
if (idx == null)
{
// Quick lookup failed, try slower lookup via isAssignable instead
idx = getMetadataByAssignableType(type);
if (idx != null)
{
// add new entry map
typeMap.put(type,idx);
}
}
// If idx is STILL null, we've got no match
if (idx == null)
{
return null;
}
return metadatas.get(idx);
}
private Integer getMetadataByAssignableType(Class<?> type)
{
for (Map.Entry<Class<?>, Integer> entry : typeMap.entrySet())
{
if (entry.getKey().isAssignableFrom(type))
{
return entry.getValue();
}
}
return null;
}
@Override
public Iterator<M> iterator()
{

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.jsr356.endpoints;
import static org.hamcrest.Matchers.*;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@ -43,6 +44,8 @@ import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicErrorSessionThr
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicErrorSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicErrorThrowableSessionSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicErrorThrowableSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicInputStreamSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicInputStreamWithThrowableSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicOpenSessionSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicOpenSocket;
import org.eclipse.jetty.websocket.jsr356.endpoints.samples.BasicPongMessageSocket;
@ -97,6 +100,7 @@ public class ClientAnnotatedEndpointScanner_GoodSignaturesTest
Field fError = findFieldRef(AnnotatedEndpointMetadata.class,"onError");
Field fText = findFieldRef(AnnotatedEndpointMetadata.class,"onText");
Field fBinary = findFieldRef(AnnotatedEndpointMetadata.class,"onBinary");
Field fBinaryStream = findFieldRef(AnnotatedEndpointMetadata.class,"onBinaryStream");
Field fPong = findFieldRef(AnnotatedEndpointMetadata.class,"onPong");
// @formatter:off
@ -120,6 +124,9 @@ public class ClientAnnotatedEndpointScanner_GoodSignaturesTest
Case.add(data, BasicBinaryMessageByteBufferSocket.class, fBinary, ByteBuffer.class);
// -- Pong Events
Case.add(data, BasicPongMessageSocket.class, fPong, PongMessage.class);
// -- InputStream Events
Case.add(data, BasicInputStreamSocket.class, fBinaryStream, InputStream.class);
Case.add(data, BasicInputStreamWithThrowableSocket.class, fBinaryStream, InputStream.class);
// @formatter:on
// TODO: validate return types

View File

@ -0,0 +1,47 @@
//
// ========================================================================
// 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.websocket.jsr356.endpoints.samples;
import java.io.IOException;
import java.io.InputStream;
import javax.websocket.ClientEndpoint;
import javax.websocket.OnMessage;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@ClientEndpoint
public class BasicInputStreamSocket extends TrackingSocket
{
@OnMessage
public void onBinary(InputStream stream)
{
try
{
String msg = IO.toString(stream);
addEvent("onBinary(%s)",msg);
}
catch (IOException e)
{
super.errorQueue.add(e);
}
dataLatch.countDown();
}
}

View File

@ -0,0 +1,39 @@
//
// ========================================================================
// 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.websocket.jsr356.endpoints.samples;
import java.io.IOException;
import java.io.InputStream;
import javax.websocket.ClientEndpoint;
import javax.websocket.OnMessage;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.websocket.jsr356.endpoints.TrackingSocket;
@ClientEndpoint
public class BasicInputStreamWithThrowableSocket extends TrackingSocket
{
@OnMessage
public void onBinary(InputStream stream) throws IOException
{
String msg = IO.toString(stream);
addEvent("onBinary(%s)",msg);
}
}

View File

@ -110,7 +110,7 @@ public class AnnotatedServerEndpointConfig implements ServerEndpointConfig
userProperties.putAll(baseConfig.getUserProperties());
}
if (anno.configurator() == null)
if (anno.configurator() == ServerEndpointConfig.Configurator.class)
{
if (configr != null)
{

View File

@ -30,6 +30,7 @@ import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.RemoteEndpoint.Basic;
import javax.websocket.Session;
@ClientEndpoint
@ -37,6 +38,7 @@ public class EchoClientSocket extends TrackingSocket
{
public final CountDownLatch eventCountLatch;
private Session session;
private Basic remote;
public EchoClientSocket(int expectedEventCount)
{
@ -76,6 +78,7 @@ public class EchoClientSocket extends TrackingSocket
public void onOpen(Session session)
{
this.session = session;
this.remote = session.getBasicRemote();
openLatch.countDown();
}
@ -93,16 +96,16 @@ public class EchoClientSocket extends TrackingSocket
public void sendObject(Object obj) throws IOException, EncodeException
{
session.getBasicRemote().sendObject(obj);
remote.sendObject(obj);
}
public void sendPartialBinary(ByteBuffer part, boolean fin) throws IOException
{
session.getBasicRemote().sendBinary(part,fin);
remote.sendBinary(part,fin);
}
public void sendPartialText(String part, boolean fin) throws IOException
{
session.getBasicRemote().sendText(part,fin);
remote.sendText(part,fin);
}
}

View File

@ -32,9 +32,11 @@ import javax.websocket.WebSocketContainer;
import org.eclipse.jetty.toolchain.test.EventQueue;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.jsr356.server.EchoCase.PartialBinary;
import org.eclipse.jetty.websocket.jsr356.server.EchoCase.PartialText;
import org.eclipse.jetty.websocket.jsr356.server.samples.binary.ByteBufferSocket;
import org.eclipse.jetty.websocket.jsr356.server.samples.partial.PartialTextSessionSocket;
import org.eclipse.jetty.websocket.jsr356.server.samples.partial.PartialTextSocket;
import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.BooleanObjectTextSocket;
@ -54,6 +56,7 @@ import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.LongObjectTe
import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.LongTextSocket;
import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.ShortObjectTextSocket;
import org.eclipse.jetty.websocket.jsr356.server.samples.primitives.ShortTextSocket;
import org.eclipse.jetty.websocket.jsr356.server.samples.streaming.InputStreamSocket;
import org.eclipse.jetty.websocket.jsr356.server.samples.streaming.ReaderParamSocket;
import org.eclipse.jetty.websocket.jsr356.server.samples.streaming.ReaderSocket;
import org.eclipse.jetty.websocket.jsr356.server.samples.streaming.StringReturnReaderParamSocket;
@ -178,6 +181,12 @@ public class EchoTest
// PathParam based
EchoCase.add(TESTCASES,IntParamTextSocket.class).requestPath("/echo/primitives/integer/params/5678").addMessage(1234).expect("1234|5678");
// ByteBuffer based
EchoCase.add(TESTCASES,ByteBufferSocket.class).addMessage(BufferUtil.toBuffer("Hello World")).expect("Hello World");
// InputStream based
EchoCase.add(TESTCASES,InputStreamSocket.class).addMessage(BufferUtil.toBuffer("Hello World")).expect("Hello World");
// Reader based
EchoCase.add(TESTCASES,ReaderSocket.class).addMessage("Hello World").expect("Hello World");

View File

@ -0,0 +1,51 @@
//
// ========================================================================
// 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.websocket.jsr356.server.samples.binary;
import java.io.IOException;
import java.nio.ByteBuffer;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.jsr356.server.StackUtil;
@ServerEndpoint("/echo/binary/bytebuffer")
public class ByteBufferSocket
{
private static final Logger LOG = Log.getLogger(ByteBufferSocket.class);
@OnMessage
public String onByteBuffer(ByteBuffer bbuf)
{
return BufferUtil.toUTF8String(bbuf);
}
@OnError
public void onError(Session session, Throwable cause) throws IOException
{
LOG.warn("Error",cause);
session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause));
}
}

View File

@ -0,0 +1,52 @@
//
// ========================================================================
// 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.websocket.jsr356.server.samples.streaming;
import java.io.IOException;
import java.io.InputStream;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.jsr356.server.StackUtil;
@ServerEndpoint("/echo/streaming/inputstream")
public class InputStreamSocket
{
private static final Logger LOG = Log.getLogger(InputStreamSocket.class);
@OnMessage
public String onInputStream(InputStream stream) throws IOException
{
return IO.toString(stream, StringUtil.__UTF8);
}
@OnError
public void onError(Session session, Throwable cause) throws IOException
{
LOG.warn("Error",cause);
session.getBasicRemote().sendText("Exception: " + StackUtil.toString(cause));
}
}

View File

@ -74,7 +74,7 @@ public class JdbcTestServer extends AbstractTestServer
static int __workers=0;
/**
* @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionIdManager()
* @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionIdManager(String)
*/
@Override
public SessionIdManager newSessionIdManager(String config)

View File

@ -63,7 +63,7 @@ public abstract class AbstractProxySerializationTest
/**
* @param sec mseconds to sleep
* @param msec milliseconds to sleep
*/
public void pause(int msec)
{

View File

@ -42,7 +42,7 @@
<filter>
<filter-name>TestFilter</filter-name>
<filter-class>com.acme.TestFilter</filter-class>
<async-support>true</async-support>
<async-supported>true</async-supported>
<init-param>
<param-name>remote</param-name>
<param-value>true</param-value>