Merge branch 'master', remote-tracking branch 'origin/master'

This commit is contained in:
Jesse McConnell 2011-09-15 07:56:46 -05:00
commit 1e8b4eb9ed
30 changed files with 1498 additions and 501 deletions

23
.gitignore vendored
View File

@ -1,14 +1,33 @@
target/
# eclipse
.classpath
.project
.settings
# maven
target/
*/src/main/java/META-INF/
.pmd
# common junk
*.log
*.swp
*.diff
*.patch
# intellij
*.iml
*.ipr
*.iws
.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>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all-server</artifactId>
<name>Jetty :: Aggregate :: All Server</name>
<properties>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,6 @@
<version>7.5.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-webapp</artifactId>
<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.TimeUnit;
import org.eclipse.jetty.io.ConnectedEndPoint;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
@ -450,6 +449,9 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
{
_selecting=Thread.currentThread();
final Selector selector=_selector;
// Stopped concurrently ?
if (selector == null)
return;
// Make any key changes required
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.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -31,7 +30,6 @@ import javax.naming.InitialContext;
import javax.naming.LinkRef;
import javax.naming.Name;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NameClassPair;
import javax.naming.NameNotFoundException;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
@ -53,17 +51,8 @@ import org.eclipse.jetty.util.log.Logger;
* <p><h4>Notes</h4>
* <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
{
private final static Logger __log=NamingUtil.__log;
@ -101,123 +90,6 @@ public class NamingContext implements Context, Cloneable, Dumpable
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
@ -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;
}
Name cname = toCanonicalName (name);
if (cname == null)
@ -521,7 +387,7 @@ public class NamingContext implements Context, Cloneable, Dumpable
/*------------------------------------------------*/
/**
* Not supported
*
*
* @param name name of subcontext to remove
* @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
* @exception NamingException if an error occurs
@ -1128,7 +994,6 @@ public class NamingContext implements Context, Cloneable, Dumpable
ctx = binding.getObject();
if (ctx instanceof Reference)
{
//deference the object
@ -1155,7 +1020,6 @@ public class NamingContext implements Context, Cloneable, Dumpable
else
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 ()
throws NamingException
{
}
@ -1362,7 +1224,7 @@ public class NamingContext implements Context, Cloneable, Dumpable
* @param name a <code>Name</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();
Binding binding=new Binding (key, obj);
@ -1394,7 +1256,7 @@ public class NamingContext implements Context, Cloneable, Dumpable
* @param name a <code>Name</code> value
* @return a <code>Binding</code> value
*/
protected Binding getBinding (Name name)
public Binding getBinding (Name name)
{
return (Binding) _bindings.get(name.toString());
}
@ -1407,13 +1269,13 @@ public class NamingContext implements Context, Cloneable, Dumpable
* @param name as a String
* @return null or the Binding
*/
protected Binding getBinding (String name)
public Binding getBinding (String name)
{
return (Binding) _bindings.get(name);
}
/*------------------------------------------------*/
protected void removeBinding (Name name)
public void removeBinding (Name name)
{
String key = name.toString();
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))
return false;

View File

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

View File

@ -12,11 +12,19 @@
// ========================================================================
package org.eclipse.jetty.jndi.java;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.Name;
import javax.naming.NameNotFoundException;
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.junit.After;
@ -31,6 +39,66 @@ import static org.junit.Assert.fail;
*/
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
public void tearDown() throws Exception
{
@ -38,6 +106,85 @@ public class TestLocalJNDI
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
public void testLocal () throws Exception
{

View File

@ -3,7 +3,7 @@
<groupId>org.eclipse.jetty.osgi</groupId>
<artifactId>jetty-osgi-project</artifactId>
<!--version>7.5.0.v20110901</version-->
<version>7.5.1-SNAPSHOT</version>
<version>7.5.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -12,6 +12,7 @@
<name>Jetty :: OSGi :: Servletbridge</name>
<description>Jetty OSGi Servletbridge webapp</description>
<packaging>war</packaging>
<properties><eclipse.pde>false</eclipse.pde></properties>
<dependencies>
<dependency>
<groupId>org.eclipse.equinox</groupId>
@ -38,4 +39,15 @@
<url>http://intalio.org/public/maven2</url>
</repository>
</repositories>
<build>
<plugins><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<pde>false</pde>
</configuration>
</plugin></plugins>
</build>
</project>

View File

@ -0,0 +1,48 @@
// ========================================================================
// Copyright (c) 2010-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.osgi.servletbridge;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.equinox.servletbridge.BridgeServlet;
/**
* Override the BridgeServlet to report on whether equinox is actually started or not
* in case it is started asynchroneously.
*
* @author hmalphettes
*/
public class BridgeServletExtended extends BridgeServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
if (FrameworkLauncherExtended.ASYNCH_START_IN_PROGRESS != null
&& req.getMethod().equals("GET")) {
if (FrameworkLauncherExtended.ASYNCH_START_IN_PROGRESS) {
resp.getWriter().append("Equinox is currently starting...\n");
return;
} else if (FrameworkLauncherExtended.ASYNCH_START_FAILURE != null) {
resp.getWriter().append("Equinox failed to start:\n");
FrameworkLauncherExtended.ASYNCH_START_FAILURE.printStackTrace(resp.getWriter());
return;
}
}
super.service(req, resp);
}
}

View File

