Merge branch 'master' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project

This commit is contained in:
hmalphettes 2011-09-14 16:34:33 +08:00
commit 1cbf5c4672
26 changed files with 1386 additions and 496 deletions

23
.gitignore vendored
View File

@ -1,14 +1,33 @@
target/ # eclipse
.classpath .classpath
.project .project
.settings .settings
# maven
target/
*/src/main/java/META-INF/ */src/main/java/META-INF/
.pmd
# common junk
*.log *.log
*.swp *.swp
*.diff *.diff
*.patch *.patch
# intellij
*.iml *.iml
*.ipr *.ipr
*.iws *.iws
.idea/ .idea/
# Mac filesystem dust
/.DS_Store
# pmd
.pmdruleset
.pmd
# netbeans
/nbproject
# vim
.*.sw[a-p]

View File

@ -5,7 +5,6 @@
<version>7.5.2-SNAPSHOT</version> <version>7.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all-server</artifactId> <artifactId>jetty-all-server</artifactId>
<name>Jetty :: Aggregate :: All Server</name> <name>Jetty :: Aggregate :: All Server</name>
<properties> <properties>

View File

@ -5,10 +5,8 @@
<version>7.5.2-SNAPSHOT</version> <version>7.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all</artifactId> <artifactId>jetty-all</artifactId>
<name>Jetty :: Aggregate :: All core Jetty</name> <name>Jetty :: Aggregate :: All core Jetty</name>
<build> <build>
<sourceDirectory>${project.build.directory}/sources</sourceDirectory> <sourceDirectory>${project.build.directory}/sources</sourceDirectory>
<plugins> <plugins>

View File

@ -5,7 +5,6 @@
<version>7.5.2-SNAPSHOT</version> <version>7.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-client</artifactId> <artifactId>jetty-client</artifactId>
<name>Jetty :: Aggregate :: HTTP Client</name> <name>Jetty :: Aggregate :: HTTP Client</name>

View File

@ -5,7 +5,6 @@
<version>7.5.2-SNAPSHOT</version> <version>7.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-plus</artifactId> <artifactId>jetty-plus</artifactId>
<name>Jetty :: Aggregate :: Plus Server</name> <name>Jetty :: Aggregate :: Plus Server</name>

View File

@ -5,7 +5,6 @@
<version>7.5.2-SNAPSHOT</version> <version>7.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-server</artifactId> <artifactId>jetty-server</artifactId>
<name>Jetty :: Aggregate :: HTTP Server</name> <name>Jetty :: Aggregate :: HTTP Server</name>

View File

@ -5,7 +5,6 @@
<version>7.5.2-SNAPSHOT</version> <version>7.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-servlet</artifactId> <artifactId>jetty-servlet</artifactId>
<name>Jetty :: Aggregate :: Servlet Server</name> <name>Jetty :: Aggregate :: Servlet Server</name>

View File

@ -5,7 +5,6 @@
<version>7.5.2-SNAPSHOT</version> <version>7.5.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-webapp</artifactId> <artifactId>jetty-webapp</artifactId>
<name>Jetty :: Aggregate :: WebApp Server</name> <name>Jetty :: Aggregate :: WebApp Server</name>

View File

