JETTY-1249 i
Apply max idle time to all connectors git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2111 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
c46d01c789
commit
80e5a95130
|
@ -3,7 +3,7 @@ jetty-7.2-SNAPSHOT
|
|||
+ 319370 WebAppClassLoader.Context
|
||||
+ 319519 Warn about duplicate configuration files
|
||||
+ JETTY-1247 synchronize recylcing of SSL NIO buffers
|
||||
+ JETTY-1249 Apply max idle time
|
||||
+ JETTY-1249 Apply max idle time to all connectors
|
||||
+ Added ignore to Logger interface
|
||||
|
||||
jetty-7.1.5.v20100705
|
||||
|
|
|
@ -124,6 +124,8 @@ public class ChannelEndPoint implements EndPoint
|
|||
*/
|
||||
public void close() throws IOException
|
||||
{
|
||||
if (_socket!=null && !_socket.isOutputShutdown())
|
||||
_socket.shutdownOutput();
|
||||
_channel.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -228,6 +228,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
|
|||
{
|
||||
if (_idleTimestamp!=0 && _maxIdleTime!=0 && now>(_idleTimestamp+_maxIdleTime))
|
||||
{
|
||||
System.err.println("IDLE "+this);
|
||||
idleExpired();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,6 @@ import java.nio.channels.SelectionKey;
|
|||
import java.nio.channels.Selector;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
@ -52,6 +49,7 @@ public abstract class SelectorManager extends AbstractLifeCycle
|
|||
private static final int __MAX_SELECTS=Integer.getInteger("org.mortbay.io.nio.MAX_SELECTS",25000).intValue();
|
||||
private static final int __BUSY_PAUSE=Integer.getInteger("org.mortbay.io.nio.BUSY_PAUSE",50).intValue();
|
||||
private static final int __BUSY_KEY=Integer.getInteger("org.mortbay.io.nio.BUSY_KEY",-1).intValue();
|
||||
private static final int __IDLE_TICK=Integer.getInteger("org.mortbay.io.nio.IDLE_TICK",400).intValue();
|
||||
|
||||
private int _maxIdleTime;
|
||||
private int _lowResourcesMaxIdleTime;
|
||||
|
@ -458,7 +456,7 @@ public abstract class SelectorManager extends AbstractLifeCycle
|
|||
retry_next=_timeout.getTimeToNext();
|
||||
|
||||
// workout how low to wait in select
|
||||
long wait = _changes.size()==0?200L:0L;
|
||||
long wait = _changes.size()==0?__IDLE_TICK:0L;
|
||||
if (wait > 0 && retry_next >= 0 && wait > retry_next)
|
||||
wait = retry_next;
|
||||
|
||||
|
@ -745,7 +743,7 @@ public abstract class SelectorManager extends AbstractLifeCycle
|
|||
}
|
||||
|
||||
// Idle tick
|
||||
if (now-_idleTick>1000)
|
||||
if (now-_idleTick>__IDLE_TICK)
|
||||
{
|
||||
_idleTick=now;
|
||||
|
||||
|
|
|
@ -19,8 +19,12 @@ import java.net.Socket;
|
|||
import java.nio.channels.ByteChannel;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.eclipse.jetty.http.HttpException;
|
||||
import org.eclipse.jetty.io.Buffer;
|
||||
import org.eclipse.jetty.io.ConnectedEndPoint;
|
||||
import org.eclipse.jetty.io.Connection;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
|
@ -46,6 +50,8 @@ import org.eclipse.jetty.util.log.Log;
|
|||
public class BlockingChannelConnector extends AbstractNIOConnector
|
||||
{
|
||||
private transient ServerSocketChannel _acceptChannel;
|
||||
private final Set<BlockingChannelEndPoint> _endpoints = Collections.newSetFromMap(new ConcurrentHashMap<BlockingChannelEndPoint,Boolean>());
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Constructor.
|
||||
|
@ -61,6 +67,46 @@ public class BlockingChannelConnector extends AbstractNIOConnector
|
|||
return _acceptChannel;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.AbstractConnector#doStart()
|
||||
*/
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
super.doStart();
|
||||
getThreadPool().dispatch(new Runnable()
|
||||
{
|
||||
|
||||
public void run()
|
||||
{
|
||||
while (isRunning())
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(400);
|
||||
long now=System.currentTimeMillis();
|
||||
for (BlockingChannelEndPoint endp : _endpoints)
|
||||
{
|
||||
endp.checkIdleTimestamp(now);
|
||||
}
|
||||
}
|
||||
catch(InterruptedException e)
|
||||
{
|
||||
Log.ignore(e);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.warn(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void open() throws IOException
|
||||
{
|
||||
|
@ -91,7 +137,7 @@ public class BlockingChannelConnector extends AbstractNIOConnector
|
|||
Socket socket=channel.socket();
|
||||
configure(socket);
|
||||
|
||||
ConnectorEndPoint connection=new ConnectorEndPoint(channel);
|
||||
BlockingChannelEndPoint connection=new BlockingChannelEndPoint(channel);
|
||||
connection.dispatch();
|
||||
}
|
||||
|
||||
|
@ -117,13 +163,13 @@ public class BlockingChannelConnector extends AbstractNIOConnector
|
|||
/* ------------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
private class ConnectorEndPoint extends ChannelEndPoint implements Runnable, ConnectedEndPoint
|
||||
private class BlockingChannelEndPoint extends ChannelEndPoint implements Runnable, ConnectedEndPoint
|
||||
{
|
||||
Connection _connection;
|
||||
boolean _dispatched=false;
|
||||
int _sotimeout;
|
||||
private Connection _connection;
|
||||
private int _timeout;
|
||||
private volatile long _idleTimestamp;
|
||||
|
||||
ConnectorEndPoint(ByteChannel channel)
|
||||
BlockingChannelEndPoint(ByteChannel channel)
|
||||
throws IOException
|
||||
{
|
||||
super(channel,BlockingChannelConnector.this._maxIdleTime);
|
||||
|
@ -145,36 +191,102 @@ public class BlockingChannelConnector extends AbstractNIOConnector
|
|||
_connection=connection;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void checkIdleTimestamp(long now)
|
||||
{
|
||||
if (_idleTimestamp!=0 && _timeout>0 && now>(_idleTimestamp+_timeout))
|
||||
{
|
||||
System.err.println("IDLE "+this);
|
||||
idleExpired();
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void idleExpired()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Log.ignore(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
void dispatch() throws IOException
|
||||
{
|
||||
if (!getThreadPool().dispatch(this))
|
||||
{
|
||||
Log.warn("dispatch failed for {}",_connection);
|
||||
ConnectorEndPoint.this.close();
|
||||
BlockingChannelEndPoint.this.close();
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.io.nio.ChannelEndPoint#fill(org.eclipse.jetty.io.Buffer)
|
||||
*/
|
||||
@Override
|
||||
public int fill(Buffer buffer) throws IOException
|
||||
{
|
||||
_idleTimestamp=System.currentTimeMillis();
|
||||
return super.fill(buffer);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.io.nio.ChannelEndPoint#flush(org.eclipse.jetty.io.Buffer)
|
||||
*/
|
||||
@Override
|
||||
public int flush(Buffer buffer) throws IOException
|
||||
{
|
||||
_idleTimestamp=System.currentTimeMillis();
|
||||
return super.flush(buffer);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @see org.eclipse.jetty.io.nio.ChannelEndPoint#flush(org.eclipse.jetty.io.Buffer, org.eclipse.jetty.io.Buffer, org.eclipse.jetty.io.Buffer)
|
||||
*/
|
||||
@Override
|
||||
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
|
||||
{
|
||||
_idleTimestamp=System.currentTimeMillis();
|
||||
return super.flush(header,buffer,trailer);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
_timeout=getMaxIdleTime();
|
||||
connectionOpened(_connection);
|
||||
_endpoints.add(this);
|
||||
|
||||
while (isOpen())
|
||||
{
|
||||
_idleTimestamp=System.currentTimeMillis();
|
||||
if (_connection.isIdle())
|
||||
{
|
||||
if (getServer().getThreadPool().isLowOnThreads())
|
||||
{
|
||||
int lrmit = getLowResourcesMaxIdleTime();
|
||||
if (lrmit>=0 && _sotimeout!= lrmit)
|
||||
if (lrmit>=0 && _timeout!= lrmit)
|
||||
{
|
||||
_sotimeout=lrmit;
|
||||
((SocketChannel)getTransport()).socket().setSoTimeout(_sotimeout);
|
||||
_timeout=lrmit;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_timeout!=getMaxIdleTime())
|
||||
{
|
||||
_timeout=getMaxIdleTime();
|
||||
}
|
||||
}
|
||||
|
||||
_connection = _connection.handle();
|
||||
}
|
||||
|
@ -182,24 +294,25 @@ public class BlockingChannelConnector extends AbstractNIOConnector
|
|||
catch (EofException e)
|
||||
{
|
||||
Log.debug("EOF", e);
|
||||
try{ConnectorEndPoint.this.close();}
|
||||
try{BlockingChannelEndPoint.this.close();}
|
||||
catch(IOException e2){Log.ignore(e2);}
|
||||
}
|
||||
catch (HttpException e)
|
||||
{
|
||||
Log.debug("BAD", e);
|
||||
try{ConnectorEndPoint.this.close();}
|
||||
try{BlockingChannelEndPoint.this.close();}
|
||||
catch(IOException e2){Log.ignore(e2);}
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
Log.warn("handle failed",e);
|
||||
try{ConnectorEndPoint.this.close();}
|
||||
try{BlockingChannelEndPoint.this.close();}
|
||||
catch(IOException e2){Log.ignore(e2);}
|
||||
}
|
||||
finally
|
||||
{
|
||||
connectionClosed(_connection);
|
||||
_endpoints.remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,16 +13,13 @@
|
|||
|
||||
package org.eclipse.jetty.server.ssl;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.security.KeyStore;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -33,7 +30,6 @@ import javax.net.ssl.KeyManager;
|
|||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
import javax.net.ssl.SSLServerSocket;
|
||||
import javax.net.ssl.SSLServerSocketFactory;
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
@ -47,7 +43,6 @@ import org.eclipse.jetty.io.EndPoint;
|
|||
import org.eclipse.jetty.io.bio.SocketEndPoint;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.bio.SocketConnector;
|
||||
import org.eclipse.jetty.util.TypeUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2010 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.server;
|
||||
|
||||
import org.eclipse.jetty.server.nio.BlockingChannelConnector;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class BlockingChannelTimeoutTest extends ConnectorTimeoutTest
|
||||
{
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception
|
||||
{
|
||||
BlockingChannelConnector connector = new BlockingChannelConnector();
|
||||
connector.setMaxIdleTime(250); //250 msec max idle
|
||||
|
||||
startServer(connector);
|
||||
}
|
||||
|
||||
}
|
|
@ -13,32 +13,33 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
||||
{
|
||||
static
|
||||
{
|
||||
System.setProperty("org.mortbay.io.nio.IDLE_TICK","100");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSelectConnectorMaxIdleWithRequest() throws Exception
|
||||
{
|
||||
/*
|
||||
* Test not working for Blocking connector
|
||||
configureServer(new EchoHandler());
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
client.setSoTimeout(10000);
|
||||
|
||||
assertFalse(client.isClosed());
|
||||
|
||||
|
@ -55,36 +56,41 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
|
|||
"\r\n").getBytes("utf-8"));
|
||||
os.write(contentB);
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
String in = IO.toString(is);
|
||||
System.err.println(in);
|
||||
|
||||
Thread.sleep(600);
|
||||
Thread.sleep(300);
|
||||
assertEquals(-1, is.read());
|
||||
*/
|
||||
}
|
||||
|
||||
Assert.assertTrue(System.currentTimeMillis()-start>200);
|
||||
Assert.assertTrue(System.currentTimeMillis()-start<1000);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSelectConnectorMaxIdleNoRequest() throws Exception
|
||||
{
|
||||
/* Test is not working for Select and Blocking connectors - gregw to look at the SelectorManager and the idle timeout
|
||||
configureServer(new EchoHandler());
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
OutputStream os=client.getOutputStream();
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
client.setSoTimeout(10000);
|
||||
InputStream is=client.getInputStream();
|
||||
assertFalse(client.isClosed());
|
||||
|
||||
Thread.sleep(1100);
|
||||
Thread.sleep(500);
|
||||
long start = System.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
os.write(("xx").getBytes("utf-8"));
|
||||
Assert.fail("Connection not closed");
|
||||
IO.toString(is);
|
||||
assertEquals(-1, is.read());
|
||||
}
|
||||
catch (IOException e)
|
||||
catch(Exception e)
|
||||
{
|
||||
//expected result
|
||||
// SSL throws
|
||||
}
|
||||
*/
|
||||
Assert.assertTrue(System.currentTimeMillis()-start<200);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
{
|
||||
configureServer(new HelloWorldHandler());
|
||||
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os=client.getOutputStream();
|
||||
|
@ -133,7 +133,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
{
|
||||
configureServer(new EchoHandler());
|
||||
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os=client.getOutputStream();
|
||||
|
@ -166,7 +166,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
{
|
||||
configureServer(new HelloWorldHandler());
|
||||
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os=client.getOutputStream();
|
||||
|
@ -202,7 +202,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
byte[] bytes=REQUEST2.getBytes();
|
||||
for (int i=0; i<LOOPS; i++)
|
||||
{
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os=client.getOutputStream();
|
||||
|
@ -247,7 +247,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
// Sort the list
|
||||
Arrays.sort(points);
|
||||
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os=client.getOutputStream();
|
||||
|
@ -283,7 +283,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
// Sort the list
|
||||
Arrays.sort(points);
|
||||
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os=client.getOutputStream();
|
||||
|
@ -321,7 +321,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
};
|
||||
for (int i=0; i<badPoints.length; ++i)
|
||||
{
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os=client.getOutputStream();
|
||||
|
@ -384,7 +384,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
configureServer(new DataHandler());
|
||||
|
||||
long start=System.currentTimeMillis();
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os=client.getOutputStream();
|
||||
|
@ -444,7 +444,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
//for (int pipeline=1;pipeline<32;pipeline++)
|
||||
for (int pipeline=1;pipeline<32;pipeline++)
|
||||
{
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
client.setSoTimeout(5000);
|
||||
|
@ -497,7 +497,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
{
|
||||
configureServer(new EchoHandler());
|
||||
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os=client.getOutputStream();
|
||||
|
@ -585,7 +585,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
{
|
||||
configureServer(new EchoHandler());
|
||||
|
||||
Socket client=new Socket(HOST,_connector.getLocalPort());
|
||||
Socket client=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os=client.getOutputStream();
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.Socket;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -27,6 +28,11 @@ public class HttpServerTestFixture
|
|||
protected static Server _server;
|
||||
protected static Connector _connector;
|
||||
|
||||
protected Socket newSocket(String host,int port) throws Exception
|
||||
{
|
||||
return new Socket(host,port);
|
||||
}
|
||||
|
||||
protected static void startServer(Connector connector) throws Exception
|
||||
{
|
||||
_server = new Server();
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2010 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.server;
|
||||
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
|
||||
{
|
||||
@BeforeClass
|
||||
public static void init() throws Exception
|
||||
{
|
||||
SelectChannelConnector connector = new SelectChannelConnector();
|
||||
connector.setMaxIdleTime(250); //250 msec max idle
|
||||
startServer(connector);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2010 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.server;
|
||||
|
||||
import org.eclipse.jetty.server.bio.SocketConnector;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class SocketTimeoutTest extends ConnectorTimeoutTest
|
||||
{
|
||||
@BeforeClass
|
||||
public static void init() throws Exception
|
||||
{
|
||||
SocketConnector connector = new SocketConnector();
|
||||
connector.setMaxIdleTime(250); //250 msec max idle
|
||||
startServer(connector);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
package org.eclipse.jetty.server.ssl;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -29,6 +33,7 @@ import java.net.HttpURLConnection;
|
|||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
@ -49,10 +54,6 @@ import org.junit.AfterClass;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package org.eclipse.jetty.server.ssl;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import javax.net.ssl.SSLEngineResult;
|
||||
|
@ -27,9 +31,6 @@ import org.eclipse.jetty.util.StringUtil;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SslRenegotiateTest
|
||||
{
|
||||
private static final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager()
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 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.server.ssl;
|
||||
import java.io.FileInputStream;
|
||||
import java.net.Socket;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
import org.eclipse.jetty.server.HttpServerTestBase;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* HttpServer Tester.
|
||||
*/
|
||||
public class SslSelectChannelServerTest extends HttpServerTestBase
|
||||
{
|
||||
static SSLContext __sslContext;
|
||||
|
||||
@Override
|
||||
protected Socket newSocket(String host, int port) throws Exception
|
||||
{
|
||||
return __sslContext.getSocketFactory().createSocket(host,port);
|
||||
}
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception
|
||||
{
|
||||
SslSelectChannelConnector connector = new SslSelectChannelConnector();
|
||||
String keystorePath = System.getProperty("basedir",".") + "/src/test/resources/keystore";
|
||||
connector.setKeystore(keystorePath);
|
||||
connector.setPassword("storepwd");
|
||||
connector.setKeyPassword("keypwd");
|
||||
connector.setTruststore(keystorePath);
|
||||
connector.setTrustPassword("storepwd");
|
||||
startServer(connector);
|
||||
|
||||
|
||||
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keystore.load(new FileInputStream(connector.getKeystore()), "storepwd".toCharArray());
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
trustManagerFactory.init(keystore);
|
||||
__sslContext = SSLContext.getInstance("SSL");
|
||||
__sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testFlush() throws Exception
|
||||
{
|
||||
// TODO this test uses URL, so noop for now
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2010 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.server.ssl;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.net.Socket;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
import org.eclipse.jetty.server.ConnectorTimeoutTest;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class SslSelectChannelTimeoutTest extends ConnectorTimeoutTest
|
||||
{
|
||||
static SSLContext __sslContext;
|
||||
|
||||
@Override
|
||||
protected Socket newSocket(String host, int port) throws Exception
|
||||
{
|
||||
return __sslContext.getSocketFactory().createSocket(host,port);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception
|
||||
{
|
||||
SslSelectChannelConnector connector = new SslSelectChannelConnector();
|
||||
connector.setMaxIdleTime(250); //250 msec max idle
|
||||
String keystorePath = System.getProperty("basedir",".") + "/src/test/resources/keystore";
|
||||
connector.setKeystore(keystorePath);
|
||||
connector.setPassword("storepwd");
|
||||
connector.setKeyPassword("keypwd");
|
||||
connector.setTruststore(keystorePath);
|
||||
connector.setTrustPassword("storepwd");
|
||||
startServer(connector);
|
||||
|
||||
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keystore.load(new FileInputStream(connector.getKeystore()), "storepwd".toCharArray());
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
trustManagerFactory.init(keystore);
|
||||
__sslContext = SSLContext.getInstance("SSL");
|
||||
__sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2004-2009 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.server.ssl;
|
||||
import java.io.FileInputStream;
|
||||
import java.net.Socket;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
import org.eclipse.jetty.server.HttpServerTestBase;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* HttpServer Tester.
|
||||
*/
|
||||
public class SslSocketServerTest extends HttpServerTestBase
|
||||
{
|
||||
static SSLContext __sslContext;
|
||||
|
||||
@Override
|
||||
protected Socket newSocket(String host, int port) throws Exception
|
||||
{
|
||||
return __sslContext.getSocketFactory().createSocket(host,port);
|
||||
}
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception
|
||||
{
|
||||
SslSocketConnector connector = new SslSocketConnector();
|
||||
String keystorePath = System.getProperty("basedir",".") + "/src/test/resources/keystore";
|
||||
connector.setKeystore(keystorePath);
|
||||
connector.setPassword("storepwd");
|
||||
connector.setKeyPassword("keypwd");
|
||||
connector.setTruststore(keystorePath);
|
||||
connector.setTrustPassword("storepwd");
|
||||
startServer(connector);
|
||||
|
||||
|
||||
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keystore.load(new FileInputStream(connector.getKeystore()), "storepwd".toCharArray());
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
trustManagerFactory.init(keystore);
|
||||
__sslContext = SSLContext.getInstance("SSL");
|
||||
__sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testFlush() throws Exception
|
||||
{
|
||||
// TODO this test uses URL, so noop for now
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2010 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.server.ssl;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.net.Socket;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
import org.eclipse.jetty.server.ConnectorTimeoutTest;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class SslSocketTimeoutTest extends ConnectorTimeoutTest
|
||||
{
|
||||
static SSLContext _sslContext;
|
||||
|
||||
@Override
|
||||
protected Socket newSocket(String host, int port) throws Exception
|
||||
{
|
||||
return _sslContext.getSocketFactory().createSocket(host,port);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception
|
||||
{
|
||||
|
||||
|
||||
SslSocketConnector connector = new SslSocketConnector();
|
||||
connector.setMaxIdleTime(250); //250 msec max idle
|
||||
String keystorePath = System.getProperty("basedir",".") + "/src/test/resources/keystore";
|
||||
connector.setKeystore(keystorePath);
|
||||
connector.setPassword("storepwd");
|
||||
connector.setKeyPassword("keypwd");
|
||||
connector.setTruststore(keystorePath);
|
||||
connector.setTrustPassword("storepwd");
|
||||
startServer(connector);
|
||||
|
||||
|
||||
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keystore.load(new FileInputStream(connector.getKeystore()), "storepwd".toCharArray());
|
||||
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
trustManagerFactory.init(keystore);
|
||||
_sslContext = SSLContext.getInstance("SSL");
|
||||
_sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
package org.eclipse.jetty.server.ssl;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -21,6 +23,7 @@ import java.io.OutputStream;
|
|||
import java.security.KeyStore;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
@ -36,8 +39,6 @@ import org.junit.AfterClass;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue