Merge branch 'master' into sslClose

This commit is contained in:
Greg Wilkins 2011-09-28 16:24:01 +10:00
commit d0ffa5cb1a
3 changed files with 70 additions and 112 deletions

View File

@ -1,5 +1,6 @@
jetty-7.5.2-SNAPSHOT
+ 358121 Implement new UTF8 Algorithm to UTF8Appendable.java
+ 353839 ajp component error when upload file
jetty-7.5.1.v20110908 - 08 September 2011
+ 350634 Added Resource.newResource(File)

View File

@ -91,36 +91,23 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector
public void startConnection( HttpDestination destination )
throws IOException
{
SocketChannel channel = null;
try
{
SocketChannel channel = SocketChannel.open();
channel = SocketChannel.open();
Address address = destination.isProxied() ? destination.getProxy() : destination.getAddress();
channel.socket().setTcpNoDelay(true);
if (_httpClient.isConnectBlocking())
{
channel.socket().connect(address.toSocketAddress(), _httpClient.getConnectTimeout());
channel.configureBlocking(false);
_selectorManager.register( channel, destination );
channel.socket().connect(address.toSocketAddress(), _httpClient.getConnectTimeout());
channel.configureBlocking(false);
_selectorManager.register( channel, destination );
}
else
{
channel.configureBlocking(false);
try
{
channel.connect(address.toSocketAddress());
}
catch (UnresolvedAddressException uae)
{
channel.close();
throw uae;
}
catch ( UnknownHostException uhe )
{
channel.close();
throw uhe;
}
channel.connect(address.toSocketAddress());
_selectorManager.register(channel,destination);
ConnectTimeout connectTimeout = new ConnectTimeout(channel,destination);
_httpClient.schedule(connectTimeout,_httpClient.getConnectTimeout());
@ -130,6 +117,8 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector
}
catch(IOException ex)
{
if (channel != null)
channel.close();
destination.onConnectionFailed(ex);
}
}

View File

@ -23,36 +23,39 @@ import java.net.URLClassLoader;
import java.util.StringTokenizer;
import java.util.Vector;
/**
* Class to handle CLASSPATH construction
*/
public class Classpath {
public class Classpath
{
private final Vector<File> _elements = new Vector<File>();
private final Vector<File> _elements = new Vector<File>();
public Classpath()
{}
{
}
public Classpath(String initial)
{
addClasspath(initial);
}
public File[] getElements()
{
return _elements.toArray(new File[_elements.size()]);
}
public int count()
{
return _elements.size();
}
public boolean addComponent(String component)
{
if ((component != null)&&(component.length()>0)) {
try {
if ((component != null) && (component.length() > 0))
{
try
{
File f = new File(component);
if (f.exists())
{
@ -63,36 +66,46 @@ public class Classpath {
return true;
}
}
} catch (IOException e) {}
}
catch (IOException e)
{
}
}
return false;
}
public boolean addComponent(File component)
{
if (component != null) {
try {
if (component.exists()) {
if (component != null)
{
try
{
if (component.exists())
{
File key = component.getCanonicalFile();
if (!_elements.contains(key)) {
if (!_elements.contains(key))
{
_elements.add(key);
return true;
}
}
} catch (IOException e) {}
}
catch (IOException e)
{
}
}
return false;
}
public boolean addClasspath(String s)
{
boolean added=false;
boolean added = false;
if (s != null)
{
StringTokenizer t = new StringTokenizer(s, File.pathSeparator);
while (t.hasMoreTokens())
{
added|=addComponent(t.nextToken());
added |= addComponent(t.nextToken());
}
}
return added;
@ -103,40 +116,49 @@ public class Classpath {
int i = 0;
for (File element : _elements)
{
out.printf("%2d: %s\n",i++,element.getAbsolutePath());
out.printf("%2d: %s\n", i++, element.getAbsolutePath());
}
}
@Override
public String toString()
{
StringBuffer cp = new StringBuffer(1024);
int cnt = _elements.size();
if (cnt >= 1) {
cp.append( ((_elements.elementAt(0))).getPath() );
if (cnt >= 1)
{
cp.append(((_elements.elementAt(0))).getPath());
}
for (int i=1; i < cnt; i++) {
for (int i = 1; i < cnt; i++)
{
cp.append(File.pathSeparatorChar);
cp.append( ((_elements.elementAt(i))).getPath() );
cp.append(((_elements.elementAt(i))).getPath());
}
return cp.toString();
}
public ClassLoader getClassLoader() {
public ClassLoader getClassLoader()
{
int cnt = _elements.size();
URL[] urls = new URL[cnt];
for (int i=0; i < cnt; i++) {
try {
String u=_elements.elementAt(i).toURI().toURL().toString();
urls[i] = new URL(encodeFileURL(u));
} catch (MalformedURLException e) {}
for (int i = 0; i < cnt; i++)
{
try
{
urls[i] = _elements.elementAt(i).toURI().toURL();
}
catch (MalformedURLException e)
{
}
}
ClassLoader parent = Thread.currentThread().getContextClassLoader();
if (parent == null) {
if (parent == null)
{
parent = Classpath.class.getClassLoader();
}
if (parent == null) {
if (parent == null)
{
parent = ClassLoader.getSystemClassLoader();
}
return new Loader(urls, parent);
@ -152,71 +174,17 @@ public class Classpath {
@Override
public String toString()
{
return "startJarLoader@"+Long.toHexString(hashCode());
return "startJarLoader@" + Long.toHexString(hashCode());
}
}
public static String encodeFileURL(String path)
{
byte[] bytes;
try
{
bytes=path.getBytes("utf-8");
}
catch (UnsupportedEncodingException e)
{
bytes=path.getBytes();
}
StringBuffer buf = new StringBuffer(bytes.length*2);
buf.append("file:");
synchronized(buf)
{
for (int i=5;i<bytes.length;i++)
{
byte b=bytes[i];
switch(b)
{
case '%':
buf.append("%25");
continue;
case ' ':
buf.append("%20");
continue;
case '/':
case '.':
case '-':
case '_':
buf.append((char)b);
continue;
default:
// let's be over conservative here!
if (Character.isJavaIdentifierPart((char)b))
{
if(b>='a' && b<='z' || b>='A' && b<='Z' || b>='0' && b<='9')
{
buf.append((char)b);
continue;
}
}
buf.append('%');
buf.append(Integer.toHexString((0xf0&b)>>4));
buf.append(Integer.toHexString((0x0f&b)));
continue;
}
}
}
return buf.toString();
}
/**
* Overlay another classpath, copying its elements into place on this Classpath, while eliminating duplicate entries
* on the classpath.
* Overlay another classpath, copying its elements into place on this
* Classpath, while eliminating duplicate entries on the classpath.
*
* @param cpOther
* the other classpath to overlay
* @param cpOther the other classpath to overlay
*/
public void overlay(Classpath cpOther)
{