Jetty9 - More refactorings and renamings.

This commit is contained in:
Simone Bordet 2012-07-20 15:23:39 +02:00
parent 6aba6d1e8c
commit 851239ee56
24 changed files with 171 additions and 197 deletions

View File

@ -4,11 +4,11 @@
// 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
// 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.
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.embedded;
@ -23,13 +23,13 @@ import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.SelectChannelConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.server.SelectChannelConnector;
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.ssl.SslContextFactory;
@ -45,14 +45,14 @@ public class LikeJettyXml
Server server = new Server();
server.setDumpAfterStart(true);
server.setDumpBeforeStop(true);
// Setup JMX
MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
mbContainer.start();
server.getContainer().addEventListener(mbContainer);
server.addBean(mbContainer,true);
mbContainer.addBean(new Log());
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(500);
@ -61,10 +61,10 @@ public class LikeJettyXml
// Setup Connectors
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(8080);
connector.setMaxIdleTime(30000);
connector.setIdleTimeout(30000);
connector.setConfidentialPort(8443);
// TODO connector.setStatsOn(false);
server.setConnectors(new Connector[]
{ connector });
@ -89,23 +89,23 @@ public class LikeJettyXml
// TODO ssl_connector.setStatsOn(false);
server.addConnector(ssl_connector);
ssl_connector.open();
HandlerCollection handlers = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
RequestLogHandler requestLogHandler = new RequestLogHandler();
handlers.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
StatisticsHandler stats = new StatisticsHandler();
stats.setHandler(handlers);
server.setHandler(stats);
// Setup deployers
DeploymentManager deployer = new DeploymentManager();
deployer.setContexts(contexts);
server.addBean(deployer);
server.addBean(deployer);
ContextProvider context_provider = new ContextProvider();
context_provider.setMonitoredDirName(jetty_home + "/contexts");
context_provider.setScanInterval(2);
@ -131,7 +131,7 @@ public class LikeJettyXml
server.setStopAtShutdown(true);
server.setSendServerVersion(true);
server.start();
server.join();
}

View File

@ -4,18 +4,18 @@
// 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
// 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.
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.embedded;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.SelectChannelConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
@ -23,7 +23,7 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
/* ------------------------------------------------------------ */
/**
* A Jetty server with multiple connectors.
*
*
*/
public class ManyConnectors
{
@ -33,7 +33,7 @@ public class ManyConnectors
SelectChannelConnector connector0 = new SelectChannelConnector();
connector0.setPort(8080);
connector0.setMaxIdleTime(30000);
connector0.setIdleTimeout(30000);
connector0.setRequestHeaderSize(8192);
SelectChannelConnector connector1 = new SelectChannelConnector();

View File

@ -25,13 +25,13 @@ public abstract class AbstractEndPoint implements EndPoint
@Override
public long getMaxIdleTime()
public long getIdleTimeout()
{
return _maxIdleTime;
}
@Override
public void setMaxIdleTime(long timeMs)
public void setIdleTimeout(long timeMs)
{
_maxIdleTime=timeMs;
}

View File

@ -44,7 +44,7 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
public AsyncByteArrayEndPoint(String input, int outputSize)
{
super(input,outputSize);
super(input, outputSize);
}
@Override
@ -81,13 +81,13 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
@Override
public <C> void fillInterested(C context, Callback<C> callback) throws IllegalStateException
{
_readInterest.register(context,callback);
_readInterest.register(context, callback);
}
@Override
public <C> void write(C context, Callback<C> callback, ByteBuffer... buffers) throws IllegalStateException
{
_writeFlusher.write(context,callback,buffers);
_writeFlusher.write(context, callback, buffers);
}
@Override
@ -110,13 +110,13 @@ public class AsyncByteArrayEndPoint extends ByteArrayEndPoint implements AsyncEn
if (isOutputShutdown() || _readInterest.isInterested() || _writeFlusher.isWriting())
{
long idleTimestamp = getIdleTimestamp();
long max_idle_time = getMaxIdleTime();
long idleTimeout = getIdleTimeout();
if (idleTimestamp != 0 && max_idle_time > 0)
if (idleTimestamp != 0 && idleTimeout > 0)
{
long idleForMs = now - idleTimestamp;
if (idleForMs > max_idle_time)
if (idleForMs > idleTimeout)
{
if (isOutputShutdown())
close();

View File

@ -116,13 +116,13 @@ public interface EndPoint
* extraordinary handling takes place.
* @return the max idle time in ms or if ms <= 0 implies an infinite timeout
*/
long getMaxIdleTime();
long getIdleTimeout();
/* ------------------------------------------------------------ */
/** Set the max idle time.
* @param timeMs the max idle time in MS. Timeout <= 0 implies an infinite timeout
*/
void setMaxIdleTime(long timeMs);
void setIdleTimeout(long timeMs);

View File

@ -66,12 +66,12 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
}
};
public SelectChannelEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key, long maxIdleTime) throws IOException
public SelectChannelEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key, long idleTimeout) throws IOException
{
super(channel);
_selector = selectSet;
_key = key;
setMaxIdleTime(maxIdleTime);
setIdleTimeout(idleTimeout);
}
@Override
@ -104,6 +104,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
@Override
public void onSelected()
{
_interestOps = 0;
if (_key.isReadable())
_readInterest.readable();
if (_key.isWritable())
@ -118,13 +119,13 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
if (isOutputShutdown() || _readInterest.isInterested() || _writeFlusher.isWriting())
{
long idleTimestamp = getIdleTimestamp();
long max_idle_time = getMaxIdleTime();
long idleTimeout = getIdleTimeout();
if (idleTimestamp != 0 && max_idle_time > 0)
if (idleTimestamp != 0 && idleTimeout > 0)
{
long idleForMs = now - idleTimestamp;
if (idleForMs > max_idle_time)
if (idleForMs > idleTimeout)
{
if (isOutputShutdown())
close();
@ -156,8 +157,13 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
if (newInterestOps != oldInterestOps)
{
_interestOps = newInterestOps;
LOG.debug("Key update {} -> {} for {}", oldInterestOps, newInterestOps, this);
_selector.submit(this);
}
else
{
LOG.debug("Ignoring key update {} -> {} for {}", oldInterestOps, newInterestOps, this);
}
}
@Override

View File

@ -7,6 +7,7 @@ import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.FutureCallback;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
@ -105,11 +106,13 @@ public class AsyncByteArrayEndPointTest
assertEquals(" more.",endp.getOutputString());
}
// TODO: idle timeout testing should be done with a SelectorManager
@Ignore
@Test
public void testIdle() throws Exception
{
AsyncByteArrayEndPoint endp = new AsyncByteArrayEndPoint();
endp.setMaxIdleTime(500);
endp.setIdleTimeout(500);
endp.setInput("test");
endp.setGrowOutput(false);
endp.setOutput(BufferUtil.allocate(5));

View File

@ -1,18 +1,11 @@
package org.eclipse.jetty.io;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
@ -27,6 +20,12 @@ import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
{
@ -231,7 +230,7 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
}
// Set Max idle
_lastEndp.setMaxIdleTime(500);
_lastEndp.setIdleTimeout(500);
// Write 8 and cause block waiting for 10
_blockAt=10;
@ -247,7 +246,7 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
assertTrue(idle<2000);
Thread.sleep(1000);
assertFalse(_lastEndp.isOpen());
}
@ -257,7 +256,7 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
{
super.testStress();
}
@Test
public void checkSslEngineBehaviour() throws Exception
{
@ -270,14 +269,14 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
ByteBuffer serverOut = ByteBuffer.allocate(server.getSession().getApplicationBufferSize());
ByteBuffer clientIn = ByteBuffer.allocate(client.getSession().getApplicationBufferSize());
ByteBuffer clientOut = ByteBuffer.allocate(client.getSession().getApplicationBufferSize());
SSLEngineResult result;
// start the client
client.setUseClientMode(true);
client.beginHandshake();
Assert.assertEquals(HandshakeStatus.NEED_WRAP,client.getHandshakeStatus());
// what if we try an unwrap?
netS2C.flip();
result=client.unwrap(netS2C,clientIn);
@ -287,7 +286,7 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
assertEquals(0,result.bytesProduced());
assertEquals(HandshakeStatus.NEED_WRAP,result.getHandshakeStatus());
netS2C.clear();
// do the needed WRAP of empty buffer
result=client.wrap(BufferUtil.EMPTY_BUFFER,netC2S);
// unwrap is a noop
@ -297,13 +296,13 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
assertEquals(HandshakeStatus.NEED_UNWRAP,result.getHandshakeStatus());
netC2S.flip();
assertEquals(netC2S.remaining(),result.bytesProduced());
// start the server
server.setUseClientMode(false);
server.beginHandshake();
Assert.assertEquals(HandshakeStatus.NEED_UNWRAP,server.getHandshakeStatus());
// what if we try a needless wrap?
serverOut.put(BufferUtil.toBuffer("Hello World"));
@ -314,15 +313,15 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
assertEquals(0,result.bytesConsumed());
assertEquals(0,result.bytesProduced());
assertEquals(HandshakeStatus.NEED_UNWRAP,result.getHandshakeStatus());
// Do the needed unwrap, to an empty buffer
result=server.unwrap(netC2S,BufferUtil.EMPTY_BUFFER);
assertEquals(SSLEngineResult.Status.BUFFER_OVERFLOW,result.getStatus());
assertEquals(0,result.bytesConsumed());
assertEquals(0,result.bytesProduced());
assertEquals(HandshakeStatus.NEED_UNWRAP,result.getHandshakeStatus());
// Do the needed unwrap, to a full buffer
serverIn.position(serverIn.limit());
@ -331,7 +330,7 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
assertEquals(0,result.bytesConsumed());
assertEquals(0,result.bytesProduced());
assertEquals(HandshakeStatus.NEED_UNWRAP,result.getHandshakeStatus());
// Do the needed unwrap, to an empty buffer
serverIn.clear();
@ -340,13 +339,13 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
assertThat(result.bytesConsumed(),greaterThan(0));
assertEquals(0,result.bytesProduced());
assertEquals(HandshakeStatus.NEED_TASK,result.getHandshakeStatus());
server.getDelegatedTask().run();
assertEquals(HandshakeStatus.NEED_WRAP,server.getHandshakeStatus());
}
}

View File

@ -192,10 +192,8 @@ public class SelectChannelEndPointTest
fillInterested();
}
}
}
@Test
public void testEcho() throws Exception
{
@ -332,7 +330,7 @@ public class SelectChannelEndPointTest
while(_lastEndp==null);
_lastEndp.setMaxIdleTime(10*specifiedTimeout);
_lastEndp.setIdleTimeout(10 * specifiedTimeout);
Thread.sleep((11*specifiedTimeout)/10);
long start=System.currentTimeMillis();
@ -384,7 +382,7 @@ public class SelectChannelEndPointTest
}
// Set Max idle
_lastEndp.setMaxIdleTime(500);
_lastEndp.setIdleTimeout(500);
// read until idle shutdown received
long start=System.currentTimeMillis();
@ -428,7 +426,7 @@ public class SelectChannelEndPointTest
}
// Set Max idle
_lastEndp.setMaxIdleTime(500);
_lastEndp.setIdleTimeout(500);
// Write 8 and cause block waiting for 10
_blockAt=10;
@ -485,7 +483,7 @@ public class SelectChannelEndPointTest
while (_lastEndp==null)
Thread.sleep(10);
_lastEndp.setMaxIdleTime(5000);
_lastEndp.setIdleTimeout(5000);
new Thread()
{
@ -599,7 +597,7 @@ public class SelectChannelEndPointTest
assertEquals("test-"+i+"/"+j,c,(char)b);
}
if (i==0)
_lastEndp.setMaxIdleTime(60000);
_lastEndp.setIdleTimeout(60000);
}

View File

@ -13,12 +13,8 @@
package org.eclipse.jetty.security;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
import java.io.IOException;
import java.util.Arrays;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -39,6 +35,9 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
/**
* @version $Revision: 1441 $ $Date: 2010-04-02 12:28:17 +0200 (Fri, 02 Apr 2010) $
*/
@ -55,14 +54,14 @@ public class DataConstraintsTest
{
_server = new Server();
_connector = new LocalHttpConnector();
_connector.setMaxIdleTime(300000);
_connector.setIdleTimeout(300000);
_connector.setIntegralPort(9998);
_connector.setIntegralScheme("FTP");
_connector.setConfidentialPort(9999);
_connector.setConfidentialScheme("SPDY");
_connectorS = new LocalHttpConnector()
{
@Override
public void customize(Request request) throws IOException
{

View File

@ -57,7 +57,7 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
private final Statistics _stats = new ConnectionStatistics();
protected int _maxIdleTime = 200000;
protected int _idleTimeout = 200000;
protected int _soLingerTime = -1;
@ -191,9 +191,9 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
* @return Returns the maxIdleTime.
*/
@Override
public long getMaxIdleTime()
public long getIdleTimeout()
{
return _maxIdleTime;
return _idleTimeout;
}
/* ------------------------------------------------------------ */
@ -213,12 +213,12 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
* Previously, Jetty supported separate idle timeouts and IO operation timeouts, however the expense of changing the value of soTimeout was significant, so
* these timeouts were merged. With the advent of NIO, it may be possible to again differentiate these values (if there is demand).
*
* @param maxIdleTime
* The maxIdleTime to set.
* @param idleTimeout
* The idleTimeout to set.
*/
public void setMaxIdleTime(int maxIdleTime)
public void setIdleTimeout(int idleTimeout)
{
_maxIdleTime = maxIdleTime;
_idleTimeout = idleTimeout;
}
/* ------------------------------------------------------------ */

View File

@ -54,7 +54,7 @@ public interface Connector extends LifeCycle
/**
* @return Max Idle time for connections in milliseconds
*/
long getMaxIdleTime();
long getIdleTimeout();
/* ------------------------------------------------------------ */
/**

View File

@ -37,7 +37,7 @@ public class LocalHttpConnector extends HttpConnector
/* ------------------------------------------------------------ */
public LocalHttpConnector()
{
setMaxIdleTime(30000);
setIdleTimeout(30000);
}
/* ------------------------------------------------------------ */
@ -181,7 +181,7 @@ public class LocalHttpConnector extends HttpConnector
public LocalEndPoint()
{
setGrowOutput(true);
setMaxIdleTime(LocalHttpConnector.this.getMaxIdleTime());
setIdleTimeout(LocalHttpConnector.this.getIdleTimeout());
}
/* ------------------------------------------------------------ */
@ -190,7 +190,7 @@ public class LocalHttpConnector extends HttpConnector
// TODO this is a busy wait
while(getIn()==null || BufferUtil.hasContent(getIn()))
Thread.yield();
setInput(BufferUtil.toBuffer(s,StringUtil.__UTF8_CHARSET));
setInput(BufferUtil.toBuffer(s, StringUtil.__UTF8_CHARSET));
}
/* ------------------------------------------------------------ */

View File

@ -28,7 +28,6 @@ import org.eclipse.jetty.io.SelectorManager;
import org.eclipse.jetty.io.SelectorManager.ManagedSelector;
import org.eclipse.jetty.server.Connector.NetConnector;
/* ------------------------------------------------------------------------------- */
/**
* Selecting NIO connector.
* <p>
@ -60,7 +59,6 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
protected ServerSocketChannel _acceptChannel;
private int _localPort=-1;
/* ------------------------------------------------------------------------------- */
/**
* Constructor.
*
@ -71,7 +69,6 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
Math.max(1,(Runtime.getRuntime().availableProcessors())/4));
}
/* ------------------------------------------------------------ */
public SelectChannelConnector(int acceptors, int selectors)
{
super(acceptors);
@ -79,7 +76,6 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
addBean(_manager,true);
}
/* ------------------------------------------------------------ */
@Override
public void accept(int acceptorID) throws IOException
{
@ -99,7 +95,6 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
}
}
/* ------------------------------------------------------------ */
@Override
public void close()
{
@ -123,7 +118,6 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
}
}
/* ------------------------------------------------------------------------------- */
@Override
public void customize(Request request) throws IOException
{
@ -131,20 +125,17 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
super.customize(request);
}
/* ------------------------------------------------------------ */
public SelectorManager getSelectorManager()
{
return _manager;
}
/* ------------------------------------------------------------ */
@Override
public synchronized Object getTransport()
{
return _acceptChannel;
}
/* ------------------------------------------------------------------------------- */
@Override
public int getLocalPort()
{
@ -154,7 +145,6 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
}
}
/* ------------------------------------------------------------ */
@Override
public void open() throws IOException
{
@ -181,14 +171,6 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
}
}
/* ------------------------------------------------------------ */
@Override
public void setMaxIdleTime(int maxIdleTime)
{
super.setMaxIdleTime(maxIdleTime);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.jetty.server.server.AbstractConnector#doStart()
*/
@ -198,27 +180,22 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
super.doStart();
}
/* ------------------------------------------------------------ */
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException
{
return new SelectChannelEndPoint(channel,selectSet,key, this._maxIdleTime);
return new SelectChannelEndPoint(channel,selectSet,key, this._idleTimeout);
}
/* ------------------------------------------------------------------------------- */
protected void endPointClosed(AsyncEndPoint endpoint)
{
connectionClosed(endpoint.getAsyncConnection());
}
/* ------------------------------------------------------------------------------- */
protected AsyncConnection newConnection(SocketChannel channel,final AsyncEndPoint endpoint)
{
return new HttpConnection(SelectChannelConnector.this,endpoint,getServer());
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
private final class ConnectorSelectorManager extends SelectorManager
{
@ -237,7 +214,7 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
protected long getIdleTimeout()
{
// TODO: avoid override this method
return SelectChannelConnector.this.getMaxIdleTime();
return SelectChannelConnector.this.getIdleTimeout();
}
@Override
@ -259,7 +236,7 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
protected void connectionUpgraded(AsyncEndPoint endpoint, AsyncConnection oldConnection)
{
super.connectionUpgraded(endpoint, oldConnection);
SelectChannelConnector.this.connectionUpgraded(oldConnection,endpoint.getAsyncConnection());
SelectChannelConnector.this.connectionUpgraded(oldConnection, endpoint.getAsyncConnection());
}
@Override
@ -271,7 +248,7 @@ public class SelectChannelConnector extends HttpConnector implements NetConnecto
@Override
public AsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint, Object attachment)
{
return SelectChannelConnector.this.newConnection(channel,endpoint);
return SelectChannelConnector.this.newConnection(channel, endpoint);
}
}
}