@ -50,6 +50,44 @@ public class FrameworkLauncherExtended extends FrameworkLauncher
private boolean deployedInPlace = false;
private URL resourceBaseAsURL = null;
protected static Boolean ASYNCH_START_IN_PROGRESS;
protected static Throwable ASYNCH_START_FAILURE = null;
/**
* If the start is asynch we do it in a different thread and return immediately.
*/
@Override
public synchronized void start() {
if (ASYNCH_START_IN_PROGRESS == null && "true".equals(super.config.getInitParameter("asyncStart"))) {
final ClassLoader webappCl = Thread.currentThread().getContextClassLoader();
Thread th = new Thread() {
public void run() {
Thread.currentThread().setContextClassLoader(webappCl);
System.out.println("Jetty-Nested: Starting equinox asynchroneously.");
FrameworkLauncherExtended.this.start();
System.out.println("Jetty-Nested: Finished starting equinox asynchroneously.");
}
};
ASYNCH_START_IN_PROGRESS = true;
try {
th.start();
} catch (Throwable t) {
ASYNCH_START_FAILURE = t;
if (t instanceof RuntimeException) {
throw (RuntimeException)t;
} else {
throw new RuntimeException("Equinox failed to start", t);
}
} finally {
ASYNCH_START_IN_PROGRESS = false;
}
} else {
System.out.println("Jetty-Nested: Starting equinox synchroneously.");
super.start();
System.out.println("Jetty-Nested: Finished starting equinox synchroneously.");
}
}
/**
* try to find the resource base for this webapp by looking for the launcher initialization file.
*/
@ -248,7 +286,10 @@ public class FrameworkLauncherExtended extends FrameworkLauncher
String logback = System.getProperty("logback.configurationFile");
if (logback == null)
{
File etcLogback = new File(jettyHome,"etc/logback.xml");
File etcLogback = new File(jettyHome,"etc/logback-nested.xml");
if (!etcLogback.exists()) {
etcLogback = new File(jettyHome,"etc/logback.xml");
}
if (etcLogback.exists())
{
System.setProperty("logback.configurationFile",etcLogback.getAbsolutePath());

View File

@ -5,13 +5,19 @@
<servlet-name>proxy</servlet-name>
<display-name>Transparent Proxy Servlet and Equinox Framework Controller</display-name>
<description>Transparent Proxy Servlet and Equinox Framework Controller</description>
<servlet-class>org.eclipse.equinox.servletbridge.BridgeServlet</servlet-class>
<servlet-class>org.eclipse.jetty.osgi.servletbridge.BridgeServletExtended</servlet-class>
<!-- Point to a folder where an equinox installation exists.
When this parameter is defined, that equinox installation is launched in place.
The parameter can also be passed as a system property. -->
<init-param>
<param-name>osgi.install.area</param-name>
<param-value>/WEB-INF/eclipse</param-value>
</init-param>
<!-- Start equinox in a different thread and display a simple
a simple status message until it is started. -->
<init-param>
<param-name>asyncStart</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>commandline</param-name>

View File

@ -5,9 +5,11 @@ import java.util.IllegalFormatCodePointException;
public abstract class Utf8Appendable
{
private final char REPLACEMENT = '\ufffd';
protected final Appendable _appendable;
protected int _more;
protected int _bits;
protected int _expectedContinuationBytes;
protected int _codePoint;
protected int _minCodePoint;
public Utf8Appendable(Appendable appendable)
{
@ -63,91 +65,112 @@ public abstract class Utf8Appendable
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 (_more>0)
// Were we expecting a continuation byte?
if (_expectedContinuationBytes>0)
{
_appendable.append('?');
_more=0;
_bits=0;
_appendable.append(REPLACEMENT);
_expectedContinuationBytes=0;
_codePoint=0;
throw new NotUtf8Exception();
}
else
_appendable.append((char)(0x7f&b));
}
else if (_more==0)
{
if ((b&0xc0)!=0xc0)
{
// 10xxxxxx
_appendable.append('?');
_more=0;
_bits=0;
throw new NotUtf8Exception();
}
else
// Else is this a start byte
else if (_expectedContinuationBytes==0)
{
if ((b & 0xe0) == 0xc0)
{
//110xxxxx
_more=1;
_bits=b&0x1f;
_expectedContinuationBytes=1;
_codePoint=b&0x1f;
_minCodePoint=0x80;
}
else if ((b & 0xf0) == 0xe0)
{
//1110xxxx
_more=2;
_bits=b&0x0f;
_expectedContinuationBytes=2;
_codePoint=b&0x0f;
_minCodePoint=0x800;
}
else if ((b & 0xf8) == 0xf0)
{
//11110xxx
_more=3;
_bits=b&0x07;
_expectedContinuationBytes=3;
_codePoint=b&0x07;
_minCodePoint=0x10000;
}
else if ((b & 0xfc) == 0xf8)
{
//111110xx
_more=4;
_bits=b&0x03;
_expectedContinuationBytes=4;
_codePoint=b&0x03;
_minCodePoint=0x200000;
}
else if ((b & 0xfe) == 0xfc)
{
//1111110x
_more=5;
_bits=b&0x01;
_expectedContinuationBytes=5;
_codePoint=b&0x01;
_minCodePoint=0x400000;
}
else
{
_appendable.append(REPLACEMENT);
_expectedContinuationBytes=0;
_codePoint=0;
throw new NotUtf8Exception();
}
}
}
else
{
if ((b&0xc0)==0xc0)
{ // 11??????
_appendable.append('?');
_more=0;
_bits=0;
throw new NotUtf8Exception();
}
else
// else is this a continuation character
else if ((b&0xc0)==0x80)
{
// 10xxxxxx
_bits=(_bits<<6)|(b&0x3f);
if (--_more==0)
_codePoint=(_codePoint<<6)|(b&0x3f);
// 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();
_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()
{

View File

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

View File

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

View File

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

View File

@ -48,9 +48,9 @@ public class Utf8StringBufferTest
buffer.toString();
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]);
assertTrue(false);
}
catch(IllegalStateException e)
catch(Utf8Appendable.NotUtf8Exception e)
{
assertTrue(e.toString().indexOf("!UTF-8")>=0);
}
assertEquals("abc?",buffer.toString());
assertEquals("abc\ufffd",buffer.toString());
}
@Test

View File

@ -25,19 +25,44 @@ public class Utf8StringBuilderTest
public void testInvalid()
throws Exception
{
Utf8StringBuilder buffer = new Utf8StringBuilder();
buffer.append((byte)0xED);
buffer.append((byte)0xA0);
String[] invalids = {
"c0af",
"EDA080",
"f08080af",
"f8808080af",
"e080af",
"F4908080",
"fbbfbfbfbf"
};
for (String i : invalids)
{
byte[] bytes = TypeUtil.fromHexString(i);
/* Test what JVM does
try
{
buffer.append((byte)0x80);
assertTrue(false);
String s = new String(bytes,0,bytes.length,"UTF-8");
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
@ -69,7 +94,7 @@ public class Utf8StringBuilderTest
buffer.toString();
assertTrue(false);
}
catch(IllegalStateException e)
catch(Utf8Appendable.NotUtf8Exception e)
{
assertTrue(e.toString().indexOf("!UTF-8")>=0);
}
@ -91,11 +116,11 @@ public class Utf8StringBuilderTest
buffer.append(bytes[i]);
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";
byte[] bytes=source.getBytes("UTF-8");
// System.err.println(TypeUtil.toHexString(bytes));
String jvmcheck = new String(bytes,0,bytes.length,"UTF-8");
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.util.B64Code;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.Utf8Appendable;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.util.log.Log;
@ -827,19 +828,21 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
return;
}
}
catch(ThreadDeath th)
{
throw th;
}
catch(Utf8Appendable.NotUtf8Exception notUtf8)
{
LOG.warn("{} for {}",notUtf8,_endp);
LOG.debug(notUtf8);
errorClose(WebSocketConnectionD13.CLOSE_BAD_PAYLOAD,"Invalid UTF-8");
}
catch(ThreadDeath th)
catch(Throwable probablyNotUtf8)
{
throw th;
}
catch(Throwable th)
{
LOG.warn(th);
LOG.warn("{} for {}",probablyNotUtf8,_endp);
LOG.debug(probablyNotUtf8);
errorClose(WebSocketConnectionD13.CLOSE_BAD_PAYLOAD,"Invalid Payload: "+probablyNotUtf8);
}
}

View File

@ -52,6 +52,8 @@ public class TestClient implements WebSocket.OnFrame
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)
@ -141,7 +143,7 @@ public class TestClient implements WebSocket.OnFrame
byte op=(byte)(off==0?opcode:WebSocketConnectionD13.OP_CONTINUATION);
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);
@ -168,6 +170,7 @@ public class TestClient implements WebSocket.OnFrame
System.err.println(" -p|--port PORT (default 8080)");
System.err.println(" -b|--binary");
System.err.println(" -v|--verbose");
System.err.println(" -q|--quiet");
System.err.println(" -c|--count n (default 10)");
System.err.println(" -s|--size n (default 64)");
System.err.println(" -f|--fragment n (default 4000) ");
@ -226,6 +229,8 @@ public class TestClient implements WebSocket.OnFrame
try
{
__start=System.currentTimeMillis();
protocol=protocol==null?"echo":protocol;
for (int i=0;i<clients;i++)
{
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+
" ("+ new InetSocketAddress(host,port)+") "+clients+" clients");
" ("+ new InetSocketAddress(host,port)+") "+clients+" clients "+protocol);
for (int p=0;p<count;p++)
@ -272,9 +277,11 @@ public class TestClient implements WebSocket.OnFrame
long duration=System.currentTimeMillis()-__start;
System.out.println("--- "+host+" websocket ping statistics using "+clients+" connection"+(clients>1?"s":"")+" ---");
System.out.println(__framesSent+" frames transmitted, "+__framesReceived+" received, "+
__messagesSent+" messages transmitted, "+__messagesReceived+" received, "+
"time "+duration+"ms "+ (1000L*__messagesReceived.get()/duration)+" req/s");
System.out.printf("%d/%d frames sent/recv, %d/%d mesg sent/recv, time %dms %dm/s %.2fbps%n",
__framesSent,__framesReceived.get(),
__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);
__clientFactory.stop();

View File

@ -107,7 +107,7 @@ public class TestServer extends Server
public void onOpen(Connection connection)
{
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)

View File

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

View File

@ -73,7 +73,7 @@ public class TestFilter implements Filter
String to = request.getServerName();
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 ||
!to.equals("localhost")&&!to.startsWith("127.0.0.") && to.indexOf(":1")<0))
{