306376 extra tests

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1398 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-03-22 03:17:25 +00:00
parent 6ba2789cab
commit 40ee939b4e
3 changed files with 99 additions and 42 deletions

View File

@ -26,6 +26,7 @@ import org.eclipse.jetty.http.HttpHeaders;
import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.http.HttpParser;
import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpVersions;
import org.eclipse.jetty.http.ssl.SslSelectChannelEndPoint;
import org.eclipse.jetty.io.Buffer;
@ -49,6 +50,7 @@ public class HttpConnection implements Connection
private HttpGenerator _generator;
private HttpParser _parser;
private boolean _http11 = true;
private int _status;
private Buffer _connectionHeader;
private Buffer _requestContentChunk;
private boolean _requestComplete;
@ -330,30 +332,33 @@ public class HttpConnection implements Connection
no_progress = 0;
if (_exchange != null)
{
_exchange.disassociate();
_exchange = null;
if (_status!=HttpStatus.SWITCHING_PROTOCOLS_101 || !_exchange.onSwitchProtocol(_endp))
{
_exchange.disassociate();
_exchange = null;
if (_pipeline == null)
{
if (!isReserved())
_destination.returnConnection(this, close);
}
else
{
if (close)
if (_pipeline == null)
{
if (!isReserved())
_destination.returnConnection(this,close);
HttpExchange exchange = _pipeline;
_pipeline = null;
_destination.send(exchange);
_destination.returnConnection(this, close);
}
else
{
HttpExchange exchange = _pipeline;
_pipeline = null;
send(exchange);
if (close)
{
if (!isReserved())
_destination.returnConnection(this,close);
HttpExchange exchange = _pipeline;
_pipeline = null;
_destination.send(exchange);
}
else
{
HttpExchange exchange = _pipeline;
_pipeline = null;
send(exchange);
}
}
}
}
@ -398,6 +403,7 @@ public class HttpConnection implements Connection
{
synchronized (this)
{
_status=0;
if (_exchange.getStatus() != HttpExchange.STATUS_WAITING_FOR_COMMIT)
throw new IllegalStateException();
@ -500,6 +506,7 @@ public class HttpConnection implements Connection
if (exchange!=null)
{
_http11 = HttpVersions.HTTP_1_1_BUFFER.equals(version);
_status=status;
exchange.getEventListener().onResponseStatus(version,status,reason);
exchange.setStatus(HttpExchange.STATUS_PARSING_HEADERS);
}

View File

@ -25,6 +25,7 @@ import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.HttpVersions;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.BufferCache.CachedBuffer;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.util.log.Log;
@ -656,6 +657,13 @@ public class HttpExchange
return getClass().getSimpleName() + "@" + hashCode() + "=" + _method + "//" + _address + _uri + "#" + getStatus();
}
/**
*/
protected boolean onSwitchProtocol(EndPoint enpd) throws IOException
{
return false;
}
/**
* Callback called when the request headers have been sent to the server.
* This implementation does nothing.

View File

@ -37,6 +37,7 @@ import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -46,6 +47,7 @@ import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.IO;
/**
* HttpServer Tester.
@ -75,23 +77,25 @@ public class SSLEngineTest extends TestCase
private static final String RESPONSE1="HTTP/1.1 200 OK\n"+"Connection: close\n"+"Server: Jetty("+JETTY_VERSION+")\n"+'\n'+HELLO_WORLD;
private static final TrustManager[] s_dummyTrustManagers=new TrustManager[]
{ new X509TrustManager()
{
public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
new X509TrustManager()
{
return null;
public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
return null;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
{
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
{
}
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
{
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
{
}
} };
};
Server server;
SslSelectChannelConnector connector;
@ -113,6 +117,8 @@ public class SSLEngineTest extends TestCase
connector.setKeystore(keystore);
connector.setPassword("storepwd");
connector.setKeyPassword("keypwd");
connector.setRequestBufferSize(512);
connector.setRequestHeaderSize(512);
server.setConnectors(new Connector[]
{ connector });
@ -134,16 +140,45 @@ public class SSLEngineTest extends TestCase
{
}
/**
* Feed the server the entire request at once.
*
* @throws Exception
*/
public void testBigResponse() throws Exception
{
SSLContext ctx=SSLContext.getInstance("SSLv3");
ctx.init(null,s_dummyTrustManagers,new java.security.SecureRandom());
int port=connector.getLocalPort();
Socket client=ctx.getSocketFactory().createSocket("localhost",port);
OutputStream os=client.getOutputStream();
String request =
"GET /?dump=102400 HTTP/1.1\r\n"+
"Host: localhost:8080\r\n"+
"Connection: close\r\n"+
"\r\n";
os.write(request.getBytes());
os.flush();
String response = IO.toString(client.getInputStream());
assertTrue(response.length()>102400);
}
/**
* Feed the server the entire request at once.
*
* @throws Exception
*/
public void /*test*/RequestJettyHttps() throws Exception
public void testRequestJettyHttps() throws Exception
{
final int loops=100;
final int numConns=100;
final int loops=10;
final int numConns=10;
Socket[] client=new Socket[numConns];
@ -259,15 +294,21 @@ public class SSLEngineTest extends TestCase
{
// System.err.println("HANDLE "+request.getRequestURI());
String ssl_id = (String)request.getAttribute("javax.servlet.request.ssl_session_id");
//assertNotNull(ssl_id);
PrintWriter out=response.getWriter();
assertNotNull(ssl_id);
try
if (request.getParameter("dump")!=null)
{
ServletOutputStream out=response.getOutputStream();
byte[] buf = new byte[Integer.valueOf(request.getParameter("dump"))];
for (int i=0;i<buf.length;i++)
buf[i]=(byte)('0'+(i%10));
out.write(buf);
out.close();
}
else
{
PrintWriter out=response.getWriter();
out.print(HELLO_WORLD);
}
finally
{
out.close();
}
}
@ -353,6 +394,7 @@ public class SSLEngineTest extends TestCase
}
}
public static class StreamHandler extends AbstractHandler
{
public int bytes=0;