View File

@ -55,7 +55,7 @@ public class NetworkTrafficSelectChannelConnector extends SelectChannelConnector
@Override
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.ManagedSelector selectSet, SelectionKey key) throws IOException
{
NetworkTrafficSelectChannelEndPoint endPoint = new NetworkTrafficSelectChannelEndPoint(channel, selectSet, key, _maxIdleTime, listeners);
NetworkTrafficSelectChannelEndPoint endPoint = new NetworkTrafficSelectChannelEndPoint(channel, selectSet, key, _idleTimeout, listeners);
endPoint.notifyOpened();
return endPoint;
}

View File

@ -14,9 +14,6 @@
package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -24,7 +21,6 @@ import java.net.Socket;
import java.util.Arrays;
import java.util.concurrent.Exchanger;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -39,6 +35,9 @@ import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @version $Revision: 889 $ $Date: 2009-09-14 14:52:16 +1000 (Mon, 14 Sep 2009) $
*/
@ -53,7 +52,7 @@ public class AsyncRequestReadTest
{
server = new Server();
connector = new SelectChannelConnector();
connector.setMaxIdleTime(10000);
connector.setIdleTimeout(10000);
server.addConnector(connector);
server.setHandler(new EmptyHandler());
server.start();
@ -65,7 +64,7 @@ public class AsyncRequestReadTest
server.stop();
server.join();
}
@Test
@Ignore
public void test() throws Exception
@ -84,7 +83,7 @@ public class AsyncRequestReadTest
"Connection: close\r\n"+
"\r\n";
byte[] h=header.getBytes(StringUtil.__ISO_8859_1);
out.write(h);
out.flush();
@ -103,7 +102,7 @@ public class AsyncRequestReadTest
long total=__total.exchange(0L,30,TimeUnit.SECONDS);
assertEquals(content.length, total);
}
@Test
@Ignore
public void tests() throws Exception
@ -115,13 +114,13 @@ public class AsyncRequestReadTest
runTest(256*1024,5321,10,100);
runTest(512*1024,32*1024,10,10);
}
public void runTest(int contentSize, int chunkSize, int chunks, int delayMS) throws Exception
{
String tst=contentSize+","+chunkSize+","+chunks+","+delayMS;
//System.err.println(tst);
final Socket socket = new Socket("localhost",connector.getLocalPort());
byte[] content = new byte[contentSize];
@ -155,7 +154,7 @@ public class AsyncRequestReadTest
assertEquals(tst,content.length, total);
}
private static class EmptyHandler extends AbstractHandler
{
public void handle(String path, final Request request, HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws IOException, ServletException

View File

@ -13,8 +13,6 @@
package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
@ -22,7 +20,6 @@ import java.net.Socket;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
@ -42,6 +39,8 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class AsyncStressTest
{
private static final Logger LOG = Log.getLogger(AsyncStressTest.class);
@ -69,7 +68,7 @@ public class AsyncStressTest
_threads.setMaxThreads(50);
_server.setThreadPool(_threads);
_connector = new SelectChannelConnector();
_connector.setMaxIdleTime(120000);
_connector.setIdleTimeout(120000);
_server.setConnectors(new Connector[]{ _connector });
_server.setHandler(_handler);
_server.start();
@ -322,8 +321,8 @@ public class AsyncStressTest
}
}
}
private static AsyncListener __asyncListener = new AsyncListener()
{
@Override
@ -341,7 +340,7 @@ public class AsyncStressTest
@Override
public void onError(AsyncEvent event) throws IOException
{
}
@Override

View File

@ -19,11 +19,6 @@
*/
package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
@ -36,6 +31,11 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
*
*/
@ -49,7 +49,7 @@ public class RFC2616Test
{
server = new Server();
connector = new LocalHttpConnector();
connector.setMaxIdleTime(10000);
connector.setIdleTimeout(10000);
server.addConnector(connector);
ContextHandler vcontext=new ContextHandler();
@ -123,7 +123,7 @@ public class RFC2616Test
"0;\015\012\015\012");
checkContains(response,offset,"HTTP/1.1 400 Bad","Chunked last");
}
@Test
public void test3_6_b() throws Exception
{
@ -165,7 +165,7 @@ public class RFC2616Test
offset=checkContains(response,offset,"/R3","3.6.1 Chunking");
}
@Test
public void test3_6_c() throws Exception
{
@ -207,7 +207,7 @@ public class RFC2616Test
offset=checkContains(response,offset,"/R3","3.6.1 Chunking");
}
@Test
public void test3_6_d() throws Exception
{
@ -365,7 +365,7 @@ public class RFC2616Test
offset=checkContains(response,offset,"Virtual Dump","virtual host")+1;
offset=checkContains(response,offset,"pathInfo=/path/R1","Default host")+1;
}
@Test
public void test5_2_2() throws Exception
{
@ -378,7 +378,7 @@ public class RFC2616Test
offset=checkContains(response,offset,"HTTP/1.1 200","Default host")+1;
offset=checkContains(response,offset,"Dump HttpHandler","Default host")+1;
offset=checkContains(response,offset,"pathInfo=/path/R1","Default host")+1;
// Virtual Host
offset=0;
response=connector.getResponses("GET /path/R2 HTTP/1.1\n"+"Host: VirtualHost\n"+"\n");
@ -430,7 +430,7 @@ public class RFC2616Test
response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host: localhost\n"+"\n"+
"GET /R2 HTTP/1.1\n"+"Host: localhost\n"+"Connection: close\n"+"\n"+
"GET /R3 HTTP/1.1\n"+"Host: localhost\n"+"Connection: close\n"+"\n");
offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","8.1.2 default")+1;
offset=checkContains(response,offset,"/R1","8.1.2 default")+1;
@ -452,7 +452,7 @@ public class RFC2616Test
{
String response;
int offset=0;
// Expect Failure
offset=0;
response=connector.getResponses(
@ -480,7 +480,7 @@ public class RFC2616Test
"Content-Length: 8\n"+
"Connection: close\n"+
"\n"+
"123456\015\012");
"123456\015\012");
checkNotContained(response,offset,"HTTP/1.1 100 ","8.2.3 expect 100");
offset=checkContains(response,offset,"HTTP/1.1 200 OK","8.2.3 expect with body")+1;
}
@ -501,16 +501,16 @@ public class RFC2616Test
String infomational= endp.takeOutputString();
offset=checkContains(infomational,offset,"HTTP/1.1 100 ","8.2.3 expect 100")+1;
checkNotContained(infomational,offset,"HTTP/1.1 200","8.2.3 expect 100");
endp.addInput("654321\015\012");
Thread.sleep(200);
String response= endp.takeOutputString();
offset=0;
offset=checkContains(response,offset,"HTTP/1.1 200","8.2.3 expect 100")+1;
offset=checkContains(response,offset,"654321","8.2.3 expect 100")+1;
offset=checkContains(response,offset,"654321","8.2.3 expect 100")+1;
}
@Test
public void test8_2_4() throws Exception
{
@ -855,7 +855,7 @@ public class RFC2616Test
"GET /R2 HTTP/1.0\n"+"Host: localhost\n"+"Connection: close\n"+"\n"+
"GET /R3 HTTP/1.0\n"+"Host: localhost\n"+"Connection: close\n"+"\n");
offset=checkContains(response,offset,"HTTP/1.1 200 OK\015\012","19.6.2 Keep-alive 1")+1;
offset=checkContains(response,offset,"Connection: keep-alive","19.6.2 Keep-alive 1")+1;

