282543 HttpClient SSL buffer size fix

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@854 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2009-09-10 08:00:20 +00:00
parent 9769da72e4
commit 1ec196076a
8 changed files with 163 additions and 14 deletions

View File

@ -19,6 +19,7 @@ jetty-7.0.0.RC6-SNAPSHOT
+ 288772 Failure to connect does not set status to EXCEPTED
+ 280723 Add non blocking statistics handler
+ 283357 org.eclipse.jetty.server.HttpConnectionTest exceptions
+ 282543 HttpClient SSL buffer size fix
jetty-6.1.20 27 August 2009
+ JETTY-838 Don't log and throw

View File

@ -19,7 +19,6 @@ import java.net.UnknownHostException;
import java.security.KeyStore;
import java.security.SecureRandom;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;

View File

@ -79,10 +79,14 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
_selectorManager.start();
SSLEngine sslEngine=_selectorManager.newSslEngine();
SSLSession ssl_session=sslEngine.getSession();
ThreadLocalBuffers buffers = new ThreadLocalBuffers()
final SSLSession ssl_session=sslEngine.getSession();
ThreadLocalBuffers ssl_buffers = new ThreadLocalBuffers()
{
{
super.setBufferSize(ssl_session.getApplicationBufferSize());
super.setHeaderSize(ssl_session.getApplicationBufferSize());
}
@Override
protected Buffer newBuffer(int size)
{
@ -100,10 +104,18 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
{
return true;
}
@Override
public void setBufferSize(int size)
{
}
@Override
public void setHeaderSize(int size)
{
}
};
buffers.setBufferSize(ssl_session.getApplicationBufferSize());
buffers.setHeaderSize(ssl_session.getPacketBufferSize());
_sslBuffers=buffers;
_sslBuffers=ssl_buffers;
_httpClient._threadPool.dispatch(this);
}
@ -147,35 +159,43 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
/* ------------------------------------------------------------ */
class Manager extends SelectorManager
{
@Override
protected SocketChannel acceptChannel(SelectionKey key) throws IOException
{
throw new IllegalStateException();
}
@Override
public boolean dispatch(Runnable task)
{
return SelectConnector.this._httpClient._threadPool.dispatch(task);
}
@Override
protected void endPointOpened(SelectChannelEndPoint endpoint)
{
}
@Override
protected void endPointClosed(SelectChannelEndPoint endpoint)
{
}
@Override
protected Connection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint)
{
if (endpoint instanceof SslSelectChannelEndPoint)
return new HttpConnection(_sslBuffers,_sslBuffers,endpoint);
return new HttpConnection(_httpClient.getRequestBuffers(),_httpClient.getResponseBuffers(),endpoint);
}
@Override
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException
{
// key should have destination at this point (will be replaced by endpoint after this call)
HttpDestination dest=(HttpDestination)key.attachment();
SelectChannelEndPoint ep=null;
if (dest.isSecure())

View File

@ -25,10 +25,10 @@ public class AsyncSslHttpExchangeTest extends SslHttpExchangeTest
_httpClient.setMaxConnectionsPerAddress(2);
_httpClient.start();
}
public void testPerf() throws Exception
{
super.testPerf();
}
@Override
public void testSun() throws Exception
{
super.testSun();
}
}

View File

@ -0,0 +1,107 @@
package org.eclipse.jetty.client;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.io.Buffer;
public class Curl
{
public static void main(String[] args)
throws Exception
{
HttpClient client = new HttpClient();
client.start();
final CountDownLatch latch = new CountDownLatch(args.length);
for (String arg : args)
{
HttpExchange ex = new HttpExchange()
{
AtomicBoolean counted=new AtomicBoolean(false);
@Override
protected void onConnectionFailed(Throwable ex)
{
if (!counted.getAndSet(true))
latch.countDown();
super.onConnectionFailed(ex);
}
@Override
protected void onException(Throwable ex)
{
if (!counted.getAndSet(true))
latch.countDown();
super.onException(ex);
}
@Override
protected void onExpire()
{
if (!counted.getAndSet(true))
latch.countDown();
super.onExpire();
}
@Override
protected void onResponseComplete() throws IOException
{
if (!counted.getAndSet(true))
latch.countDown();
super.onResponseComplete();
}
@Override
protected void onResponseContent(Buffer content) throws IOException
{
super.onResponseContent(content);
System.err.println("got "+content.length());
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.client.HttpExchange#onResponseHeader(org.eclipse.jetty.io.Buffer, org.eclipse.jetty.io.Buffer)
*/
@Override
protected void onResponseHeader(Buffer name, Buffer value) throws IOException
{
super.onResponseHeader(name,value);
System.err.println(name+": "+value);
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.client.HttpExchange#onResponseHeaderComplete()
*/
@Override
protected void onResponseHeaderComplete() throws IOException
{
super.onResponseHeaderComplete();
System.err.println();
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.client.HttpExchange#onResponseStatus(org.eclipse.jetty.io.Buffer, int, org.eclipse.jetty.io.Buffer)
*/
@Override
protected void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException
{
super.onResponseStatus(version,status,reason);
System.err.println(version+" "+status+" "+reason);
}
};
ex.setMethod(HttpMethods.GET);
ex.setURL(arg);
client.send(ex);
}
latch.await();
}
}

View File

@ -29,6 +29,7 @@ import junit.framework.TestCase;
import org.eclipse.jetty.client.security.ProxyAuthorization;
import org.eclipse.jetty.http.HttpHeaders;
import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.EofException;
@ -243,6 +244,20 @@ public class HttpExchangeTest extends TestCase
}
}
public void testSun() throws Exception
{
ContentExchange httpExchange=new ContentExchange();
httpExchange.setURL(_scheme+"www.sun.com/");
httpExchange.setMethod(HttpMethods.GET);
_httpClient.send(httpExchange);
int status = httpExchange.waitForDone();
String result=httpExchange.getResponseContent();
assertTrue(result.indexOf("<title>Sun Microsystems</title>")>0);
assertEquals(HttpExchange.STATUS_COMPLETED, status);
assertEquals(HttpStatus.OK_200,httpExchange.getResponseStatus());
}
public void testProxy() throws Exception
{
if (_scheme.equals("https://"))

View File

@ -175,6 +175,13 @@ public abstract class ThreadLocalBuffers implements Buffers
_headerSize = size;
}
/* ------------------------------------------------------------ */
@Override
public String toString()
{
return "{{"+getHeaderSize()+","+getBufferSize()+"}}";
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
protected static class ThreadBuffers

View File

@ -632,7 +632,7 @@ public class SslSelectChannelConnector extends SelectChannelConnector implements
}
};
buffers.setBufferSize(ssl_session.getApplicationBufferSize());
buffers.setHeaderSize(ssl_session.getPacketBufferSize());
buffers.setHeaderSize(ssl_session.getApplicationBufferSize());
_sslBuffers=buffers;
if (getRequestHeaderSize()<ssl_session.getApplicationBufferSize())