@ -30,7 +30,6 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.ConnectedEndPoint; import org.eclipse.jetty.io.ConnectedEndPoint;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
@ -450,6 +449,9 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
{ {
_selecting=Thread.currentThread(); _selecting=Thread.currentThread();
final Selector selector=_selector; final Selector selector=_selector;
// Stopped concurrently ?
if (selector == null)
return;
// Make any key changes required // Make any key changes required
Object change; Object change;

View File

@ -0,0 +1,69 @@
// ========================================================================
// Copyright (c) 2011 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.jndi;
import java.util.Iterator;
import javax.naming.Binding;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
/** BindingEnumeration
* <p>Implementation of NamingEnumeration
*
* <p><h4>Notes</h4>
* <p>Used to return results of Context.listBindings();
*
* <p><h4>Usage</h4>
*
*/
public class BindingEnumeration implements NamingEnumeration<Binding>
{
Iterator<Binding> _delegate;
public BindingEnumeration (Iterator<Binding> e)
{
_delegate = e;
}
public void close()
throws NamingException
{
}
public boolean hasMore ()
throws NamingException
{
return _delegate.hasNext();
}
public Binding next()
throws NamingException
{
Binding b = (Binding)_delegate.next();
return new Binding (b.getName(), b.getClassName(), b.getObject(), true);
}
public boolean hasMoreElements()
{
return _delegate.hasNext();
}
public Binding nextElement()
{
Binding b = (Binding)_delegate.next();
return new Binding (b.getName(), b.getClassName(), b.getObject(),true);
}
}

View File

@ -0,0 +1,69 @@
// ========================================================================
// Copyright (c) 2011 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.jndi;
import java.util.Iterator;
import javax.naming.Binding;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
/** NameEnumeration
* <p>Implementation of NamingEnumeration interface.
*
* <p><h4>Notes</h4>
* <p>Used for returning results of Context.list();
*
* <p><h4>Usage</h4>
*
*/
public class NameEnumeration implements NamingEnumeration<NameClassPair>
{
Iterator<Binding> _delegate;
public NameEnumeration (Iterator<Binding> e)
{
_delegate = e;
}
public void close()
throws NamingException
{
}
public boolean hasMore ()
throws NamingException
{
return _delegate.hasNext();
}
public NameClassPair next()
throws NamingException
{
Binding b = _delegate.next();
return new NameClassPair(b.getName(),b.getClassName(),true);
}
public boolean hasMoreElements()
{
return _delegate.hasNext();
}
public NameClassPair nextElement()
{
Binding b = _delegate.next();
return new NameClassPair(b.getName(),b.getClassName(),true);
}
}

View File

@ -20,7 +20,6 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -31,7 +30,6 @@ import javax.naming.InitialContext;
import javax.naming.LinkRef; import javax.naming.LinkRef;
import javax.naming.Name; import javax.naming.Name;
import javax.naming.NameAlreadyBoundException; import javax.naming.NameAlreadyBoundException;
import javax.naming.NameClassPair;
import javax.naming.NameNotFoundException; import javax.naming.NameNotFoundException;
import javax.naming.NameParser; import javax.naming.NameParser;
import javax.naming.NamingEnumeration; import javax.naming.NamingEnumeration;
@ -53,17 +51,8 @@ import org.eclipse.jetty.util.log.Logger;
* <p><h4>Notes</h4> * <p><h4>Notes</h4>
* <p>All Names are expected to be Compound, not Composite. * <p>All Names are expected to be Compound, not Composite.
* *
* <p><h4>Usage</h4> *
* <pre>
*/ */
/*
* </pre>
*
* @see
*
*
* @version 1.0
*/
public class NamingContext implements Context, Cloneable, Dumpable public class NamingContext implements Context, Cloneable, Dumpable
{ {
private final static Logger __log=NamingUtil.__log; private final static Logger __log=NamingUtil.__log;
@ -101,123 +90,6 @@ public class NamingContext implements Context, Cloneable, Dumpable
void unbind(NamingContext ctx, Binding binding); void unbind(NamingContext ctx, Binding binding);
} }
/*------------------------------------------------*/
/** NameEnumeration
* <p>Implementation of NamingEnumeration interface.
*
* <p><h4>Notes</h4>
* <p>Used for returning results of Context.list();
*
* <p><h4>Usage</h4>
* <pre>
*/
/*
* </pre>
*
* @see
*
*/
public class NameEnumeration implements NamingEnumeration<NameClassPair>
{
Iterator<Binding> _delegate;
public NameEnumeration (Iterator<Binding> e)
{
_delegate = e;
}
public void close()
throws NamingException
{
}
public boolean hasMore ()
throws NamingException
{
return _delegate.hasNext();
}
public NameClassPair next()
throws NamingException
{
Binding b = _delegate.next();
return new NameClassPair(b.getName(),b.getClassName(),true);
}
public boolean hasMoreElements()
{
return _delegate.hasNext();
}
public NameClassPair nextElement()
{
Binding b = _delegate.next();
return new NameClassPair(b.getName(),b.getClassName(),true);
}
}
/*------------------------------------------------*/
/** BindingEnumeration
* <p>Implementation of NamingEnumeration
*
* <p><h4>Notes</h4>
* <p>Used to return results of Context.listBindings();
*
* <p><h4>Usage</h4>
* <pre>
*/
/*
* </pre>
*
* @see
*
*/
public class BindingEnumeration implements NamingEnumeration<Binding>
{
Iterator<Binding> _delegate;
public BindingEnumeration (Iterator<Binding> e)
{
_delegate = e;
}
public void close()
throws NamingException
{
}
public boolean hasMore ()
throws NamingException
{
return _delegate.hasNext();
}
public Binding next()
throws NamingException
{
Binding b = (Binding)_delegate.next();
return new Binding (b.getName(), b.getClassName(), b.getObject(), true);
}
public boolean hasMoreElements()
{
return _delegate.hasNext();
}
public Binding nextElement()
{
Binding b = (Binding)_delegate.next();
return new Binding (b.getName(), b.getClassName(), b.getObject(),true);
}
}
/*------------------------------------------------*/ /*------------------------------------------------*/
/** /**
* Constructor * Constructor
@ -240,26 +112,6 @@ public class NamingContext implements Context, Cloneable, Dumpable
} }
/*------------------------------------------------*/
/**
* Creates a new <code>NamingContext</code> instance.
*
* @param env a <code>Hashtable</code> value
*/
public NamingContext (Hashtable<String,Object> env)
{
if (env != null)
_env.putAll(env);
}
/*------------------------------------------------*/
/**
* Constructor
*
*/
public NamingContext ()
{
}
/*------------------------------------------------*/ /*------------------------------------------------*/
@ -313,6 +165,22 @@ public class NamingContext implements Context, Cloneable, Dumpable
} }
public void setEnv (Hashtable<String,Object> env)
{
_env.clear();
_env.putAll(env);
}
public Map<String,Binding> getBindings ()
{
return _bindings;
}
public void setBindings(Map<String,Binding> bindings)
{
_bindings = bindings;
}
/*------------------------------------------------*/ /*------------------------------------------------*/
/** /**
@ -436,8 +304,6 @@ public class NamingContext implements Context, Cloneable, Dumpable
throw ne; throw ne;
} }
Name cname = toCanonicalName (name); Name cname = toCanonicalName (name);
if (cname == null) if (cname == null)
@ -521,7 +387,7 @@ public class NamingContext implements Context, Cloneable, Dumpable
/*------------------------------------------------*/ /*------------------------------------------------*/
/** /**
* Not supported *
* *
* @param name name of subcontext to remove * @param name name of subcontext to remove
* @exception NamingException if an error occurs * @exception NamingException if an error occurs
@ -536,7 +402,7 @@ public class NamingContext implements Context, Cloneable, Dumpable
/*------------------------------------------------*/ /*------------------------------------------------*/
/** /**
* Not supported *
* *
* @param name name of subcontext to remove * @param name name of subcontext to remove
* @exception NamingException if an error occurs * @exception NamingException if an error occurs
@ -1128,7 +994,6 @@ public class NamingContext implements Context, Cloneable, Dumpable
ctx = binding.getObject(); ctx = binding.getObject();
if (ctx instanceof Reference) if (ctx instanceof Reference)
{ {
//deference the object //deference the object
@ -1155,7 +1020,6 @@ public class NamingContext implements Context, Cloneable, Dumpable
else else
throw new NotContextException ("Object bound at "+firstComponent +" is not a Context"); throw new NotContextException ("Object bound at "+firstComponent +" is not a Context");
} }
} }
/*------------------------------------------------*/ /*------------------------------------------------*/
@ -1248,8 +1112,6 @@ public class NamingContext implements Context, Cloneable, Dumpable
public void close () public void close ()
throws NamingException throws NamingException
{ {
} }
@ -1362,7 +1224,7 @@ public class NamingContext implements Context, Cloneable, Dumpable
* @param name a <code>Name</code> value * @param name a <code>Name</code> value
* @param obj an <code>Object</code> value * @param obj an <code>Object</code> value
*/ */
protected void addBinding (Name name, Object obj) throws NameAlreadyBoundException public void addBinding (Name name, Object obj) throws NameAlreadyBoundException
{ {
String key = name.toString(); String key = name.toString();
Binding binding=new Binding (key, obj); Binding binding=new Binding (key, obj);
@ -1394,7 +1256,7 @@ public class NamingContext implements Context, Cloneable, Dumpable
* @param name a <code>Name</code> value * @param name a <code>Name</code> value
* @return a <code>Binding</code> value * @return a <code>Binding</code> value
*/ */
protected Binding getBinding (Name name) public Binding getBinding (Name name)
{ {
return (Binding) _bindings.get(name.toString()); return (Binding) _bindings.get(name.toString());
} }
@ -1407,13 +1269,13 @@ public class NamingContext implements Context, Cloneable, Dumpable
* @param name as a String * @param name as a String
* @return null or the Binding * @return null or the Binding
*/ */
protected Binding getBinding (String name) public Binding getBinding (String name)
{ {
return (Binding) _bindings.get(name); return (Binding) _bindings.get(name);
} }
/*------------------------------------------------*/ /*------------------------------------------------*/
protected void removeBinding (Name name) public void removeBinding (Name name)
{ {
String key = name.toString(); String key = name.toString();
if (__log.isDebugEnabled()) if (__log.isDebugEnabled())
@ -1455,7 +1317,7 @@ public class NamingContext implements Context, Cloneable, Dumpable
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
private boolean isLocked() public boolean isLocked()
{ {
if ((_env.get(LOCK_PROPERTY) == null) && (_env.get(UNLOCK_PROPERTY) == null)) if ((_env.get(LOCK_PROPERTY) == null) && (_env.get(UNLOCK_PROPERTY) == null))
return false; return false;

View File

@ -67,8 +67,7 @@ public class javaRootURLContext implements Context
try try
{ {
__javaNameParser = new javaNameParser(); __javaNameParser = new javaNameParser();
__nameRoot = new NamingContext(); __nameRoot = new NamingContext(null,null,null,__javaNameParser);
__nameRoot.setNameParser(__javaNameParser);
StringRefAddr parserAddr = new StringRefAddr("parser", __javaNameParser.getClass().getName()); StringRefAddr parserAddr = new StringRefAddr("parser", __javaNameParser.getClass().getName());

View File

@ -12,11 +12,19 @@
// ======================================================================== // ========================================================================
package org.eclipse.jetty.jndi.java; package org.eclipse.jetty.jndi.java;
import java.util.Hashtable;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.naming.Name; import javax.naming.Name;
import javax.naming.NameNotFoundException; import javax.naming.NameNotFoundException;
import javax.naming.NameParser; import javax.naming.NameParser;
import javax.naming.NamingException;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.StringRefAddr;
import javax.naming.spi.ObjectFactory;
import org.eclipse.jetty.jndi.NamingUtil; import org.eclipse.jetty.jndi.NamingUtil;
import org.junit.After; import org.junit.After;
@ -31,6 +39,66 @@ import static org.junit.Assert.fail;
*/ */
public class TestLocalJNDI public class TestLocalJNDI
{ {
public static class FruitFactory implements ObjectFactory
{
public FruitFactory()
{
}
public Object getObjectInstance(Object obj, Name name, Context ctx, Hashtable env) throws Exception
{
if (!env.containsKey("flavour"))
throw new Exception ("No flavour!");
if (obj instanceof Reference)
{
Reference ref = (Reference)obj;
if (ref.getClassName().equals(Fruit.class.getName()))
{
RefAddr addr = ref.get("fruit");
if (addr != null)
{
return new Fruit((String)addr.getContent());
}
}
}
return null;
}
}
public static class Fruit implements Referenceable
{
String fruit;
public Fruit(String f)
{
fruit = f;
}
public Reference getReference() throws NamingException
{
return new Reference(
Fruit.class.getName(),
new StringRefAddr("fruit", fruit),
FruitFactory.class.getName(),
null); // Factory location
}
public String toString()
{
return fruit;
}
}
@After @After
public void tearDown() throws Exception public void tearDown() throws Exception
{ {
@ -38,6 +106,85 @@ public class TestLocalJNDI
ic.destroySubcontext("a"); ic.destroySubcontext("a");
} }
@Test
public void testLocalReferenceable() throws Exception
{
Hashtable<String,String> env1 = new Hashtable<String,String>();
env1.put("flavour", "orange");
InitialContext ic1 = new InitialContext(env1);
ic1.bind("valencia", new Fruit("orange"));
Object o = ic1.lookup("valencia");
Hashtable<String,String> env2 = new Hashtable<String,String>();
InitialContext ic2 = new InitialContext(env2);
try
{
o = ic2.lookup("valencia");
fail("Constructed object from reference without correct environment");
}
catch (Exception e)
{
assertEquals("No flavour!", e.getMessage());
}
}
@Test
public void testLocalEnvironment() throws Exception
{
Hashtable<String,String> env1 = new Hashtable<String,String>();
env1.put("make", "holden");
env1.put("model", "commodore");
Object car1 = new Object();
InitialContext ic = new InitialContext(env1);
ic.bind("car1", car1);
assertNotNull(ic.lookup("car1"));
assertEquals(car1, ic.lookup("car1"));
Context carz = ic.createSubcontext("carz");
assertNotNull(carz);
Hashtable ht = carz.getEnvironment();
assertNotNull(ht);
assertEquals("holden", ht.get("make"));
assertEquals("commodore", ht.get("model"));
Hashtable<String,String> env2 = new Hashtable<String,String>();
env2.put("flavour", "strawberry");
InitialContext ic2 = new InitialContext(env2);
assertEquals(car1, ic2.lookup("car1"));
Context c = (Context)ic2.lookup("carz");
assertNotNull(c);
ht = c.getEnvironment();
assertEquals("holden", ht.get("make"));
assertEquals("commodore", ht.get("model"));
Context icecreamz = ic2.createSubcontext("icecreamz");
ht = icecreamz.getEnvironment();
assertNotNull(ht);
assertEquals("strawberry", ht.get("flavour"));
Context hatchbackz = ic2.createSubcontext("carz/hatchbackz");
assertNotNull(hatchbackz);
ht = hatchbackz.getEnvironment();
assertNotNull(ht);
assertEquals("holden", ht.get("make"));
assertEquals("commodore", ht.get("model"));
assertEquals(null, ht.get("flavour"));
c = (Context)ic.lookup("carz/hatchbackz");
assertNotNull(c);
assertEquals(hatchbackz, c);
}
@Test @Test
public void testLocal () throws Exception public void testLocal () throws Exception
{ {

View File

@ -5,9 +5,11 @@ import java.util.IllegalFormatCodePointException;
public abstract class Utf8Appendable public abstract class Utf8Appendable
{ {
private final char REPLACEMENT = '\ufffd';
protected final Appendable _appendable; protected final Appendable _appendable;
protected int _more; protected int _expectedContinuationBytes;
protected int _bits; protected int _codePoint;
protected int _minCodePoint;
public Utf8Appendable(Appendable appendable) public Utf8Appendable(Appendable appendable)
{ {
@ -63,91 +65,112 @@ public abstract class Utf8Appendable
protected void appendByte(byte b) throws IOException protected void appendByte(byte b) throws IOException
{ {
// Check for invalid bytes
if (b==(byte)0xc0 || b==(byte)0xc1 || (int)b>=0xf5)
{
_appendable.append(REPLACEMENT);
_expectedContinuationBytes=0;
_codePoint=0;
throw new NotUtf8Exception();
}
// Is it plain ASCII?
if (b>=0) if (b>=0)
{ {
if (_more>0) // Were we expecting a continuation byte?
if (_expectedContinuationBytes>0)
{ {
_appendable.append('?'); _appendable.append(REPLACEMENT);
_more=0; _expectedContinuationBytes=0;
_bits=0; _codePoint=0;
throw new NotUtf8Exception(); throw new NotUtf8Exception();
} }
else else
_appendable.append((char)(0x7f&b)); _appendable.append((char)(0x7f&b));
} }
else if (_more==0) // Else is this a start byte
{ else if (_expectedContinuationBytes==0)
if ((b&0xc0)!=0xc0)
{
// 10xxxxxx
_appendable.append('?');
_more=0;
_bits=0;
throw new NotUtf8Exception();
}
else
{ {
if ((b & 0xe0) == 0xc0) if ((b & 0xe0) == 0xc0)
{ {
//110xxxxx //110xxxxx
_more=1; _expectedContinuationBytes=1;
_bits=b&0x1f; _codePoint=b&0x1f;
_minCodePoint=0x80;
} }
else if ((b & 0xf0) == 0xe0) else if ((b & 0xf0) == 0xe0)
{ {
//1110xxxx //1110xxxx
_more=2; _expectedContinuationBytes=2;
_bits=b&0x0f; _codePoint=b&0x0f;
_minCodePoint=0x800;
} }
else if ((b & 0xf8) == 0xf0) else if ((b & 0xf8) == 0xf0)
{ {
//11110xxx //11110xxx
_more=3; _expectedContinuationBytes=3;
_bits=b&0x07; _codePoint=b&0x07;
_minCodePoint=0x10000;
} }
else if ((b & 0xfc) == 0xf8) else if ((b & 0xfc) == 0xf8)
{ {
//111110xx //111110xx
_more=4; _expectedContinuationBytes=4;
_bits=b&0x03; _codePoint=b&0x03;
_minCodePoint=0x200000;
} }
else if ((b & 0xfe) == 0xfc) else if ((b & 0xfe) == 0xfc)
{ {
//1111110x //1111110x
_more=5; _expectedContinuationBytes=5;
_bits=b&0x01; _codePoint=b&0x01;
_minCodePoint=0x400000;
} }
else else
{ {
_appendable.append(REPLACEMENT);
_expectedContinuationBytes=0;
_codePoint=0;
throw new NotUtf8Exception(); throw new NotUtf8Exception();
} }
} }
} // else is this a continuation character
else else if ((b&0xc0)==0x80)
{
if ((b&0xc0)==0xc0)
{ // 11??????
_appendable.append('?');
_more=0;
_bits=0;
throw new NotUtf8Exception();
}
else
{ {
// 10xxxxxx // 10xxxxxx
_bits=(_bits<<6)|(b&0x3f); _codePoint=(_codePoint<<6)|(b&0x3f);
if (--_more==0)
// was that the last continuation?
if (--_expectedContinuationBytes==0)
{ {
if (_bits>=0xD800 && _bits<=0xDFFF) // If this a valid unicode point?
if (_codePoint<_minCodePoint || (_codePoint>=0xD800 && _codePoint<=0xDFFF))
{
_appendable.append(REPLACEMENT);
_expectedContinuationBytes=0;
_codePoint=0;
throw new NotUtf8Exception(); throw new NotUtf8Exception();
_appendable.append(new String(Character.toChars(_bits))); }
_minCodePoint=0;
char[] chars = Character.toChars(_codePoint);
for (char c : chars)
_appendable.append(c);
} }
} }
// Else this is not a continuation character
else
{
// ! 10xxxxxx
_appendable.append(REPLACEMENT);
_expectedContinuationBytes=0;
_codePoint=0;
throw new NotUtf8Exception();
} }
} }
public static class NotUtf8Exception extends IllegalStateException public static class NotUtf8Exception extends IllegalArgumentException
{ {
public NotUtf8Exception() public NotUtf8Exception()
{ {

View File

@ -53,13 +53,13 @@ public class Utf8StringBuffer extends Utf8Appendable
public void reset() public void reset()
{ {
_buffer.setLength(0); _buffer.setLength(0);
_more=0; _expectedContinuationBytes=0;
_bits=0; _codePoint=0;
} }
public StringBuffer getStringBuffer() public StringBuffer getStringBuffer()
{ {
if (_more!=0) if (_expectedContinuationBytes!=0)
throw new NotUtf8Exception(); throw new NotUtf8Exception();
return _buffer; return _buffer;
} }
@ -67,7 +67,7 @@ public class Utf8StringBuffer extends Utf8Appendable
@Override @Override
public String toString() public String toString()
{ {
if (_more!=0) if (_expectedContinuationBytes!=0)
throw new NotUtf8Exception(); throw new NotUtf8Exception();
return _buffer.toString(); return _buffer.toString();
} }

View File

@ -52,13 +52,13 @@ public class Utf8StringBuilder extends Utf8Appendable
public void reset() public void reset()
{ {
_buffer.setLength(0); _buffer.setLength(0);
_more=0; _expectedContinuationBytes=0;
_bits=0; _codePoint=0;
} }
public StringBuilder getStringBuilder() public StringBuilder getStringBuilder()
{ {
if (_more!=0) if (_expectedContinuationBytes!=0)
throw new NotUtf8Exception(); throw new NotUtf8Exception();
return _buffer; return _buffer;
} }
@ -66,7 +66,7 @@ public class Utf8StringBuilder extends Utf8Appendable
@Override @Override
public String toString() public String toString()
{ {
if (_more!=0) if (_expectedContinuationBytes!=0)
throw new NotUtf8Exception(); throw new NotUtf8Exception();
return _buffer.toString(); return _buffer.toString();
} }

View File

@ -7,6 +7,8 @@ import java.util.List;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.OS; import org.eclipse.jetty.toolchain.test.OS;
import org.eclipse.jetty.util.Scanner.Notification; import org.eclipse.jetty.util.Scanner.Notification;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -25,10 +27,8 @@ public class ScannerTest
@BeforeClass @BeforeClass
public static void setUpBeforeClass() throws Exception public static void setUpBeforeClass() throws Exception
{ {
_directory = File.createTempFile("scan",""); _directory = MavenTestingUtils.getTargetTestingDir(ScannerTest.class.getSimpleName());
_directory.delete(); FS.ensureEmpty(_directory);
_directory.mkdir();
_directory.deleteOnExit();
_scanner = new Scanner(); _scanner = new Scanner();
_scanner.addScanDir(_directory); _scanner.addScanDir(_directory);
@ -88,7 +88,7 @@ public class ScannerTest
public void testAddedChangeRemove() throws Exception public void testAddedChangeRemove() throws Exception
{ {
// TODO needs to be further investigated // TODO needs to be further investigated
Assume.assumeTrue(!OS.IS_WINDOWS && !OS.IS_OSX); Assume.assumeTrue(!OS.IS_WINDOWS);
touch("a0"); touch("a0");
@ -96,7 +96,7 @@ public class ScannerTest
_scanner.scan(); _scanner.scan();
_scanner.scan(); _scanner.scan();
Event event = _queue.poll(); Event event = _queue.poll();
Assert.assertTrue(event!=null); Assert.assertNotNull("Event should not be null", event);
Assert.assertEquals(_directory+"/a0",event._filename); Assert.assertEquals(_directory+"/a0",event._filename);
Assert.assertEquals(Notification.ADDED,event._notification); Assert.assertEquals(Notification.ADDED,event._notification);
@ -197,7 +197,7 @@ public class ScannerTest
public void testSizeChange() throws Exception public void testSizeChange() throws Exception
{ {
// TODO needs to be further investigated // TODO needs to be further investigated
Assume.assumeTrue(!OS.IS_WINDOWS && !OS.IS_OSX); Assume.assumeTrue(!OS.IS_WINDOWS);
touch("tsc0"); touch("tsc0");
_scanner.scan(); _scanner.scan();

View File

@ -48,9 +48,9 @@ public class Utf8StringBufferTest
buffer.toString(); buffer.toString();
assertTrue(false); assertTrue(false);
} }
catch(IllegalStateException e) catch(Utf8Appendable.NotUtf8Exception e)
{ {
assertTrue(e.toString().indexOf("!UTF-8")>=0); assertTrue(true);
} }
} }
@ -70,11 +70,11 @@ public class Utf8StringBufferTest
buffer.append(bytes[i]); buffer.append(bytes[i]);
assertTrue(false); assertTrue(false);
} }
catch(IllegalStateException e) catch(Utf8Appendable.NotUtf8Exception e)
{ {
assertTrue(e.toString().indexOf("!UTF-8")>=0); assertTrue(e.toString().indexOf("!UTF-8")>=0);
} }
assertEquals("abc?",buffer.toString()); assertEquals("abc\ufffd",buffer.toString());
} }
@Test @Test

View File

@ -25,19 +25,44 @@ public class Utf8StringBuilderTest
public void testInvalid() public void testInvalid()
throws Exception throws Exception
{ {
Utf8StringBuilder buffer = new Utf8StringBuilder(); String[] invalids = {
buffer.append((byte)0xED); "c0af",
buffer.append((byte)0xA0); "EDA080",
"f08080af",
"f8808080af",
"e080af",
"F4908080",
"fbbfbfbfbf"
};
for (String i : invalids)
{
byte[] bytes = TypeUtil.fromHexString(i);
/* Test what JVM does
try try
{ {
buffer.append((byte)0x80); String s = new String(bytes,0,bytes.length,"UTF-8");
assertTrue(false); System.err.println(i+": "+s);
} }
catch(Utf8Appendable.NotUtf8Exception e) catch(Exception e)
{ {
assertTrue(true); System.err.println(i+": "+e);
} }
*/
try
{
Utf8StringBuilder buffer = new Utf8StringBuilder();
buffer.append(bytes,0,bytes.length);
assertEquals(i,"not expected",buffer.toString());
}
catch(IllegalArgumentException e)
{
assertTrue(i,true);
}
}
} }
@Test @Test
@ -69,7 +94,7 @@ public class Utf8StringBuilderTest
buffer.toString(); buffer.toString();
assertTrue(false); assertTrue(false);
} }
catch(IllegalStateException e) catch(Utf8Appendable.NotUtf8Exception e)
{ {
assertTrue(e.toString().indexOf("!UTF-8")>=0); assertTrue(e.toString().indexOf("!UTF-8")>=0);
} }
@ -91,11 +116,11 @@ public class Utf8StringBuilderTest
buffer.append(bytes[i]); buffer.append(bytes[i]);
assertTrue(false); assertTrue(false);
} }
catch(IllegalStateException e) catch(Utf8Appendable.NotUtf8Exception e)
{ {
assertTrue(e.toString().indexOf("!UTF-8")>=0); assertTrue(true);
} }
assertEquals("abc?", buffer.toString()); assertEquals("abc\ufffd", buffer.toString());
} }
@ -106,6 +131,7 @@ public class Utf8StringBuilderTest
String source="\uD842\uDF9F"; String source="\uD842\uDF9F";
byte[] bytes=source.getBytes("UTF-8"); byte[] bytes=source.getBytes("UTF-8");
// System.err.println(TypeUtil.toHexString(bytes));
String jvmcheck = new String(bytes,0,bytes.length,"UTF-8"); String jvmcheck = new String(bytes,0,bytes.length,"UTF-8");
assertEquals(source,jvmcheck); assertEquals(source,jvmcheck);

View File

@ -30,6 +30,7 @@ import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint; import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.util.B64Code; import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.Utf8Appendable; import org.eclipse.jetty.util.Utf8Appendable;
import org.eclipse.jetty.util.Utf8StringBuilder; import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
@ -827,19 +828,21 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
return; return;
} }
} }
catch(ThreadDeath th)
{
throw th;
}
catch(Utf8Appendable.NotUtf8Exception notUtf8) catch(Utf8Appendable.NotUtf8Exception notUtf8)
{ {
LOG.warn("{} for {}",notUtf8,_endp); LOG.warn("{} for {}",notUtf8,_endp);
LOG.debug(notUtf8); LOG.debug(notUtf8);
errorClose(WebSocketConnectionD13.CLOSE_BAD_PAYLOAD,"Invalid UTF-8"); errorClose(WebSocketConnectionD13.CLOSE_BAD_PAYLOAD,"Invalid UTF-8");
} }
catch(ThreadDeath th) catch(Throwable probablyNotUtf8)
{ {
throw th; LOG.warn("{} for {}",probablyNotUtf8,_endp);
} LOG.debug(probablyNotUtf8);
catch(Throwable th) errorClose(WebSocketConnectionD13.CLOSE_BAD_PAYLOAD,"Invalid Payload: "+probablyNotUtf8);
{
LOG.warn(th);
} }
} }

View File

@ -52,6 +52,8 @@ public class TestClient implements WebSocket.OnFrame
public void onOpen(Connection connection) public void onOpen(Connection connection)
{ {
if (_verbose)
System.err.printf("%s#onHandshake %s %s\n",this.getClass().getSimpleName(),connection,connection.getClass().getSimpleName());
} }
public void onClose(int closeCode, String message) public void onClose(int closeCode, String message)
@ -141,7 +143,7 @@ public class TestClient implements WebSocket.OnFrame
byte op=(byte)(off==0?opcode:WebSocketConnectionD13.OP_CONTINUATION); byte op=(byte)(off==0?opcode:WebSocketConnectionD13.OP_CONTINUATION);
if (_verbose) if (_verbose)
System.err.printf("%s#addFrame %s|%s %s\n",this.getClass().getSimpleName(),TypeUtil.toHexString(flags),TypeUtil.toHexString(op),TypeUtil.toHexString(data,off,len)); System.err.printf("%s#sendFrame %s|%s %s\n",this.getClass().getSimpleName(),TypeUtil.toHexString(flags),TypeUtil.toHexString(op),TypeUtil.toHexString(data,off,len));
_connection.sendFrame(flags,op,data,off,len); _connection.sendFrame(flags,op,data,off,len);
@ -168,6 +170,7 @@ public class TestClient implements WebSocket.OnFrame
System.err.println(" -p|--port PORT (default 8080)"); System.err.println(" -p|--port PORT (default 8080)");
System.err.println(" -b|--binary"); System.err.println(" -b|--binary");
System.err.println(" -v|--verbose"); System.err.println(" -v|--verbose");
System.err.println(" -q|--quiet");
System.err.println(" -c|--count n (default 10)"); System.err.println(" -c|--count n (default 10)");
System.err.println(" -s|--size n (default 64)"); System.err.println(" -s|--size n (default 64)");
System.err.println(" -f|--fragment n (default 4000) "); System.err.println(" -f|--fragment n (default 4000) ");
@ -226,6 +229,8 @@ public class TestClient implements WebSocket.OnFrame
try try
{ {
__start=System.currentTimeMillis(); __start=System.currentTimeMillis();
protocol=protocol==null?"echo":protocol;
for (int i=0;i<clients;i++) for (int i=0;i<clients;i++)
{ {
client[i]=new TestClient(host,port,protocol==null?null:protocol,60000); client[i]=new TestClient(host,port,protocol==null?null:protocol,60000);
@ -233,7 +238,7 @@ public class TestClient implements WebSocket.OnFrame
} }
System.out.println("Jetty WebSocket PING "+host+":"+port+ System.out.println("Jetty WebSocket PING "+host+":"+port+
" ("+ new InetSocketAddress(host,port)+") "+clients+" clients"); " ("+ new InetSocketAddress(host,port)+") "+clients+" clients "+protocol);
for (int p=0;p<count;p++) for (int p=0;p<count;p++)
@ -272,9 +277,11 @@ public class TestClient implements WebSocket.OnFrame
long duration=System.currentTimeMillis()-__start; long duration=System.currentTimeMillis()-__start;
System.out.println("--- "+host+" websocket ping statistics using "+clients+" connection"+(clients>1?"s":"")+" ---"); System.out.println("--- "+host+" websocket ping statistics using "+clients+" connection"+(clients>1?"s":"")+" ---");
System.out.println(__framesSent+" frames transmitted, "+__framesReceived+" received, "+ System.out.printf("%d/%d frames sent/recv, %d/%d mesg sent/recv, time %dms %dm/s %.2fbps%n",
__messagesSent+" messages transmitted, "+__messagesReceived+" received, "+ __framesSent,__framesReceived.get(),
"time "+duration+"ms "+ (1000L*__messagesReceived.get()/duration)+" req/s"); __messagesSent,__messagesReceived.get(),
duration,(1000L*__messagesReceived.get()/duration),
1000.0D*__messagesReceived.get()*8*size/duration/1024/1024);
System.out.printf("rtt min/ave/max = %.3f/%.3f/%.3f ms\n",__minDuration.get()/1000000.0,__messagesReceived.get()==0?0.0:(__totalTime.get()/__messagesReceived.get()/1000000.0),__maxDuration.get()/1000000.0); System.out.printf("rtt min/ave/max = %.3f/%.3f/%.3f ms\n",__minDuration.get()/1000000.0,__messagesReceived.get()==0?0.0:(__totalTime.get()/__messagesReceived.get()/1000000.0),__maxDuration.get()/1000000.0);
__clientFactory.stop(); __clientFactory.stop();

View File

@ -107,7 +107,7 @@ public class TestServer extends Server
public void onOpen(Connection connection) public void onOpen(Connection connection)
{ {
if (_verbose) if (_verbose)
System.err.printf("%s#onOpen %s\n",this.getClass().getSimpleName(),connection); System.err.printf("%s#onOpen %s %s\n",this.getClass().getSimpleName(),connection,connection.getProtocol());
} }
public void onHandshake(FrameConnection connection) public void onHandshake(FrameConnection connection)

View File

@ -3,7 +3,7 @@
<parent> <parent>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-parent</artifactId> <artifactId>jetty-parent</artifactId>
<version>18</version> <version>19-SNAPSHOT</version>
</parent> </parent>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-project</artifactId> <artifactId>jetty-project</artifactId>

View File

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