View File

@ -32,7 +32,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
public static void init() throws Exception
{
SelectChannelConnector connector = new SelectChannelConnector();
connector.setMaxIdleTime(MAX_IDLE_TIME); // 250 msec max idle
connector.setIdleTimeout(MAX_IDLE_TIME); // 250 msec max idle
startServer(connector);
}

View File

@ -13,17 +13,12 @@
package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import java.io.IOException;
import java.net.Socket;
import java.util.Queue;
import java.util.Random;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -31,7 +26,6 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.toolchain.test.OS;
import org.eclipse.jetty.toolchain.test.Stress;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -41,6 +35,10 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
public class StressTest
{
private static final Logger LOG = Log.getLogger(StressTest.class);
@ -91,7 +89,7 @@ public class StressTest
_connector = new SelectChannelConnector(1,1);
_connector.setAcceptQueueSize(5000);
_connector.setMaxIdleTime(30000);
_connector.setIdleTimeout(30000);
_server.addConnector(_connector);
TestHandler _handler = new TestHandler();
@ -120,7 +118,7 @@ public class StressTest
{
// TODO needs to be further investigated
assumeTrue(!OS.IS_OSX || Stress.isEnabled());
doThreads(10,10,false);
Thread.sleep(1000);
doThreads(100,20,false);
@ -138,7 +136,7 @@ public class StressTest
{
// TODO needs to be further investigated
assumeTrue(!OS.IS_OSX || Stress.isEnabled());
doThreads(20,10,true);
Thread.sleep(1000);
doThreads(100,50,true);

View File

@ -143,7 +143,7 @@ public class SslBytesServerTest extends SslBytesTest
// };
}
};
connector.setMaxIdleTime(idleTimeout);
connector.setIdleTimeout(idleTimeout);
// connector.setPort(5870);
connector.setPort(0);

View File

@ -16,7 +16,6 @@ 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;
@ -27,7 +26,7 @@ import org.junit.BeforeClass;
public class SslSelectChannelTimeoutTest extends ConnectorTimeoutTest
{
static SSLContext __sslContext;
@Override
protected Socket newSocket(String host, int port) throws Exception
{
@ -36,9 +35,9 @@ public class SslSelectChannelTimeoutTest extends ConnectorTimeoutTest
@BeforeClass
public static void init() throws Exception
{
{
SslSelectChannelConnector connector = new SslSelectChannelConnector();
connector.setMaxIdleTime(MAX_IDLE_TIME); //250 msec max idle
connector.setIdleTimeout(MAX_IDLE_TIME); //250 msec max idle
String keystorePath = System.getProperty("basedir",".") + "/src/test/resources/keystore";
SslContextFactory cf = connector.getSslContextFactory();
cf.setKeyStorePath(keystorePath);
@ -47,14 +46,14 @@ public class SslSelectChannelTimeoutTest extends ConnectorTimeoutTest
cf.setTrustStore(keystorePath);
cf.setTrustStorePassword("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);
}
}

View File

@ -12,11 +12,7 @@ package org.eclipse.jetty.servlet;
//You may elect to redistribute this code under either of these licenses.
//========================================================================
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@ -35,12 +31,15 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* This tests verifies that merging of queryStrings works when dispatching
* Requests via {@link Continuation} multiple times.
*
*
* @author tbecker
*
*
*/
public class AsyncContextDispatchWithQueryStrings {
@ -50,7 +49,7 @@ public class AsyncContextDispatchWithQueryStrings {
@Before
public void setUp() throws Exception {
_connector.setMaxIdleTime(30000);
_connector.setIdleTimeout(30000);
_server.setConnectors(new Connector[] { _connector });
_contextHandler.setContextPath("/");

View File

@ -12,15 +12,9 @@ package org.eclipse.jetty.servlet;
//You may elect to redistribute this code under either of these licenses.
//========================================================================
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType;
import javax.servlet.ServletException;
@ -30,7 +24,6 @@ import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import junit.framework.Assert;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.LocalHttpConnector;
@ -42,9 +35,14 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
* This tests the correct functioning of the AsyncContext
*
*
* tests for #371649 and #371635
*/
public class AsyncContextTest
@ -56,11 +54,11 @@ public class AsyncContextTest
@Before
public void setUp() throws Exception
{
{
_server = new Server();
_contextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
_connector = new LocalHttpConnector();
_connector.setMaxIdleTime(30000);
_connector.setIdleTimeout(30000);
_server.setConnectors(new Connector[]
{ _connector });
@ -84,7 +82,7 @@ public class AsyncContextTest
{
_server.stop();
}
@Test
public void testSimpleAsyncContext() throws Exception
{
@ -117,16 +115,16 @@ public class AsyncContextTest
Assert.assertEquals("context path attr is correct","async:run:attr:contextPath:",br.readLine());
Assert.assertEquals("request uri attr is correct","async:run:attr:requestURI:/servletPath",br.readLine());
}
@Test
public void testDispatchAsyncContextEncodedPathAndQueryString() throws Exception
{
String request = "GET /path%20with%20spaces/servletPath?dispatch=true&queryStringWithEncoding=space%20space HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ "Connection: close\r\n" + "\r\n";
String responseString = _connector.getResponses(request);
BufferedReader br = parseHeader(responseString);
assertThat("servlet gets right path",br.readLine(),equalTo("doGet:getServletPath:/servletPath2"));
assertThat("async context gets right path in get",br.readLine(), equalTo("doGet:async:getServletPath:/servletPath2"));
assertThat("servlet path attr is original",br.readLine(),equalTo("async:run:attr:servletPath:/path with spaces/servletPath"));
@ -294,7 +292,7 @@ public class AsyncContextTest
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
if (request.getParameter("dispatch") != null)
{
{
AsyncContext asyncContext = request.startAsync(request,response);
asyncContext.dispatch("/servletPath2");
}
@ -320,7 +318,7 @@ public class AsyncContextTest
{
response.getOutputStream().print("doGet:getServletPath:" + request.getServletPath() + "\n");
AsyncContext asyncContext = request.startAsync(request, response);
response.getOutputStream().print("doGet:async:getServletPath:" + ((HttpServletRequest)asyncContext.getRequest()).getServletPath() + "\n");
response.getOutputStream().print("doGet:async:getServletPath:" + ((HttpServletRequest)asyncContext.getRequest()).getServletPath() + "\n");
asyncContext.start(new AsyncRunnable(asyncContext));
return;
}
@ -338,21 +336,21 @@ public class AsyncContextTest
@Override
public void run()
{
HttpServletRequest req = (HttpServletRequest)_context.getRequest();
HttpServletRequest req = (HttpServletRequest)_context.getRequest();
try
{
_context.getResponse().getOutputStream().print("async:run:attr:servletPath:" + req.getAttribute(AsyncContext.ASYNC_SERVLET_PATH) + "\n");
_context.getResponse().getOutputStream().print("async:run:attr:pathInfo:" + req.getAttribute(AsyncContext.ASYNC_PATH_INFO) + "\n");
_context.getResponse().getOutputStream().print("async:run:attr:queryString:" + req.getAttribute(AsyncContext.ASYNC_QUERY_STRING) + "\n");
_context.getResponse().getOutputStream().print("async:run:attr:contextPath:" + req.getAttribute(AsyncContext.ASYNC_CONTEXT_PATH) + "\n");
_context.getResponse().getOutputStream().print("async:run:attr:requestURI:" + req.getAttribute(AsyncContext.ASYNC_REQUEST_URI) + "\n");
_context.getResponse().getOutputStream().print("async:run:attr:pathInfo:" + req.getAttribute(AsyncContext.ASYNC_PATH_INFO) + "\n");
_context.getResponse().getOutputStream().print("async:run:attr:queryString:" + req.getAttribute(AsyncContext.ASYNC_QUERY_STRING) + "\n");
_context.getResponse().getOutputStream().print("async:run:attr:contextPath:" + req.getAttribute(AsyncContext.ASYNC_CONTEXT_PATH) + "\n");
_context.getResponse().getOutputStream().print("async:run:attr:requestURI:" + req.getAttribute(AsyncContext.ASYNC_REQUEST_URI) + "\n");
}
catch (IOException e)
{
e.printStackTrace();
}
_context.complete();
_context.complete();
}
}
@ -363,6 +361,6 @@ public class AsyncContextTest
super(response);
}
}
}