Merge branch 'jetty-9-configuration' into jetty-9

Conflicts:
	jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslConnection.java
This commit is contained in:
Greg Wilkins 2012-09-13 08:22:06 +10:00
commit a41b6e32ac
151 changed files with 2226 additions and 1717 deletions

View File

@ -38,6 +38,11 @@
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId> <artifactId>jetty-jmx</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.spdy</groupId>
<artifactId>spdy-jetty-http</artifactId>
<version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.toolchain</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>

View File

@ -27,8 +27,7 @@ import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.security.HashLoginService; import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.HttpServerConnectionFactory;
import org.eclipse.jetty.server.NCSARequestLog; import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.server.SelectChannelConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
@ -65,13 +64,11 @@ public class LikeJettyXml
mbContainer.addBean(new Log()); mbContainer.addBean(new Log());
// Setup Connectors // Setup Connectors
SelectChannelConnector connector = new SelectChannelConnector(server); HttpConnectionFactory http = new HttpConnectionFactory();
http.getHttpChannelConfig().setSecurePort(8443);
SelectChannelConnector connector = new SelectChannelConnector(server,http);
connector.setPort(8080); connector.setPort(8080);
connector.setIdleTimeout(30000); connector.setIdleTimeout(30000);
HttpConfiguration httpConfiguration = new HttpConfiguration(null, false);
httpConfiguration.setConfidentialPort(8443);
connector.setDefaultConnectionFactory(new HttpServerConnectionFactory(connector, httpConfiguration));
// TODO connector.setStatsOn(false);
server.setConnectors(new Connector[] server.setConnectors(new Connector[]
{ connector }); { connector });
@ -94,7 +91,6 @@ public class LikeJettyXml
}); });
SelectChannelConnector sslConnector = new SelectChannelConnector(server,sslContextFactory); SelectChannelConnector sslConnector = new SelectChannelConnector(server,sslContextFactory);
sslConnector.setPort(8443); sslConnector.setPort(8443);
// TODO sslConnector.setStatsOn(false);
server.addConnector(sslConnector); server.addConnector(sslConnector);
sslConnector.open(); sslConnector.open();

View File

@ -18,10 +18,23 @@
package org.eclipse.jetty.embedded; package org.eclipse.jetty.embedded;
import org.eclipse.jetty.io.ArrayByteBufferPool;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.ForwardedRequestCustomizer;
import org.eclipse.jetty.server.HttpChannelConfig;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.server.SelectChannelConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.spdy.NPNServerConnectionFactory;
import org.eclipse.jetty.spdy.http.PushStrategy;
import org.eclipse.jetty.spdy.http.ReferrerPushStrategy;
import org.eclipse.jetty.spdy.http.HTTPSPDYServerConnectionFactory;
import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.TimerScheduler;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
@ -32,31 +45,73 @@ public class ManyConnectors
{ {
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception
{ {
String jetty_home = System.getProperty("jetty.home","../jetty-server/src/main/config");
System.setProperty("jetty.home", jetty_home);
Server server = new Server(); Server server = new Server();
// HTTP connector
SelectChannelConnector connector0 = new SelectChannelConnector(server); SelectChannelConnector connector0 = new SelectChannelConnector(server);
connector0.setPort(8080); connector0.setPort(8080);
connector0.setIdleTimeout(30000); connector0.setIdleTimeout(30000);
SelectChannelConnector connector1 = new SelectChannelConnector(server); // HTTPS connector
connector1.setHost("127.0.0.1");
connector1.setPort(8888);
String jetty_home = System.getProperty("jetty.home","../jetty-distribution/target/distribution");
System.setProperty("jetty.home", jetty_home);
SslContextFactory sslContextFactory = new SslContextFactory(); SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(jetty_home + "/etc/keystore"); sslContextFactory.setKeyStorePath(jetty_home + "/etc/keystore");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g"); sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
SelectChannelConnector sslConnector = new SelectChannelConnector(server,sslContextFactory);
sslConnector.setPort(8443);
server.setConnectors(new Connector[] SelectChannelConnector connector1 = new SelectChannelConnector(server,sslContextFactory);
{ connector0, connector1, sslConnector }); connector1.setPort(8443);
// A verbosely fully configured connector with SSL, SPDY and HTTP
HttpChannelConfig config = new HttpChannelConfig();
config.setSecureScheme("https");
config.setSecurePort(8443);
config.setOutputBufferSize(32768);
config.setRequestHeaderSize(8192);
config.setResponseHeaderSize(8192);
config.addCustomizer(new ForwardedRequestCustomizer());
config.addCustomizer(new SecureRequestCustomizer());
HttpConnectionFactory http = new HttpConnectionFactory(config);
http.setInputBufferSize(16384);
PushStrategy push = new ReferrerPushStrategy();
HTTPSPDYServerConnectionFactory spdy2 = new HTTPSPDYServerConnectionFactory(2,config,push);
spdy2.setInputBufferSize(8192);
spdy2.setInitialWindowSize(32768);
HTTPSPDYServerConnectionFactory spdy3 = new HTTPSPDYServerConnectionFactory(3,config,push);
spdy2.setInputBufferSize(8192);
NPNServerConnectionFactory npn = new NPNServerConnectionFactory(http.getProtocol(),spdy2.getProtocol(),spdy3.getProtocol());
npn.setDefaultProtocol(http.getProtocol());
npn.setInputBufferSize(1024);
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory,npn.getProtocol());
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(256);
TimerScheduler scheduler = new TimerScheduler();
ByteBufferPool bufferPool= new ArrayByteBufferPool(32,4096,32768);
SelectChannelConnector connector2 = new SelectChannelConnector(server,threadPool,scheduler,bufferPool,2,2,ssl,npn,spdy3,spdy2,http);
connector2.setDefaultProtocol("ssl-npn");
connector2.setPort(8444);
connector2.setIdleTimeout(30000);
connector2.setSoLingerTime(10000);
// Set the connectors
server.setConnectors(new Connector[] { connector0, connector1, connector2 });
server.setHandler(new HelloHandler()); server.setHandler(new HelloHandler());
server.start(); server.start();
server.dumpStdErr();
server.join(); server.join();
} }
} }

View File

@ -51,7 +51,7 @@
# for a full listing do # for a full listing do
# java -jar start.jar --list-options # java -jar start.jar --list-options
#----------------------------------------------------------- #-----------------------------------------------------------
OPTIONS=Server,jsp,resources,websocket,ext,plus OPTIONS=Server,jsp,resources,websocket,ext
#----------------------------------------------------------- #-----------------------------------------------------------
@ -64,7 +64,6 @@ etc/jetty.xml
# etc/jetty-ssl.xml # etc/jetty-ssl.xml
# etc/jetty-requestlog.xml # etc/jetty-requestlog.xml
etc/jetty-deploy.xml etc/jetty-deploy.xml
#etc/jetty-overlay.xml
etc/jetty-webapps.xml etc/jetty-webapps.xml
etc/jetty-contexts.xml etc/jetty-contexts.xml
etc/jetty-testrealm.xml etc/jetty-testrealm.xml

View File

@ -47,6 +47,8 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
// TODO: Make this class inherit from oej.util.Fields // TODO: Make this class inherit from oej.util.Fields
// TODO move this class to jetty-http?
/** /**
* HTTP Fields. A collection of HTTP header and or Trailer fields. * HTTP Fields. A collection of HTTP header and or Trailer fields.
@ -787,11 +789,11 @@ public class HttpFields implements Iterable<HttpFields.Field>
// Format value and params // Format value and params
StringBuilder buf = new StringBuilder(128); StringBuilder buf = new StringBuilder(128);
String name_value_params; String name_value_params;
boolean quoted = QuotedStringTokenizer.quoteIfNeeded(buf, name, delim); QuotedStringTokenizer.quoteIfNeeded(buf, name, delim);
buf.append('='); buf.append('=');
String start=buf.toString(); String start=buf.toString();
if (value != null && value.length() > 0) if (value != null && value.length() > 0)
quoted|=QuotedStringTokenizer.quoteIfNeeded(buf, value, delim); QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
if (path != null && path.length() > 0) if (path != null && path.length() > 0)

View File

@ -59,9 +59,9 @@ public class HttpParser
CLOSED CLOSED
}; };
private final HttpHandler _handler; private final HttpHandler<ByteBuffer> _handler;
private final RequestHandler _requestHandler; private final RequestHandler<ByteBuffer> _requestHandler;
private final ResponseHandler _responseHandler; private final ResponseHandler<ByteBuffer> _responseHandler;
private final int _maxHeaderBytes; private final int _maxHeaderBytes;
private HttpHeader _header; private HttpHeader _header;
private String _headerString; private String _headerString;
@ -91,19 +91,19 @@ public class HttpParser
private final Utf8StringBuilder _utf8=new Utf8StringBuilder(); private final Utf8StringBuilder _utf8=new Utf8StringBuilder();
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
public HttpParser(RequestHandler handler) public HttpParser(RequestHandler<ByteBuffer> handler)
{ {
this(handler,-1); this(handler,-1);
} }
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
public HttpParser(ResponseHandler handler) public HttpParser(ResponseHandler<ByteBuffer> handler)
{ {
this(handler,-1); this(handler,-1);
} }
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
public HttpParser(RequestHandler handler,int maxHeaderBytes) public HttpParser(RequestHandler<ByteBuffer> handler,int maxHeaderBytes)
{ {
_handler=handler; _handler=handler;
_requestHandler=handler; _requestHandler=handler;
@ -112,7 +112,7 @@ public class HttpParser
} }
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
public HttpParser(ResponseHandler handler,int maxHeaderBytes) public HttpParser(ResponseHandler<ByteBuffer> handler,int maxHeaderBytes)
{ {
_handler=handler; _handler=handler;
_requestHandler=null; _requestHandler=null;
@ -931,12 +931,14 @@ public class HttpParser
case CLOSED: case CLOSED:
if (BufferUtil.hasContent(buffer)) if (BufferUtil.hasContent(buffer))
{ {
_headerBytes+=buffer.remaining(); int len=buffer.remaining();
_headerBytes+=len;
if (_headerBytes>_maxHeaderBytes) if (_headerBytes>_maxHeaderBytes)
{ {
Thread.sleep(100);
String chars = BufferUtil.toDetailString(buffer); String chars = BufferUtil.toDetailString(buffer);
BufferUtil.clear(buffer); BufferUtil.clear(buffer);
throw new IllegalStateException(this+" data when CLOSED: "+chars); throw new IllegalStateException(String.format("%s %d/%d data when CLOSED:%s",this,len,_headerBytes,chars));
} }
BufferUtil.clear(buffer); BufferUtil.clear(buffer);
} }
@ -1182,6 +1184,7 @@ public class HttpParser
} }
setState(State.CLOSED); setState(State.CLOSED);
_endOfContent=EndOfContent.UNKNOWN_CONTENT; _endOfContent=EndOfContent.UNKNOWN_CONTENT;
_contentLength=-1;
_contentPosition=0; _contentPosition=0;
_responseStatus=0; _responseStatus=0;
_headerBytes=0; _headerBytes=0;
@ -1194,6 +1197,7 @@ public class HttpParser
// reset state // reset state
setState(State.START); setState(State.START);
_endOfContent=EndOfContent.UNKNOWN_CONTENT; _endOfContent=EndOfContent.UNKNOWN_CONTENT;
_contentLength=-1;
_contentPosition=0; _contentPosition=0;
_responseStatus=0; _responseStatus=0;
_contentChunk=null; _contentChunk=null;

View File

@ -115,9 +115,9 @@ public class HttpFieldsTest
header.put("name:2", "value:\r\n2"); header.put("name:2", "value:\r\n2");
ByteBuffer buffer = BufferUtil.allocate(1024); ByteBuffer buffer = BufferUtil.allocate(1024);
buffer.clear(); BufferUtil.flipToFill(buffer);
header.putTo(buffer); header.putTo(buffer);
buffer.flip(); BufferUtil.flipToFlush(buffer,0);
String out = BufferUtil.toString(buffer); String out = BufferUtil.toString(buffer);
assertThat(out,containsString("name0: value??0")); assertThat(out,containsString("name0: value??0"));
assertThat(out,containsString("name??1: value1")); assertThat(out,containsString("name??1: value1"));
@ -134,9 +134,9 @@ public class HttpFieldsTest
header.put("CONTENT-ENCODING", "gZIP"); header.put("CONTENT-ENCODING", "gZIP");
ByteBuffer buffer = BufferUtil.allocate(1024); ByteBuffer buffer = BufferUtil.allocate(1024);
buffer.clear(); BufferUtil.flipToFill(buffer);
header.putTo(buffer); header.putTo(buffer);
buffer.flip(); BufferUtil.flipToFlush(buffer,0);
String out = BufferUtil.toString(buffer); String out = BufferUtil.toString(buffer);
Assert.assertThat(out,Matchers.containsString(HttpHeader.CONNECTION+": "+HttpHeaderValue.KEEP_ALIVE)); Assert.assertThat(out,Matchers.containsString(HttpHeader.CONNECTION+": "+HttpHeaderValue.KEEP_ALIVE));

View File

@ -45,6 +45,8 @@ public abstract class AbstractConnection implements Connection
private enum State {IDLE,INTERESTED,FILLING,FILLING_INTERESTED}; private enum State {IDLE,INTERESTED,FILLING,FILLING_INTERESTED};
private final AtomicReference<State> _state = new AtomicReference<>(State.IDLE); private final AtomicReference<State> _state = new AtomicReference<>(State.IDLE);
private int _inputBufferSize=8192;
public AbstractConnection(EndPoint endp, Executor executor) public AbstractConnection(EndPoint endp, Executor executor)
{ {
this(endp, executor, true); this(endp, executor, true);
@ -118,6 +120,16 @@ public abstract class AbstractConnection implements Connection
}; };
} }
public int getInputBufferSize()
{
return _inputBufferSize;
}
public void setInputBufferSize(int inputBufferSize)
{
_inputBufferSize = inputBufferSize;
}
public Executor getExecutor() public Executor getExecutor()
{ {
return _executor; return _executor;
@ -146,7 +158,6 @@ public abstract class AbstractConnection implements Connection
break; break;
case FILLING: case FILLING:
if (_state.compareAndSet(State.FILLING,State.FILLING_INTERESTED)) if (_state.compareAndSet(State.FILLING,State.FILLING_INTERESTED))
break loop; break loop;
break; break;

View File

@ -109,7 +109,10 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements SelectorMa
Connection old = getConnection(); Connection old = getConnection();
super.setConnection(connection); super.setConnection(connection);
if (old != null && old != connection) if (old != null && old != connection)
{
LOG.debug("Upgrading connection {} -> {} on endPoint {}", old, connection, this);
_selector.getSelectorManager().connectionUpgraded(this, old); _selector.getSelectorManager().connectionUpgraded(this, old);
}
} }
@Override @Override

View File

@ -19,7 +19,9 @@
package org.eclipse.jetty.io.ssl; package org.eclipse.jetty.io.ssl;
import java.io.IOException; import java.io.IOException;
import java.net.SocketException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
@ -31,6 +33,7 @@ import javax.net.ssl.SSLException;
import org.eclipse.jetty.io.AbstractConnection; import org.eclipse.jetty.io.AbstractConnection;
import org.eclipse.jetty.io.AbstractEndPoint; import org.eclipse.jetty.io.AbstractEndPoint;
import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.ChannelEndPoint;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;
@ -111,6 +114,19 @@ public class SslConnection extends AbstractConnection
this._bufferPool = byteBufferPool; this._bufferPool = byteBufferPool;
this._sslEngine = sslEngine; this._sslEngine = sslEngine;
this._decryptedEndPoint = new DecryptedEndPoint(); this._decryptedEndPoint = new DecryptedEndPoint();
// TODO ugly
if (endPoint instanceof ChannelEndPoint)
{
try
{
((SocketChannel)((ChannelEndPoint)endPoint).getChannel()).socket().setSoLinger(true,30000);
}
catch (SocketException e)
{
throw new RuntimeIOException(e);
}
}
} }
public SSLEngine getSSLEngine() public SSLEngine getSSLEngine()
@ -396,6 +412,18 @@ public class SslConnection extends AbstractConnection
} }
} }
@Override
public void setConnection(Connection connection)
{
if (connection instanceof AbstractConnection)
{
AbstractConnection a = (AbstractConnection)connection;
if (a.getInputBufferSize()<_sslEngine.getSession().getApplicationBufferSize());
a.setInputBufferSize(_sslEngine.getSession().getApplicationBufferSize());
}
super.setConnection(connection);
}
public SslConnection getSslConnection() public SslConnection getSslConnection()
{ {
return SslConnection.this; return SslConnection.this;

View File

@ -0,0 +1,2 @@
OPTIONS=plus
etc/jetty-plus.xml

View File

View File

@ -28,9 +28,10 @@ import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.PathMap; import org.eclipse.jetty.http.PathMap;
import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpChannel;
import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpChannelConfig;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response; import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.UserIdentity; import org.eclipse.jetty.server.UserIdentity;
@ -87,12 +88,14 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
/** /**
* @return Returns the constraintMappings. * @return Returns the constraintMappings.
*/ */
@Override
public List<ConstraintMapping> getConstraintMappings() public List<ConstraintMapping> getConstraintMappings()
{ {
return _constraintMappings; return _constraintMappings;
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@Override
public Set<String> getRoles() public Set<String> getRoles()
{ {
return _roles; return _roles;
@ -134,6 +137,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
* The constraintMappings to set. * The constraintMappings to set.
* @param roles The known roles (or null to determine them from the mappings) * @param roles The known roles (or null to determine them from the mappings)
*/ */
@Override
public void setConstraintMappings(List<ConstraintMapping> constraintMappings, Set<String> roles) public void setConstraintMappings(List<ConstraintMapping> constraintMappings, Set<String> roles)
{ {
if (isStarted()) if (isStarted())
@ -181,6 +185,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
/** /**
* @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping)
*/ */
@Override
public void addConstraintMapping(ConstraintMapping mapping) public void addConstraintMapping(ConstraintMapping mapping)
{ {
_constraintMappings.add(mapping); _constraintMappings.add(mapping);
@ -198,6 +203,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
/** /**
* @see org.eclipse.jetty.security.ConstraintAware#addRole(java.lang.String) * @see org.eclipse.jetty.security.ConstraintAware#addRole(java.lang.String)
*/ */
@Override
public void addRole(String role) public void addRole(String role)
{ {
boolean modified = _roles.add(role); boolean modified = _roles.add(role);
@ -325,6 +331,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
} }
} }
@Override
protected RoleInfo prepareConstraintInfo(String pathInContext, Request request) protected RoleInfo prepareConstraintInfo(String pathInContext, Request request)
{ {
Map<String, RoleInfo> mappings = _constraintMap.match(pathInContext); Map<String, RoleInfo> mappings = _constraintMap.match(pathInContext);
@ -354,34 +361,16 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
if (dataConstraint == null || dataConstraint == UserDataConstraint.None) if (dataConstraint == null || dataConstraint == UserDataConstraint.None)
return true; return true;
HttpConfiguration httpConfiguration = HttpChannel.getCurrentHttpChannel().getHttpConfiguration(); HttpChannelConfig httpConfig = HttpChannel.getCurrentHttpChannel().getHttpChannelConfig();
if (dataConstraint == UserDataConstraint.Integral) if (dataConstraint == UserDataConstraint.Confidential || dataConstraint == UserDataConstraint.Integral)
{ {
if (httpConfiguration.isIntegral(request)) if (request.isSecure())
return true;
if (httpConfiguration.getIntegralPort() > 0)
{
String url = httpConfiguration.getIntegralScheme() + "://" + request.getServerName() + ":" + httpConfiguration.getIntegralPort() + request.getRequestURI();
if (request.getQueryString() != null)
url += "?" + request.getQueryString();
response.setContentLength(0);
response.sendRedirect(url);
}
else
response.sendError(Response.SC_FORBIDDEN,"!Integral");
request.setHandled(true);
return false;
}
else if (dataConstraint == UserDataConstraint.Confidential)
{
if (httpConfiguration.isConfidential(request))
return true; return true;
if (httpConfiguration.getConfidentialPort() > 0) if (httpConfig.getSecurePort() > 0)
{ {
String url = httpConfiguration.getConfidentialScheme() + "://" + request.getServerName() + ":" + httpConfiguration.getConfidentialPort() String url = httpConfig.getSecureScheme() + "://" + request.getServerName() + ":" + httpConfig.getSecurePort()
+ request.getRequestURI(); + request.getRequestURI();
if (request.getQueryString() != null) if (request.getQueryString() != null)
url += "?" + request.getQueryString(); url += "?" + request.getQueryString();
@ -390,7 +379,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
response.sendRedirect(url); response.sendRedirect(url);
} }
else else
response.sendError(Response.SC_FORBIDDEN,"!Confidential"); response.sendError(HttpStatus.FORBIDDEN_403,"!Secure");
request.setHandled(true); request.setHandled(true);
return false; return false;
@ -402,6 +391,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr
} }
@Override
protected boolean isAuthMandatory(Request baseRequest, Response base_response, Object constraintInfo) protected boolean isAuthMandatory(Request baseRequest, Response base_response, Object constraintInfo)
{ {
return constraintInfo != null && ((RoleInfo)constraintInfo).isChecked(); return constraintInfo != null && ((RoleInfo)constraintInfo).isChecked();

View File

@ -28,8 +28,8 @@ import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.security.authentication.BasicAuthenticator; import org.eclipse.jetty.security.authentication.BasicAuthenticator;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpChannelConfig;
import org.eclipse.jetty.server.HttpServerConnectionFactory; import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
@ -60,38 +60,25 @@ public class DataConstraintsTest
public void startServer() public void startServer()
{ {
_server = new Server(); _server = new Server();
_connector = new LocalConnector(_server);
_connector.setIdleTimeout(300000);
HttpConfiguration httpConfiguration = new HttpConfiguration(null, false);
httpConfiguration.setIntegralPort(9998);
httpConfiguration.setIntegralScheme("FTP");
httpConfiguration.setConfidentialPort(9999);
httpConfiguration.setConfidentialScheme("SPDY");
_connector.setDefaultConnectionFactory(new HttpServerConnectionFactory(_connector, httpConfiguration));
_connectorS = new LocalConnector(_server); HttpConnectionFactory http = new HttpConnectionFactory();
_connectorS.setDefaultConnectionFactory(new HttpServerConnectionFactory(_connectorS, new HttpConfiguration(null,false) http.getHttpChannelConfig().setSecurePort(9999);
http.getHttpChannelConfig().setSecureScheme("BWTP");
_connector = new LocalConnector(_server,http);
_connector.setIdleTimeout(300000);
HttpConnectionFactory https = new HttpConnectionFactory();
https.getHttpChannelConfig().addCustomizer(new HttpChannelConfig.Customizer()
{ {
@Override @Override
public void customize(Request request) throws IOException public void customize(Connector connector, HttpChannelConfig channelConfig, Request request)
{ {
request.setScheme(HttpScheme.HTTPS.asString()); request.setScheme(HttpScheme.HTTPS.asString());
super.customize(request); request.setSecure(true);
} }
});
_connectorS = new LocalConnector(_server,https);
@Override
public boolean isIntegral(Request request)
{
return true;
}
@Override
public boolean isConfidential(Request request)
{
return true;
}
}));
_server.setConnectors(new Connector[]{_connector,_connectorS}); _server.setConnectors(new Connector[]{_connector,_connectorS});
ContextHandler _context = new ContextHandler(); ContextHandler _context = new ContextHandler();
@ -106,6 +93,7 @@ public class DataConstraintsTest
_security.setHandler(new AbstractHandler() _security.setHandler(new AbstractHandler()
{ {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{ {
baseRequest.setHandled(true); baseRequest.setHandled(true);
@ -149,8 +137,8 @@ public class DataConstraintsTest
response = _connector.getResponses("GET /ctx/integral/info HTTP/1.0\r\n\r\n"); response = _connector.getResponses("GET /ctx/integral/info HTTP/1.0\r\n\r\n");
assertThat(response, containsString("HTTP/1.1 302 Found")); assertThat(response, containsString("HTTP/1.1 302 Found"));
assertThat(response, containsString("Location: FTP://")); assertThat(response, containsString("Location: BWTP://"));
assertThat(response, containsString(":9998")); assertThat(response, containsString(":9999"));
response = _connectorS.getResponses("GET /ctx/integral/info HTTP/1.0\r\n\r\n"); response = _connectorS.getResponses("GET /ctx/integral/info HTTP/1.0\r\n\r\n");
assertThat(response, containsString("HTTP/1.1 404 Not Found")); assertThat(response, containsString("HTTP/1.1 404 Not Found"));
@ -181,7 +169,7 @@ public class DataConstraintsTest
response = _connector.getResponses("GET /ctx/confid/info HTTP/1.0\r\n\r\n"); response = _connector.getResponses("GET /ctx/confid/info HTTP/1.0\r\n\r\n");
assertThat(response, containsString("HTTP/1.1 302 Found")); assertThat(response, containsString("HTTP/1.1 302 Found"));
assertThat(response, containsString("Location: SPDY://")); assertThat(response, containsString("Location: BWTP://"));
assertThat(response, containsString(":9999")); assertThat(response, containsString(":9999"));
response = _connectorS.getResponses("GET /ctx/confid/info HTTP/1.0\r\n\r\n"); response = _connectorS.getResponses("GET /ctx/confid/info HTTP/1.0\r\n\r\n");
@ -444,11 +432,14 @@ public class DataConstraintsTest
{ {
this.identityService = identityService; this.identityService = identityService;
} }
@Override
public String getName() public String getName()
{ {
return "name"; return "name";
} }
@Override
public UserIdentity login(String username, Object credentials) public UserIdentity login(String username, Object credentials)
{ {
if("admin".equals(username) && "password".equals(credentials)) if("admin".equals(username) && "password".equals(credentials))
@ -456,20 +447,24 @@ public class DataConstraintsTest
return null; return null;
} }
@Override
public boolean validate(UserIdentity user) public boolean validate(UserIdentity user)
{ {
return false; return false;
} }
@Override
public IdentityService getIdentityService() public IdentityService getIdentityService()
{ {
return identityService; return identityService;
} }
@Override
public void setIdentityService(IdentityService service) public void setIdentityService(IdentityService service)
{ {
} }
@Override
public void logout(UserIdentity user) public void logout(UserIdentity user)
{ {
} }

View File

@ -38,7 +38,7 @@
<Arg name="server"><Ref id="Server" /></Arg> <Arg name="server"><Ref id="Server" /></Arg>
<Set name="host"><Property name="jetty.host" /></Set> <Set name="host"><Property name="jetty.host" /></Set>
<Set name="port"><Property name="jetty.port" default="8080"/></Set> <Set name="port"><Property name="jetty.port" default="8080"/></Set>
<Set name="idleTimeout">300000</Set> <Set name="idleTimeout">30000</Set>
</New> </New>
</Arg> </Arg>
</Call> </Call>

View File

@ -0,0 +1,78 @@
//
// ========================================================================
// Copyright (c) 1995-2012 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.util.ArrayUtil;
import org.eclipse.jetty.util.component.AggregateLifeCycle;
import org.eclipse.jetty.util.ssl.SslContextFactory;
public abstract class AbstractConnectionFactory extends AggregateLifeCycle implements ConnectionFactory
{
final String _protocol;
int _inputbufferSize=8192;
protected AbstractConnectionFactory(String protocol)
{
_protocol=protocol;
}
@Override
public String getProtocol()
{
return _protocol;
}
public int getInputBufferSize()
{
return _inputbufferSize;
}
public void setInputBufferSize(int size)
{
_inputbufferSize=size;
}
@Override
public String toString()
{
return String.format("%s@%x{%s}",this.getClass().getSimpleName(),hashCode(),getProtocol());
}
public static ConnectionFactory[] getFactories(SslContextFactory sslContextFactory, ConnectionFactory... factories)
{
factories=ArrayUtil.removeNulls(factories);
if (sslContextFactory==null)
return factories;
for (ConnectionFactory factory : factories)
{
if (factory instanceof HttpChannelConfig.ConnectionFactory)
{
HttpChannelConfig config = ((HttpChannelConfig.ConnectionFactory)factory).getHttpChannelConfig();
if (config.getCustomizer(SecureRequestCustomizer.class)==null)
config.addCustomizer(new SecureRequestCustomizer());
}
}
return ArrayUtil.prependToArray(new SslConnectionFactory(sslContextFactory,factories[0].getProtocol()),factories,ConnectionFactory.class);
}
}

View File

@ -20,7 +20,10 @@ package org.eclipse.jetty.server;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -37,36 +40,49 @@ import org.eclipse.jetty.util.component.AggregateLifeCycle;
import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.util.thread.TimerScheduler; import org.eclipse.jetty.util.thread.TimerScheduler;
/** /**
* <p>Partial implementation of {@link Connector}</p> * <p>Partial implementation of {@link Connector}</p>
*
* <p>
* The connector keeps a collection of {@link ConnectionFactory} instances, each of which are known by their
* protocol name. The protocol name may be a real protocol (eg http/1.1 or spdy/3) or it may be a private name
* that represents a special connection factory. For example, the name "SSL-http/1.1" is used for
* an {@link SslConnectionFactory} that has been instantiated with the {@link HttpConnectionFactory} as it's
* next protocol.
* <p>
* If NPN is used to select the real protocol used by an SSL connection, then the name "SSL-NPN" is used,
* which represents a {@link SslConnectionFactory} with a NPNConnectionFactory as the next protocol. Once
* the NPN connection is established, it will get the next protocol from the NPN extension and then call
* {@link #getConnectionFactory(String)} to get the next connection factory.
*
*/ */
@ManagedObject("Abstract implementation of the Connector Interface") @ManagedObject("Abstract implementation of the Connector Interface")
public abstract class AbstractConnector extends AggregateLifeCycle implements Connector, Dumpable public abstract class AbstractConnector extends AggregateLifeCycle implements Connector, Dumpable
{ {
protected final Logger LOG = Log.getLogger(getClass()); protected final Logger LOG = Log.getLogger(getClass());
// Order is important on server side, so we use a LinkedHashMap // Order is important on server side, so we use a LinkedHashMap
private final Map<String, ConnectionFactory> factories = new LinkedHashMap<>(); private final Map<String, ConnectionFactory> _factories = new LinkedHashMap<>();
private final Statistics _stats = new ConnectorStatistics(); private final Statistics _stats = new ConnectorStatistics();
private final Server _server; private final Server _server;
private final SslContextFactory _sslContextFactory;
private final Executor _executor; private final Executor _executor;
private final Scheduler _scheduler; private final Scheduler _scheduler;
private final ByteBufferPool _byteBufferPool; private final ByteBufferPool _byteBufferPool;
private final Thread[] _acceptors; private final Thread[] _acceptors;
private volatile CountDownLatch _stopping; private volatile CountDownLatch _stopping;
private volatile long _idleTimeout = 200000; private long _idleTimeout = 200000;
private volatile ConnectionFactory defaultConnectionFactory; private String _defaultProtocol;
private ConnectionFactory _defaultConnectionFactory;
/** /**
* @param server The server this connector will be added to. Must not be null. * @param server The server this connector will be added to. Must not be null.
* @param factory TODO
* @param sslContextFactory the SSL context factory to make this connector SSL enabled, or null
* @param executor An executor for this connector or null to use the servers executor * @param executor An executor for this connector or null to use the servers executor
* @param scheduler A scheduler for this connector or null to use the servers scheduler * @param scheduler A scheduler for this connector or null to use the servers scheduler
* @param pool A buffer pool for this connector or null to use a default {@link ByteBufferPool} * @param pool A buffer pool for this connector or null to use a default {@link ByteBufferPool}
* @param sslContextFactory the SSL context factory to make this connector SSL enabled, or null
* @param acceptors the number of acceptor threads to use, or 0 for a default value. * @param acceptors the number of acceptor threads to use, or 0 for a default value.
*/ */
public AbstractConnector( public AbstractConnector(
@ -74,14 +90,13 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
Executor executor, Executor executor,
Scheduler scheduler, Scheduler scheduler,
ByteBufferPool pool, ByteBufferPool pool,
SslContextFactory sslContextFactory, int acceptors,
int acceptors) ConnectionFactory... factories)
{ {
_server=server; _server=server;
_executor=executor!=null?executor:_server.getThreadPool(); _executor=executor!=null?executor:_server.getThreadPool();
_scheduler=scheduler!=null?scheduler:new TimerScheduler(); _scheduler=scheduler!=null?scheduler:new TimerScheduler();
_byteBufferPool = pool!=null?pool:new ArrayByteBufferPool(); _byteBufferPool = pool!=null?pool:new ArrayByteBufferPool();
_sslContextFactory = sslContextFactory;
addBean(_server,false); addBean(_server,false);
addBean(_executor); addBean(_executor);
@ -89,9 +104,11 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
unmanage(_executor); // inherited from server unmanage(_executor); // inherited from server
addBean(_scheduler); addBean(_scheduler);
addBean(_byteBufferPool); addBean(_byteBufferPool);
addBean(_sslContextFactory);
addBean(_stats,true); addBean(_stats,true);
for (ConnectionFactory factory:factories)
addConnectionFactory(factory);
if (acceptors<=0) if (acceptors<=0)
acceptors=Math.max(1,(Runtime.getRuntime().availableProcessors()) / 4); acceptors=Math.max(1,(Runtime.getRuntime().availableProcessors()) / 4);
if (acceptors > 2 * Runtime.getRuntime().availableProcessors()) if (acceptors > 2 * Runtime.getRuntime().availableProcessors())
@ -123,12 +140,6 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
return _byteBufferPool; return _byteBufferPool;
} }
@Override
public SslContextFactory getSslContextFactory()
{
return _sslContextFactory;
}
@Override @Override
public long getIdleTimeout() public long getIdleTimeout()
{ {
@ -162,10 +173,13 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
return _acceptors.length; return _acceptors.length;
} }
@Override @Override
protected void doStart() throws Exception protected void doStart() throws Exception
{ {
_defaultConnectionFactory = getConnectionFactory(_defaultProtocol);
if(_defaultConnectionFactory==null)
throw new IllegalStateException("No protocol factory for default protocol: "+_defaultProtocol);
super.doStart(); super.doStart();
_stopping=new CountDownLatch(_acceptors.length); _stopping=new CountDownLatch(_acceptors.length);
@ -232,54 +246,95 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
return isRunning(); return isRunning();
} }
@Override
public ConnectionFactory getConnectionFactory(String protocol) public ConnectionFactory getConnectionFactory(String protocol)
{ {
synchronized (factories) synchronized (_factories)
{ {
return factories.get(protocol); return _factories.get(protocol.toLowerCase());
} }
} }
public ConnectionFactory putConnectionFactory(String protocol, ConnectionFactory factory) @Override
public <T extends ConnectionFactory> T getConnectionFactory(Class<T> factoryType)
{ {
synchronized (factories) synchronized (_factories)
{ {
return factories.put(protocol, factory); for (ConnectionFactory f : _factories.values())
if (factoryType.isAssignableFrom(f.getClass()))
return (T)f;
return null;
}
}
public void addConnectionFactory(ConnectionFactory factory)
{
synchronized (_factories)
{
ConnectionFactory old=_factories.remove(factory.getProtocol());
if (old!=null)
removeBean(old);
_factories.put(factory.getProtocol().toLowerCase(), factory);
addBean(factory);
if (_defaultProtocol==null)
_defaultProtocol=factory.getProtocol();
} }
} }
public ConnectionFactory removeConnectionFactory(String protocol) public ConnectionFactory removeConnectionFactory(String protocol)
{ {
synchronized (factories) synchronized (_factories)
{ {
return factories.remove(protocol); ConnectionFactory factory= _factories.remove(protocol.toLowerCase());
removeBean(factory);
return factory;
} }
} }
public Map<String, ConnectionFactory> getConnectionFactories() @Override
public Collection<ConnectionFactory> getConnectionFactories()
{ {
synchronized (factories) synchronized (_factories)
{ {
return new LinkedHashMap<>(factories); return _factories.values();
}
}
@Override
public List<String> getProtocols()
{
synchronized (_factories)
{
return new ArrayList<>(_factories.keySet());
} }
} }
public void clearConnectionFactories() public void clearConnectionFactories()
{ {
synchronized (factories) synchronized (_factories)
{ {
factories.clear(); _factories.clear();
} }
} }
public ConnectionFactory getDefaultConnectionFactory() public String getDefaultProtocol()
{ {
return defaultConnectionFactory; return _defaultProtocol;
} }
public void setDefaultConnectionFactory(ConnectionFactory defaultConnectionFactory) public void setDefaultProtocol(String defaultProtocol)
{ {
this.defaultConnectionFactory = defaultConnectionFactory; if(isRunning())
throw new IllegalStateException(getState());
_defaultProtocol = defaultProtocol.toLowerCase();
}
@Override
public ConnectionFactory getDefaultConnectionFactory()
{
if (isStarted())
return _defaultConnectionFactory;
return getConnectionFactory(_defaultProtocol);
} }
private class Acceptor implements Runnable private class Acceptor implements Runnable
@ -358,4 +413,13 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
{ {
return _scheduler; return _scheduler;
} }
@Override
public String toString()
{
return String.format("%s@%x{%s}",
getClass().getSimpleName(),
hashCode(),
getDefaultProtocol());
}
} }

View File

@ -23,7 +23,6 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.util.thread.Scheduler;
/** /**
@ -34,9 +33,9 @@ public abstract class AbstractNetworkConnector extends AbstractConnector impleme
private volatile String _host; private volatile String _host;
private volatile int _port = 0; private volatile int _port = 0;
public AbstractNetworkConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, SslContextFactory sslContextFactory, int acceptors) public AbstractNetworkConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, int acceptors, ConnectionFactory... factories)
{ {
super(server, executor, scheduler, pool, sslContextFactory, acceptors); super(server,executor,scheduler,pool,acceptors,factories);
} }
public void setHost(String host) public void setHost(String host)
@ -110,8 +109,8 @@ public abstract class AbstractNetworkConnector extends AbstractConnector impleme
@Override @Override
public String toString() public String toString()
{ {
return String.format("%s@%s:%d", return String.format("%s{%s:%d}",
getClass().getSimpleName(), super.toString(),
getHost() == null ? "0.0.0.0" : getHost(), getHost() == null ? "0.0.0.0" : getHost(),
getLocalPort() <= 0 ? getPort() : getLocalPort()); getLocalPort() <= 0 ? getPort() : getLocalPort());
} }

View File

@ -42,6 +42,5 @@ public class ByteBufferHttpInput extends HttpInput<ByteBuffer>
@Override @Override
protected void onContentConsumed(ByteBuffer item) protected void onContentConsumed(ByteBuffer item)
{ {
item.clear();
} }
} }

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import java.nio.channels.SocketChannel;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
@ -28,12 +27,14 @@ import org.eclipse.jetty.io.EndPoint;
*/ */
public interface ConnectionFactory public interface ConnectionFactory
{ {
public String getProtocol();
/** /**
* <p>Creates a new {@link Connection} with the given parameters</p> * <p>Creates a new {@link Connection} with the given parameters</p>
* @param channel the {@link SocketChannel} associated with the connection * @param connector The {@link Connector} creating this connection
* @param endPoint the {@link EndPoint} associated with the connection * @param endPoint the {@link EndPoint} associated with the connection
* @param attachment the attachment associated with the connection
* @return a new {@link Connection} * @return a new {@link Connection}
*/ */
public Connection newConnection(SocketChannel channel, EndPoint endPoint, Object attachment); public Connection newConnection(Connector connector, EndPoint endPoint);
} }

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.ByteBufferPool;
@ -25,7 +27,6 @@ import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.Graceful; import org.eclipse.jetty.util.component.Graceful;
import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.util.thread.Scheduler;
/** /**
@ -57,9 +58,21 @@ public interface Connector extends LifeCycle, Graceful
public ByteBufferPool getByteBufferPool(); public ByteBufferPool getByteBufferPool();
/** /**
* @return the {@link SslContextFactory} associated with this {@link Connector} * @return the {@link ConnectionFactory} associated with the protocol name
*/ */
public SslContextFactory getSslContextFactory(); public ConnectionFactory getConnectionFactory(String nextProtocol);
public <T extends ConnectionFactory> T getConnectionFactory(Class<T> factoryType);
/**
* @return the default {@link ConnectionFactory} associated with the default protocol name
*/
public ConnectionFactory getDefaultConnectionFactory();
public Collection<ConnectionFactory> getConnectionFactories();
public List<String> getProtocols();
/** /**
* @return the dle timeout for connections in milliseconds * @return the dle timeout for connections in milliseconds
@ -199,4 +212,6 @@ public interface Connector extends LifeCycle, Graceful
*/ */
public void connectionClosed(long duration, int messagesIn, int messagesOut); public void connectionClosed(long duration, int messagesIn, int messagesOut);
} }
} }

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException; import javax.servlet.ServletException;

View File

@ -0,0 +1,280 @@
//
// ========================================================================
// Copyright (c) 1995-2012 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 java.net.InetSocketAddress;
import javax.servlet.ServletRequest;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.server.HttpChannelConfig.Customizer;
public class ForwardedRequestCustomizer implements Customizer
{
private String _hostHeader;
private String _forwardedHostHeader = HttpHeader.X_FORWARDED_HOST.toString();
private String _forwardedServerHeader = HttpHeader.X_FORWARDED_SERVER.toString();
private String _forwardedForHeader = HttpHeader.X_FORWARDED_FOR.toString();
private String _forwardedProtoHeader = HttpHeader.X_FORWARDED_PROTO.toString();
private String _forwardedCipherSuiteHeader;
private String _forwardedSslSessionIdHeader;
/* ------------------------------------------------------------ */
public String getHostHeader()
{
return _hostHeader;
}
/* ------------------------------------------------------------ */
/**
* Set a forced valued for the host header to control what is returned by {@link ServletRequest#getServerName()} and {@link ServletRequest#getServerPort()}.
* This value is only used if {@link #isForwarded()} is true.
*
* @param hostHeader
* The value of the host header to force.
*/
public void setHostHeader(String hostHeader)
{
_hostHeader = hostHeader;
}
/* ------------------------------------------------------------ */
/*
*
* @see #setForwarded(boolean)
*/
public String getForwardedHostHeader()
{
return _forwardedHostHeader;
}
/* ------------------------------------------------------------ */
/**
* @param forwardedHostHeader
* The header name for forwarded hosts (default x-forwarded-host)
* @see #setForwarded(boolean)
*/
public void setForwardedHostHeader(String forwardedHostHeader)
{
_forwardedHostHeader = forwardedHostHeader;
}
/* ------------------------------------------------------------ */
/**
* @return the header name for forwarded server.
* @see #setForwarded(boolean)
*/
public String getForwardedServerHeader()
{
return _forwardedServerHeader;
}
/* ------------------------------------------------------------ */
/**
* @param forwardedServerHeader
* The header name for forwarded server (default x-forwarded-server)
* @see #setForwarded(boolean)
*/
public void setForwardedServerHeader(String forwardedServerHeader)
{
_forwardedServerHeader = forwardedServerHeader;
}
/* ------------------------------------------------------------ */
/**
* @return the forwarded for header
* @see #setForwarded(boolean)
*/
public String getForwardedForHeader()
{
return _forwardedForHeader;
}
/* ------------------------------------------------------------ */
/**
* @param forwardedRemoteAddressHeader
* The header name for forwarded for (default x-forwarded-for)
* @see #setForwarded(boolean)
*/
public void setForwardedForHeader(String forwardedRemoteAddressHeader)
{
_forwardedForHeader = forwardedRemoteAddressHeader;
}
/* ------------------------------------------------------------ */
/**
* Get the forwardedProtoHeader.
*
* @return the forwardedProtoHeader (default X-Forwarded-For)
* @see #setForwarded(boolean)
*/
public String getForwardedProtoHeader()
{
return _forwardedProtoHeader;
}
/* ------------------------------------------------------------ */
/**
* Set the forwardedProtoHeader.
*
* @param forwardedProtoHeader
* the forwardedProtoHeader to set (default X-Forwarded-For)
* @see #setForwarded(boolean)
*/
public void setForwardedProtoHeader(String forwardedProtoHeader)
{
_forwardedProtoHeader = forwardedProtoHeader;
}
/* ------------------------------------------------------------ */
/**
* @return The header name holding a forwarded cipher suite (default null)
*/
public String getForwardedCipherSuiteHeader()
{
return _forwardedCipherSuiteHeader;
}
/* ------------------------------------------------------------ */
/**
* @param forwardedCipherSuite
* The header name holding a forwarded cipher suite (default null)
*/
public void setForwardedCipherSuiteHeader(String forwardedCipherSuite)
{
_forwardedCipherSuiteHeader = forwardedCipherSuite;
}
/* ------------------------------------------------------------ */
/**
* @return The header name holding a forwarded SSL Session ID (default null)
*/
public String getForwardedSslSessionIdHeader()
{
return _forwardedSslSessionIdHeader;
}
/* ------------------------------------------------------------ */
/**
* @param forwardedSslSessionId
* The header name holding a forwarded SSL Session ID (default null)
*/
public void setForwardedSslSessionIdHeader(String forwardedSslSessionId)
{
_forwardedSslSessionIdHeader = forwardedSslSessionId;
}
/* ------------------------------------------------------------ */
@Override
public void customize(Connector connector, HttpChannelConfig config, Request request)
{
HttpFields httpFields = request.getHttpFields();
// Do SSL first
if (getForwardedCipherSuiteHeader()!=null)
{
String cipher_suite=httpFields.getStringField(getForwardedCipherSuiteHeader());
if (cipher_suite!=null)
request.setAttribute("javax.servlet.request.cipher_suite",cipher_suite);
}
if (getForwardedSslSessionIdHeader()!=null)
{
String ssl_session_id=httpFields.getStringField(getForwardedSslSessionIdHeader());
if(ssl_session_id!=null)
{
request.setAttribute("javax.servlet.request.ssl_session_id", ssl_session_id);
request.setScheme(HttpScheme.HTTPS.asString());
}
}
// Retrieving headers from the request
String forwardedHost = getLeftMostFieldValue(httpFields,getForwardedHostHeader());
String forwardedServer = getLeftMostFieldValue(httpFields,getForwardedServerHeader());
String forwardedFor = getLeftMostFieldValue(httpFields,getForwardedForHeader());
String forwardedProto = getLeftMostFieldValue(httpFields,getForwardedProtoHeader());
if (_hostHeader != null)
{
// Update host header
httpFields.put(HttpHeader.HOST.toString(),_hostHeader);
request.setServerName(null);
request.setServerPort(-1);
request.getServerName();
}
else if (forwardedHost != null)
{
// Update host header
httpFields.put(HttpHeader.HOST.toString(),forwardedHost);
request.setServerName(null);
request.setServerPort(-1);
request.getServerName();
}
else if (forwardedServer != null)
{
// Use provided server name
request.setServerName(forwardedServer);
}
if (forwardedFor != null)
{
request.setRemoteAddr(new InetSocketAddress(forwardedFor,request.getRemotePort()));
}
if (forwardedProto != null)
{
request.setScheme(forwardedProto);
if (forwardedProto.equals(config.getSecureScheme()))
request.setSecure(true);
}
}
/* ------------------------------------------------------------ */
protected String getLeftMostFieldValue(HttpFields fields, String header)
{
if (header == null)
return null;
String headerValue = fields.getStringField(header);
if (headerValue == null)
return null;
int commaIndex = headerValue.indexOf(',');
if (commaIndex == -1)
{
// Single value
return headerValue;
}
// The left-most value is the farthest downstream client
return headerValue.substring(0,commaIndex);
}
/* ------------------------------------------------------------ */
@Override
public String toString()
{
return String.format("%s@%x",this.getClass().getSimpleName(),hashCode());
}
}

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
@ -63,14 +64,14 @@ import org.eclipse.jetty.util.thread.Scheduler;
public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
{ {
private static final Logger LOG = Log.getLogger(HttpChannel.class); private static final Logger LOG = Log.getLogger(HttpChannel.class);
private static final ThreadLocal<HttpChannel> __currentChannel = new ThreadLocal<>(); private static final ThreadLocal<HttpChannel<?>> __currentChannel = new ThreadLocal<>();
public static HttpChannel getCurrentHttpChannel() public static HttpChannel<?> getCurrentHttpChannel()
{ {
return __currentChannel.get(); return __currentChannel.get();
} }
protected static void setCurrentHttpChannel(HttpChannel channel) protected static void setCurrentHttpChannel(HttpChannel<?> channel)
{ {
__currentChannel.set(channel); __currentChannel.set(channel);
} }
@ -78,7 +79,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
private final AtomicBoolean _committed = new AtomicBoolean(); private final AtomicBoolean _committed = new AtomicBoolean();
private final AtomicInteger _requests = new AtomicInteger(); private final AtomicInteger _requests = new AtomicInteger();
private final Connector _connector; private final Connector _connector;
private final HttpConfiguration _configuration; private final HttpChannelConfig _configuration;
private final EndPoint _endPoint; private final EndPoint _endPoint;
private final HttpTransport _transport; private final HttpTransport _transport;
private final HttpURI _uri; private final HttpURI _uri;
@ -90,7 +91,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
private boolean _expect100Continue = false; private boolean _expect100Continue = false;
private boolean _expect102Processing = false; private boolean _expect102Processing = false;
public HttpChannel(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport, HttpInput<T> input) public HttpChannel(Connector connector, HttpChannelConfig configuration, EndPoint endPoint, HttpTransport transport, HttpInput<T> input)
{ {
_connector = connector; _connector = connector;
_configuration = configuration; _configuration = configuration;
@ -131,7 +132,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
return _connector.getByteBufferPool(); return _connector.getByteBufferPool();
} }
public HttpConfiguration getHttpConfiguration() public HttpChannelConfig getHttpChannelConfig()
{ {
return _configuration; return _configuration;
} }
@ -237,8 +238,11 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
if (_state.isInitial()) if (_state.isInitial())
{ {
_request.setTimeStamp(System.currentTimeMillis());
_request.setDispatcherType(DispatcherType.REQUEST); _request.setDispatcherType(DispatcherType.REQUEST);
getHttpConfiguration().customize(_request);
for (HttpChannelConfig.Customizer customizer : _configuration.getCustomizers())
customizer.customize(getConnector(),_configuration,_request);
getServer().handle(this); getServer().handle(this);
} }
else else
@ -321,7 +325,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
if (_state.isSuspended()) if (_state.isSuspended())
{ {
HttpFields fields = new HttpFields(); HttpFields fields = new HttpFields();
ResponseInfo info = new ResponseInfo(_request.getHttpVersion(), fields, 0, Response.SC_INTERNAL_SERVER_ERROR, null, _request.isHead()); ResponseInfo info = new ResponseInfo(_request.getHttpVersion(), fields, 0, HttpStatus.INTERNAL_SERVER_ERROR_500, null, _request.isHead());
boolean committed = commitResponse(info, null, true); boolean committed = commitResponse(info, null, true);
if (!committed) if (!committed)
LOG.warn("Could not send response error 500: "+x); LOG.warn("Could not send response error 500: "+x);
@ -515,7 +519,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("{} content {}", this, item); LOG.debug("{} content {}", this, item);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
HttpInput<T> input = _request.getHttpInput(); HttpInput<T> input = (HttpInput<T>)_request.getHttpInput();
input.content(item); input.content(item);
return true; return true;
} }

View File

@ -0,0 +1,124 @@
//
// ========================================================================
// Copyright (c) 1995-2012 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 java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jetty.http.HttpScheme;
public class HttpChannelConfig
{
private List<Customizer> _customizers=new CopyOnWriteArrayList<>();
private int _outputBufferSize=32*1024;
private int _requestHeaderSize=8*1024;
private int _responseHeaderSize=8*1024;
private int _securePort;
private String _secureScheme = HttpScheme.HTTPS.asString();
public interface Customizer
{
public void customize(Connector connector, HttpChannelConfig channelConfig, Request request);
}
public interface ConnectionFactory
{
HttpChannelConfig getHttpChannelConfig();
}
public void addCustomizer(Customizer customizer)
{
_customizers.add(customizer);
}
public List<Customizer> getCustomizers()
{
return _customizers;
}
public <T> T getCustomizer(Class<T> type)
{
for (Customizer c : _customizers)
if (type.isAssignableFrom(c.getClass()))
return (T)c;
return null;
}
public int getOutputBufferSize()
{
return _outputBufferSize;
}
public int getRequestHeaderSize()
{
return _requestHeaderSize;
}
public int getResponseHeaderSize()
{
return _responseHeaderSize;
}
public int getSecurePort()
{
return _securePort;
}
public String getSecureScheme()
{
return _secureScheme;
}
public void setCustomizers(List<Customizer> customizers)
{
_customizers.clear();
_customizers.addAll(customizers);
}
public void setOutputBufferSize(int responseBufferSize)
{
_outputBufferSize = responseBufferSize;
}
public void setRequestHeaderSize(int requestHeaderSize)
{
_requestHeaderSize = requestHeaderSize;
}
public void setResponseHeaderSize(int responseHeaderSize)
{
_responseHeaderSize = responseHeaderSize;
}
public void setSecurePort(int confidentialPort)
{
_securePort = confidentialPort;
}
public void setSecureScheme(String confidentialScheme)
{
_secureScheme = confidentialScheme;
}
@Override
public String toString()
{
return String.format("%s@%x{%d,%d/%d,%s://:%d,%s}",this.getClass().getSimpleName(),hashCode(),_outputBufferSize,_requestHeaderSize,_responseHeaderSize,_secureScheme,_securePort,_customizers);
}
}

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.server;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent; import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener; import javax.servlet.AsyncListener;

View File

@ -1,556 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 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 java.io.IOException;
import java.net.InetSocketAddress;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSession;
import javax.servlet.ServletRequest;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.server.ssl.SslCertificates;
import org.eclipse.jetty.util.component.AggregateLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.ssl.SslContextFactory;
public class HttpConfiguration extends AggregateLifeCycle
{
static final Logger LOG = Log.getLogger(HttpConfiguration.class);
private final SslContextFactory _sslContextFactory;
private final boolean _ssl;
private String _integralScheme = HttpScheme.HTTPS.asString();
private int _integralPort = 0;
private String _confidentialScheme = HttpScheme.HTTPS.asString();
private int _confidentialPort = 0;
private boolean _forwarded;
private String _hostHeader;
private String _forwardedHostHeader = HttpHeader.X_FORWARDED_HOST.toString();
private String _forwardedServerHeader = HttpHeader.X_FORWARDED_SERVER.toString();
private String _forwardedForHeader = HttpHeader.X_FORWARDED_FOR.toString();
private String _forwardedProtoHeader = HttpHeader.X_FORWARDED_PROTO.toString();
private String _forwardedCipherSuiteHeader;
private String _forwardedSslSessionIdHeader;
private int _requestHeaderSize=8*1024;
private int _requestBufferSize=16*1024;
private int _responseHeaderSize=8*1024;
private int _responseBufferSize=32*1024;
public HttpConfiguration(SslContextFactory sslContextFactory,boolean ssl)
{
_sslContextFactory=sslContextFactory!=null?sslContextFactory:ssl?new SslContextFactory(SslContextFactory.DEFAULT_KEYSTORE_PATH):null;
_ssl=ssl;
if (_sslContextFactory!=null)
addBean(_sslContextFactory,sslContextFactory==null);
}
public SslContextFactory getSslContextFactory()
{
return _sslContextFactory;
}
public boolean isSecure()
{
return _ssl;
}
public int getRequestHeaderSize()
{
return _requestHeaderSize;
}
public void setRequestHeaderSize(int requestHeaderSize)
{
_requestHeaderSize = requestHeaderSize;
}
public int getRequestBufferSize()
{
return _requestBufferSize;
}
public void setRequestBufferSize(int requestBufferSize)
{
_requestBufferSize = requestBufferSize;
}
public int getResponseHeaderSize()
{
return _responseHeaderSize;
}
public void setResponseHeaderSize(int responseHeaderSize)
{
_responseHeaderSize = responseHeaderSize;
}
public int getResponseBufferSize()
{
return _responseBufferSize;
}
public void setResponseBufferSize(int responseBufferSize)
{
_responseBufferSize = responseBufferSize;
}
/* ------------------------------------------------------------ */
/**
* Allow the Listener a chance to customise the request. before the server
* does its stuff. <br>
* This allows the required attributes to be set for SSL requests. <br>
* The requirements of the Servlet specs are:
* <ul>
* <li> an attribute named "javax.servlet.request.ssl_session_id" of type
* String (since Servlet Spec 3.0).</li>
* <li> an attribute named "javax.servlet.request.cipher_suite" of type
* String.</li>
* <li> an attribute named "javax.servlet.request.key_size" of type Integer.</li>
* <li> an attribute named "javax.servlet.request.X509Certificate" of type
* java.security.cert.X509Certificate[]. This is an array of objects of type
* X509Certificate, the order of this array is defined as being in ascending
* order of trust. The first certificate in the chain is the one set by the
* client, the next is the one used to authenticate the first, and so on.
* </li>
* </ul>
*/
public void customize(Request request) throws IOException
{
if (isSecure())
{
request.setScheme(HttpScheme.HTTPS.asString());
SslConnection.DecryptedEndPoint ssl_endp = (SslConnection.DecryptedEndPoint)request.getHttpChannel().getEndPoint();
SslConnection sslConnection = ssl_endp.getSslConnection();
SSLEngine sslEngine=sslConnection.getSSLEngine();
SslCertificates.customize(sslEngine,request);
}
request.setTimeStamp(System.currentTimeMillis());
if (isForwarded())
checkForwardedHeaders(request);
}
/* ------------------------------------------------------------ */
protected void checkForwardedHeaders(Request request) throws IOException
{
HttpFields httpFields = request.getHttpFields();
// Do SSL first
if (getForwardedCipherSuiteHeader()!=null)
{
String cipher_suite=httpFields.getStringField(getForwardedCipherSuiteHeader());
if (cipher_suite!=null)
request.setAttribute("javax.servlet.request.cipher_suite",cipher_suite);
}
if (getForwardedSslSessionIdHeader()!=null)
{
String ssl_session_id=httpFields.getStringField(getForwardedSslSessionIdHeader());
if(ssl_session_id!=null)
{
request.setAttribute("javax.servlet.request.ssl_session_id", ssl_session_id);
request.setScheme(HttpScheme.HTTPS.asString());
}
}
// Retrieving headers from the request
String forwardedHost = getLeftMostFieldValue(httpFields,getForwardedHostHeader());
String forwardedServer = getLeftMostFieldValue(httpFields,getForwardedServerHeader());
String forwardedFor = getLeftMostFieldValue(httpFields,getForwardedForHeader());
String forwardedProto = getLeftMostFieldValue(httpFields,getForwardedProtoHeader());
if (_hostHeader != null)
{
// Update host header
httpFields.put(HttpHeader.HOST.toString(),_hostHeader);
request.setServerName(null);
request.setServerPort(-1);
request.getServerName();
}
else if (forwardedHost != null)
{
// Update host header
httpFields.put(HttpHeader.HOST.toString(),forwardedHost);
request.setServerName(null);
request.setServerPort(-1);
request.getServerName();
}
else if (forwardedServer != null)
{
// Use provided server name
request.setServerName(forwardedServer);
}
if (forwardedFor != null)
{
request.setRemoteAddr(new InetSocketAddress(forwardedFor,request.getRemotePort()));
}
if (forwardedProto != null)
{
request.setScheme(forwardedProto);
}
}
/* ------------------------------------------------------------ */
protected String getLeftMostFieldValue(HttpFields fields, String header)
{
if (header == null)
return null;
String headerValue = fields.getStringField(header);
if (headerValue == null)
return null;
int commaIndex = headerValue.indexOf(',');
if (commaIndex == -1)
{
// Single value
return headerValue;
}
// The left-most value is the farthest downstream client
return headerValue.substring(0,commaIndex);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.jetty.server.Connector#getConfidentialPort()
*/
public int getConfidentialPort()
{
return _confidentialPort;
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.jetty.server.Connector#getConfidentialScheme()
*/
public String getConfidentialScheme()
{
return _confidentialScheme;
}
/* ------------------------------------------------------------ */
/**
* The request is integral IFF it is secure AND the server port
* matches any configured {@link #getIntegralPort()}.
* This allows separation of listeners providing INTEGRAL versus
* CONFIDENTIAL constraints, such as one SSL listener configured to require
* client certs providing CONFIDENTIAL, whereas another SSL listener not
* requiring client certs providing mere INTEGRAL constraints.
* <p>
* The request is secure if it is SSL or it {@link #isForwarded()} is true
* and the scheme matches {@link #getIntegralScheme()()}
*/
public boolean isIntegral(Request request)
{
boolean https = isSecure() || _forwarded && _integralScheme.equalsIgnoreCase(request.getScheme());
int iPort=getIntegralPort();
boolean port = iPort<=0||iPort==request.getServerPort();
return https && port;
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.jetty.server.Connector#getConfidentialPort()
*/
public int getIntegralPort()
{
return _integralPort;
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.jetty.server.Connector#getIntegralScheme()
*/
public String getIntegralScheme()
{
return _integralScheme;
}
/* ------------------------------------------------------------ */
/**
* The request is confidential IFF it is secure AND the server port
* matches any configured {@link #getConfidentialPort()}.
* This allows separation of listeners providing INTEGRAL versus
* CONFIDENTIAL constraints, such as one SSL listener configured to require
* client certs providing CONFIDENTIAL, whereas another SSL listener not
* requiring client certs providing mere INTEGRAL constraints.
* <p>
* The request is secure if it is SSL or it {@link #isForwarded()} is true
* and the scheme matches {@link #getConfidentialScheme()}
*/
public boolean isConfidential(Request request)
{
boolean https = isSecure() || _forwarded && _confidentialScheme.equalsIgnoreCase(request.getScheme());
int confidentialPort=getConfidentialPort();
boolean port = confidentialPort<=0||confidentialPort==request.getServerPort();
return https && port;
}
/* ------------------------------------------------------------ */
/**
* @param confidentialPort
* The confidentialPort to set.
*/
public void setConfidentialPort(int confidentialPort)
{
_confidentialPort = confidentialPort;
}
/* ------------------------------------------------------------ */
/**
* @param confidentialScheme
* The confidentialScheme to set.
*/
public void setConfidentialScheme(String confidentialScheme)
{
_confidentialScheme = confidentialScheme;
}
/* ------------------------------------------------------------ */
/**
* @param integralPort
* The integralPort to set.
*/
public void setIntegralPort(int integralPort)
{
_integralPort = integralPort;
}
/* ------------------------------------------------------------ */
/**
* @param integralScheme
* The integralScheme to set.
*/
public void setIntegralScheme(String integralScheme)
{
_integralScheme = integralScheme;
}
/* ------------------------------------------------------------ */
/**
* Is reverse proxy handling on?
*
* @return true if this connector is checking the x-forwarded-for/host/server headers
*/
public boolean isForwarded()
{
return _forwarded;
}
/* ------------------------------------------------------------ */
/**
* Set reverse proxy handling. If set to true, then the X-Forwarded headers (or the headers set in their place) are looked for to set the request protocol,
* host, server and client ip.
*
* @param check true if this connector is checking the x-forwarded-for/host/server headers
* @see #setForwardedForHeader(String)
* @see #setForwardedHostHeader(String)
* @see #setForwardedProtoHeader(String)
* @see #setForwardedServerHeader(String)
*/
public void setForwarded(boolean check)
{
if (check)
LOG.debug("{} is forwarded",this);
_forwarded = check;
}
/* ------------------------------------------------------------ */
public String getHostHeader()
{
return _hostHeader;
}
/* ------------------------------------------------------------ */
/**
* Set a forced valued for the host header to control what is returned by {@link ServletRequest#getServerName()} and {@link ServletRequest#getServerPort()}.
* This value is only used if {@link #isForwarded()} is true.
*
* @param hostHeader
* The value of the host header to force.
*/
public void setHostHeader(String hostHeader)
{
_hostHeader = hostHeader;
}
/* ------------------------------------------------------------ */
/*
*
* @see #setForwarded(boolean)
*/
public String getForwardedHostHeader()
{
return _forwardedHostHeader;
}
/* ------------------------------------------------------------ */
/**
* @param forwardedHostHeader
* The header name for forwarded hosts (default x-forwarded-host)
* @see #setForwarded(boolean)
*/
public void setForwardedHostHeader(String forwardedHostHeader)
{
_forwardedHostHeader = forwardedHostHeader;
}
/* ------------------------------------------------------------ */
/**
* @return the header name for forwarded server.
* @see #setForwarded(boolean)
*/
public String getForwardedServerHeader()
{
return _forwardedServerHeader;
}
/* ------------------------------------------------------------ */
/**
* @param forwardedServerHeader
* The header name for forwarded server (default x-forwarded-server)
* @see #setForwarded(boolean)
*/
public void setForwardedServerHeader(String forwardedServerHeader)
{
_forwardedServerHeader = forwardedServerHeader;
}
/* ------------------------------------------------------------ */
/**
* @return the forwarded for header
* @see #setForwarded(boolean)
*/
public String getForwardedForHeader()
{
return _forwardedForHeader;
}
/* ------------------------------------------------------------ */
/**
* @param forwardedRemoteAddressHeader
* The header name for forwarded for (default x-forwarded-for)
* @see #setForwarded(boolean)
*/
public void setForwardedForHeader(String forwardedRemoteAddressHeader)
{
_forwardedForHeader = forwardedRemoteAddressHeader;
}
/* ------------------------------------------------------------ */
/**
* Get the forwardedProtoHeader.
*
* @return the forwardedProtoHeader (default X-Forwarded-For)
* @see #setForwarded(boolean)
*/
public String getForwardedProtoHeader()
{
return _forwardedProtoHeader;
}
/* ------------------------------------------------------------ */
/**
* Set the forwardedProtoHeader.
*
* @param forwardedProtoHeader
* the forwardedProtoHeader to set (default X-Forwarded-For)
* @see #setForwarded(boolean)
*/
public void setForwardedProtoHeader(String forwardedProtoHeader)
{
_forwardedProtoHeader = forwardedProtoHeader;
}
/* ------------------------------------------------------------ */
/**
* @return The header name holding a forwarded cipher suite (default null)
*/
public String getForwardedCipherSuiteHeader()
{
return _forwardedCipherSuiteHeader;
}
/* ------------------------------------------------------------ */
/**
* @param forwardedCipherSuite
* The header name holding a forwarded cipher suite (default null)
*/
public void setForwardedCipherSuiteHeader(String forwardedCipherSuite)
{
_forwardedCipherSuiteHeader = forwardedCipherSuite;
}
/* ------------------------------------------------------------ */
/**
* @return The header name holding a forwarded SSL Session ID (default null)
*/
public String getForwardedSslSessionIdHeader()
{
return _forwardedSslSessionIdHeader;
}
/* ------------------------------------------------------------ */
/**
* @param forwardedSslSessionId
* The header name holding a forwarded SSL Session ID (default null)
*/
public void setForwardedSslSessionIdHeader(String forwardedSslSessionId)
{
_forwardedSslSessionIdHeader = forwardedSslSessionId;
}
/* ------------------------------------------------------------ */
@Override
protected void doStart() throws Exception
{
if (_sslContextFactory!=null)
{
_sslContextFactory.checkKeyStore();
super.doStart();
SSLEngine sslEngine = _sslContextFactory.newSSLEngine();
sslEngine.setUseClientMode(false);
SSLSession sslSession = sslEngine.getSession();
if (getRequestHeaderSize()<sslSession.getApplicationBufferSize())
setRequestHeaderSize(sslSession.getApplicationBufferSize());
if (getRequestBufferSize()<sslSession.getApplicationBufferSize())
setRequestBufferSize(sslSession.getApplicationBufferSize());
}
else
super.doStart();
}
}

View File

@ -49,14 +49,14 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
private static final Logger LOG = Log.getLogger(HttpConnection.class); private static final Logger LOG = Log.getLogger(HttpConnection.class);
private static final ThreadLocal<HttpConnection> __currentConnection = new ThreadLocal<>(); private static final ThreadLocal<HttpConnection> __currentConnection = new ThreadLocal<>();
private final HttpConfiguration _configuration; private final HttpChannelConfig _config;
private final Connector _connector; private final Connector _connector;
private final ByteBufferPool _bufferPool; // TODO: remove field, use a _connector.getByteBufferPool() private final ByteBufferPool _bufferPool;
private final HttpGenerator _generator; private final HttpGenerator _generator;
private final HttpChannelOverHttp _channel; private final HttpChannelOverHttp _channel;
private final HttpParser _parser; private final HttpParser _parser;
private ByteBuffer _requestBuffer = null; private volatile ByteBuffer _requestBuffer = null;
private ByteBuffer _chunk = null; private volatile ByteBuffer _chunk = null;
public static HttpConnection getCurrentConnection() public static HttpConnection getCurrentConnection()
{ {
@ -68,11 +68,16 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
__currentConnection.set(connection); __currentConnection.set(connection);
} }
public HttpConnection(HttpConfiguration config, Connector connector, EndPoint endPoint) public HttpChannelConfig getHttpChannelConfig()
{
return _config;
}
public HttpConnection(HttpChannelConfig config, Connector connector, EndPoint endPoint)
{ {
super(endPoint, connector.getExecutor()); super(endPoint, connector.getExecutor());
_configuration = config; _config = config;
_connector = connector; _connector = connector;
_bufferPool = _connector.getByteBufferPool(); _bufferPool = _connector.getByteBufferPool();
_generator = new HttpGenerator(); // TODO: consider moving the generator to the transport, where it belongs _generator = new HttpGenerator(); // TODO: consider moving the generator to the transport, where it belongs
@ -98,7 +103,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
return _connector; return _connector;
} }
public HttpChannel getHttpChannel() public HttpChannel<?> getHttpChannel()
{ {
return _channel; return _channel;
} }
@ -145,8 +150,9 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
{ {
if (_requestBuffer != null && !_requestBuffer.hasRemaining()) if (_requestBuffer != null && !_requestBuffer.hasRemaining())
{ {
_bufferPool.release(_requestBuffer); ByteBuffer buffer=_requestBuffer;
_requestBuffer = null; _requestBuffer=null;
_bufferPool.release(buffer);
} }
} }
@ -175,7 +181,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
if (!event && BufferUtil.isEmpty(_requestBuffer)) if (!event && BufferUtil.isEmpty(_requestBuffer))
{ {
if (_requestBuffer == null) if (_requestBuffer == null)
_requestBuffer = _bufferPool.acquire(_configuration.getRequestHeaderSize(), false); _requestBuffer = _bufferPool.acquire(getInputBufferSize(), false);
int filled = getEndPoint().fill(_requestBuffer); int filled = getEndPoint().fill(_requestBuffer);
if (filled==0) // Do a retry on fill 0 (optimisation for SSL connections) if (filled==0) // Do a retry on fill 0 (optimisation for SSL connections)
@ -315,7 +321,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
{ {
case NEED_HEADER: case NEED_HEADER:
{ {
header = _bufferPool.acquire(_configuration.getResponseHeaderSize(), false); header = _bufferPool.acquire(_config.getResponseHeaderSize(), false);
continue; continue;
} }
case NEED_CHUNK: case NEED_CHUNK:
@ -533,7 +539,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
// We will need a buffer to read into // We will need a buffer to read into
if (_requestBuffer==null) if (_requestBuffer==null)
_requestBuffer=_bufferPool.acquire(_configuration.getRequestBufferSize(),false); _requestBuffer=_bufferPool.acquire(getInputBufferSize(),false);
// read some data // read some data
int filled=getEndPoint().fill(_requestBuffer); int filled=getEndPoint().fill(_requestBuffer);
@ -590,9 +596,9 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
private class HttpChannelOverHttp extends HttpChannel<ByteBuffer> private class HttpChannelOverHttp extends HttpChannel<ByteBuffer>
{ {
public HttpChannelOverHttp(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport, HttpInput<ByteBuffer> input) public HttpChannelOverHttp(Connector connector, HttpChannelConfig config, EndPoint endPoint, HttpTransport transport, HttpInput<ByteBuffer> input)
{ {
super(connector,configuration,endPoint,transport,input); super(connector,config,endPoint,transport,input);
} }
@Override @Override

View File

@ -19,39 +19,40 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import java.nio.channels.SocketChannel;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
public class HttpServerConnectionFactory implements ConnectionFactory public class HttpConnectionFactory extends AbstractConnectionFactory implements HttpChannelConfig.ConnectionFactory
{ {
private final Connector connector; private final HttpChannelConfig _config;
private final HttpConfiguration configuration;
public HttpServerConnectionFactory(Connector connector) public HttpConnectionFactory()
{ {
this(connector, new HttpConfiguration(connector.getSslContextFactory(), connector.getSslContextFactory() != null)); this(new HttpChannelConfig());
} setInputBufferSize(16384);
public HttpServerConnectionFactory(Connector connector, HttpConfiguration configuration)
{
this.connector = connector;
this.configuration = configuration;
} }
public Connector getConnector() public HttpConnectionFactory(HttpChannelConfig config)
{ {
return connector; super(HttpVersion.HTTP_1_1.toString());
} _config=config;
addBean(_config);
public HttpConfiguration getHttpConfiguration()
{
return configuration;
} }
@Override @Override
public Connection newConnection(SocketChannel channel, EndPoint endPoint, Object attachment) public HttpChannelConfig getHttpChannelConfig()
{ {
return new HttpConnection(getHttpConfiguration(), getConnector(), endPoint); return _config;
} }
@Override
public Connection newConnection(Connector connector, EndPoint endPoint)
{
HttpConnection connection = new HttpConnection(_config, connector, endPoint);
connection.setInputBufferSize(getInputBufferSize()); // TODO constructor injection
return connection;
}
} }

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import javax.servlet.ServletInputStream; import javax.servlet.ServletInputStream;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;

View File

@ -22,6 +22,7 @@ import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
@ -54,7 +55,7 @@ public class HttpOutput extends ServletOutputStream
public HttpOutput(HttpChannel channel) public HttpOutput(HttpChannel channel)
{ {
_channel = channel; _channel = channel;
_bufferSize = _channel.getHttpConfiguration().getResponseBufferSize(); _bufferSize = _channel.getHttpChannelConfig().getOutputBufferSize();
} }
public boolean isWritten() public boolean isWritten()
@ -209,7 +210,7 @@ public class HttpOutput extends ServletOutputStream
HttpContent httpContent = (HttpContent)content; HttpContent httpContent = (HttpContent)content;
Response response = _channel.getResponse(); Response response = _channel.getResponse();
String contentType = httpContent.getContentType(); String contentType = httpContent.getContentType();
if (contentType != null) if (contentType != null && !response.getHttpFields().containsKey(HttpHeader.CONTENT_TYPE.asString()))
response.getHttpFields().put(HttpHeader.CONTENT_TYPE, contentType); response.getHttpFields().put(HttpHeader.CONTENT_TYPE, contentType);
if (httpContent.getContentLength() > 0) if (httpContent.getContentLength() > 0)

View File

@ -27,19 +27,44 @@ import org.eclipse.jetty.util.thread.Scheduler;
public class HttpServerConnector extends SelectChannelConnector public class HttpServerConnector extends SelectChannelConnector
{ {
public HttpServerConnector(Server server) public HttpServerConnector(
@Name("server") Server server)
{ {
this(server, null); this(server,null,null,null,null,null,0,0);
} }
public HttpServerConnector(Server server, SslContextFactory sslContextFactory) public HttpServerConnector(
@Name("server") Server server,
@Name("sslContextFactory") SslContextFactory sslContextFactory)
{ {
this(server, null, null, null, sslContextFactory, 0, 0); this(server,null,sslContextFactory, null, null, null, 0, 0);
} }
public HttpServerConnector(@Name("server") Server server, @Name("executor") Executor executor, @Name("scheduler") Scheduler scheduler, @Name("bufferPool") ByteBufferPool pool, @Name("sslContextFactory") SslContextFactory sslContextFactory, @Name("acceptors") int acceptors, @Name("selectors") int selectors) public HttpServerConnector(
@Name("server") Server server,
@Name("connectionFactory") HttpConnectionFactory connectionFactory)
{ {
super(server, executor, scheduler, pool, sslContextFactory, acceptors, selectors); this(server,connectionFactory,null, null, null, null, 0, 0);
setDefaultConnectionFactory(new HttpServerConnectionFactory(this)); }
public HttpServerConnector(
@Name("server") Server server,
@Name("connectionFactory") HttpConnectionFactory connectionFactory,
@Name("sslContextFactory") SslContextFactory sslContextFactory)
{
this(server,connectionFactory,sslContextFactory, null, null, null, 0, 0);
}
public HttpServerConnector(
@Name("server") Server server,
@Name("connectionFactory") HttpConnectionFactory connectionFactory,
@Name("sslContextFactory") SslContextFactory sslContextFactory,
@Name("executor") Executor executor,
@Name("scheduler") Scheduler scheduler,
@Name("bufferPool") ByteBufferPool pool,
@Name("acceptors") int acceptors,
@Name("selectors") int selectors)
{
super(server,executor,scheduler,pool,acceptors,selectors,AbstractConnectionFactory.getFactories(sslContextFactory,connectionFactory==null?new HttpConnectionFactory():connectionFactory));
} }
} }

View File

@ -25,13 +25,10 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLEngine;
import org.eclipse.jetty.io.ByteArrayEndPoint; import org.eclipse.jetty.io.ByteArrayEndPoint;
import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.ssl.SslContextFactory;
@ -41,22 +38,31 @@ public class LocalConnector extends AbstractConnector
{ {
private final BlockingQueue<LocalEndPoint> _connects = new LinkedBlockingQueue<>(); private final BlockingQueue<LocalEndPoint> _connects = new LinkedBlockingQueue<>();
public LocalConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, int acceptors, ConnectionFactory... factories)
{
super(server,executor,scheduler,pool,acceptors,factories);
setIdleTimeout(30000);
}
public LocalConnector(Server server) public LocalConnector(Server server)
{ {
this(server,null); this(server, null, null, null, 0, new HttpConnectionFactory());
} }
public LocalConnector(Server server, SslContextFactory sslContextFactory) public LocalConnector(Server server, SslContextFactory sslContextFactory)
{ {
this(server, null, null, null, sslContextFactory, 0); this(server, null, null, null, 0,AbstractConnectionFactory.getFactories(sslContextFactory,new HttpConnectionFactory()));
} }
public LocalConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, public LocalConnector(Server server, ConnectionFactory connectionFactory)
SslContextFactory sslContextFactory, int acceptors)
{ {
super(server,executor,scheduler,pool, sslContextFactory, acceptors); this(server, null, null, null, 0, connectionFactory);
setIdleTimeout(30000); }
setDefaultConnectionFactory(new HttpServerConnectionFactory(this));
public LocalConnector(Server server, ConnectionFactory connectionFactory, SslContextFactory sslContextFactory)
{
this(server, null, null, null, 0,AbstractConnectionFactory.getFactories(sslContextFactory,connectionFactory));
} }
@Override @Override
@ -159,29 +165,10 @@ public class LocalConnector extends AbstractConnector
LocalEndPoint endPoint = _connects.take(); LocalEndPoint endPoint = _connects.take();
endPoint.onOpen(); endPoint.onOpen();
SslContextFactory sslContextFactory = getSslContextFactory(); Connection connection = getDefaultConnectionFactory().newConnection(this, endPoint);
if (sslContextFactory != null) endPoint.setConnection(connection);
{ connectionOpened(connection);
SSLEngine engine = sslContextFactory.newSSLEngine(endPoint.getRemoteAddress()); connection.onOpen();
engine.setUseClientMode(false);
SslConnection sslConnection = new SslConnection(getByteBufferPool(), getExecutor(), endPoint, engine);
endPoint.setConnection(sslConnection);
connectionOpened(sslConnection);
sslConnection.onOpen();
EndPoint appEndPoint = sslConnection.getDecryptedEndPoint();
Connection connection = getDefaultConnectionFactory().newConnection(null, appEndPoint, null);
appEndPoint.setConnection(connection);
connection.onOpen();
}
else
{
Connection connection = getDefaultConnectionFactory().newConnection(null, endPoint, null);
endPoint.setConnection(connection);
connectionOpened(connection);
connection.onOpen();
}
} }
public class LocalEndPoint extends ByteArrayEndPoint public class LocalEndPoint extends ByteArrayEndPoint

View File

@ -24,6 +24,7 @@ import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeader;

View File

@ -37,6 +37,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.AsyncListener; import javax.servlet.AsyncListener;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
@ -118,28 +119,30 @@ public class Request implements HttpServletRequest
private static final Collection<Locale> __defaultLocale = Collections.singleton(Locale.getDefault()); private static final Collection<Locale> __defaultLocale = Collections.singleton(Locale.getDefault());
private static final int __NONE = 0, _STREAM = 1, __READER = 2; private static final int __NONE = 0, _STREAM = 1, __READER = 2;
private final HttpChannel _channel; private final HttpChannel<?> _channel;
private final HttpFields _fields=new HttpFields(); private final HttpFields _fields=new HttpFields();
private final List<ServletRequestAttributeListener> _requestAttributeListeners=new ArrayList<>(); private final List<ServletRequestAttributeListener> _requestAttributeListeners=new ArrayList<>();
private final HttpInput _input; private final HttpInput<?> _input;
private boolean _secure;
private boolean _asyncSupported = true; private boolean _asyncSupported = true;
private boolean _newContext;
private boolean _cookiesExtracted = false;
private boolean _handled = false;
private boolean _paramsExtracted;
private boolean _requestedSessionIdFromCookie = false;
private volatile Attributes _attributes; private volatile Attributes _attributes;
private Authentication _authentication; private Authentication _authentication;
private MultiMap<String> _baseParameters; private MultiMap<String> _baseParameters;
private String _characterEncoding; private String _characterEncoding;
private ContextHandler.Context _context; private ContextHandler.Context _context;
private boolean _newContext;
private String _contextPath; private String _contextPath;
private CookieCutter _cookies; private CookieCutter _cookies;
private boolean _cookiesExtracted = false;
private DispatcherType _dispatcherType; private DispatcherType _dispatcherType;
private boolean _handled = false;
private int _inputState = __NONE; private int _inputState = __NONE;
private HttpMethod _httpMethod; private HttpMethod _httpMethod;
private String _httpMethodString; private String _httpMethodString;
private MultiMap<String> _parameters; private MultiMap<String> _parameters;
private boolean _paramsExtracted;
private String _pathInfo; private String _pathInfo;
private int _port; private int _port;
private HttpVersion _httpVersion = HttpVersion.HTTP_1_1; private HttpVersion _httpVersion = HttpVersion.HTTP_1_1;
@ -149,7 +152,6 @@ public class Request implements HttpServletRequest
private String _readerEncoding; private String _readerEncoding;
private InetSocketAddress _remote; private InetSocketAddress _remote;
private String _requestedSessionId; private String _requestedSessionId;
private boolean _requestedSessionIdFromCookie = false;
private String _requestURI; private String _requestURI;
private Map<Object, HttpSession> _savedNewSessions; private Map<Object, HttpSession> _savedNewSessions;
private String _scheme = URIUtil.HTTP; private String _scheme = URIUtil.HTTP;
@ -164,7 +166,7 @@ public class Request implements HttpServletRequest
private MultiPartInputStream _multiPartInputStream; //if the request is a multi-part mime private MultiPartInputStream _multiPartInputStream; //if the request is a multi-part mime
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public Request(HttpChannel channel, HttpInput input) public Request(HttpChannel<?> channel, HttpInput<?> input)
{ {
_channel = channel; _channel = channel;
_input = input; _input = input;
@ -177,7 +179,7 @@ public class Request implements HttpServletRequest
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public HttpInput getHttpInput() public HttpInput<?> getHttpInput()
{ {
return _input; return _input;
} }
@ -394,7 +396,7 @@ public class Request implements HttpServletRequest
/** /**
* @return Returns the connection. * @return Returns the connection.
*/ */
public HttpChannel getHttpChannel() public HttpChannel<?> getHttpChannel()
{ {
return _channel; return _channel;
} }
@ -613,7 +615,6 @@ public class Request implements HttpServletRequest
return Collections.enumeration(__defaultLocale); return Collections.enumeration(__defaultLocale);
List<Locale> langs = new ArrayList<>(); List<Locale> langs = new ArrayList<>();
int size = acceptLanguage.size();
// convert to locals // convert to locals
for (String language : acceptLanguage) for (String language : acceptLanguage)
@ -1374,7 +1375,13 @@ public class Request implements HttpServletRequest
@Override @Override
public boolean isSecure() public boolean isSecure()
{ {
return _channel.getHttpConfiguration().isConfidential(this); return _secure;
}
/* ------------------------------------------------------------ */
public void setSecure(boolean secure)
{
_secure=secure;
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */

View File

@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;

View File

@ -0,0 +1,169 @@
//
// ========================================================================
// Copyright (c) 1995-2012 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 java.security.cert.X509Certificate;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSession;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.io.ssl.SslConnection.DecryptedEndPoint;
import org.eclipse.jetty.server.ssl.ServletSSL;
import org.eclipse.jetty.server.ssl.SslCertificates;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
public class SecureRequestCustomizer implements HttpChannelConfig.Customizer
{
private static final Logger LOG = Log.getLogger(SecureRequestCustomizer.class);
/**
* The name of the SSLSession attribute that will contain any cached information.
*/
public static final String CACHED_INFO_ATTR = CachedInfo.class.getName();
@Override
public void customize(Connector connector, HttpChannelConfig channelConfig, Request request)
{
if (request.getHttpChannel().getEndPoint() instanceof DecryptedEndPoint)
{
request.setScheme(HttpScheme.HTTPS.asString());
request.setSecure(true);
SslConnection.DecryptedEndPoint ssl_endp = (DecryptedEndPoint)request.getHttpChannel().getEndPoint();
SslConnection sslConnection = ssl_endp.getSslConnection();
SSLEngine sslEngine=sslConnection.getSSLEngine();
customize(sslEngine,request);
}
}
/* ------------------------------------------------------------ */
/*
* Allow the Listener a chance to customise the request. before the server
* does its stuff. <br>
* This allows the required attributes to be set for SSL requests. <br>
* The requirements of the Servlet specs are:
* <ul>
* <li> an attribute named "javax.servlet.request.ssl_session_id" of type
* String (since Servlet Spec 3.0).</li>
* <li> an attribute named "javax.servlet.request.cipher_suite" of type
* String.</li>
* <li> an attribute named "javax.servlet.request.key_size" of type Integer.</li>
* <li> an attribute named "javax.servlet.request.X509Certificate" of type
* java.security.cert.X509Certificate[]. This is an array of objects of type
* X509Certificate, the order of this array is defined as being in ascending
* order of trust. The first certificate in the chain is the one set by the
* client, the next is the one used to authenticate the first, and so on.
* </li>
* </ul>
*
* @param request
* HttpRequest to be customised.
*/
public void customize(SSLEngine sslEngine, Request request)
{
request.setScheme(HttpScheme.HTTPS.asString());
SSLSession sslSession = sslEngine.getSession();
try
{
String cipherSuite=sslSession.getCipherSuite();
Integer keySize;
X509Certificate[] certs;
String idStr;
CachedInfo cachedInfo=(CachedInfo)sslSession.getValue(CACHED_INFO_ATTR);
if (cachedInfo!=null)
{
keySize=cachedInfo.getKeySize();
certs=cachedInfo.getCerts();
idStr=cachedInfo.getIdStr();
}
else
{
keySize=new Integer(ServletSSL.deduceKeyLength(cipherSuite));
certs=SslCertificates.getCertChain(sslSession);
byte[] bytes = sslSession.getId();
idStr = TypeUtil.toHexString(bytes);
cachedInfo=new CachedInfo(keySize,certs,idStr);
sslSession.putValue(CACHED_INFO_ATTR,cachedInfo);
}
if (certs!=null)
request.setAttribute("javax.servlet.request.X509Certificate",certs);
request.setAttribute("javax.servlet.request.cipher_suite",cipherSuite);
request.setAttribute("javax.servlet.request.key_size",keySize);
request.setAttribute("javax.servlet.request.ssl_session_id", idStr);
}
catch (Exception e)
{
LOG.warn(Log.EXCEPTION,e);
}
}
@Override
public String toString()
{
return String.format("%s@%x",this.getClass().getSimpleName(),hashCode());
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/**
* Simple bundle of information that is cached in the SSLSession. Stores the
* effective keySize and the client certificate chain.
*/
private static class CachedInfo
{
private final X509Certificate[] _certs;
private final Integer _keySize;
private final String _idStr;
CachedInfo(Integer keySize, X509Certificate[] certs,String idStr)
{
this._keySize=keySize;
this._certs=certs;
this._idStr=idStr;
}
X509Certificate[] getCerts()
{
return _certs;
}
Integer getKeySize()
{
return _keySize;
}
String getIdStr()
{
return _idStr;
}
}
}

View File

@ -29,7 +29,6 @@ import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.net.ssl.SSLEngine;
import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
@ -37,9 +36,7 @@ import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.SelectChannelEndPoint; import org.eclipse.jetty.io.SelectChannelEndPoint;
import org.eclipse.jetty.io.SelectorManager; import org.eclipse.jetty.io.SelectorManager;
import org.eclipse.jetty.io.SelectorManager.ManagedSelector; import org.eclipse.jetty.io.SelectorManager.ManagedSelector;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.Name;
import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.util.thread.Scheduler;
@ -57,42 +54,40 @@ public class SelectChannelConnector extends AbstractNetworkConnector
private volatile boolean _reuseAddress = true; private volatile boolean _reuseAddress = true;
private volatile int _lingerTime = -1; private volatile int _lingerTime = -1;
public SelectChannelConnector(@Name("server") Server server)
public SelectChannelConnector(Server server)
{ {
this(server, null); this(server,null,null,null,0,0,new HttpConnectionFactory());
} }
public SelectChannelConnector(@Name("server")Server server, @Name("sslContextFactory") SslContextFactory sslContextFactory) public SelectChannelConnector(Server server,ConnectionFactory... factories)
{ {
this(server, null, null, null, sslContextFactory, 0, 0); this(server,null,null,null,0,0,factories);
}
public SelectChannelConnector(Server server,SslContextFactory sslContextFactory)
{
this(server,null,null,null,0,0,AbstractConnectionFactory.getFactories(sslContextFactory,new HttpConnectionFactory()));
}
public SelectChannelConnector(Server server,SslContextFactory sslContextFactory,ConnectionFactory... factories)
{
this(server,null,null,null,0,0,AbstractConnectionFactory.getFactories(sslContextFactory,factories));
} }
/** /**
* @param server The server this connector will be added to. Must not be null. * @param server The server this connector will be added to. Must not be null.
* @param factory TODO
* @param executor An executor for this connector or null to use the servers executor * @param executor An executor for this connector or null to use the servers executor
* @param scheduler A scheduler for this connector or null to use the servers scheduler * @param scheduler A scheduler for this connector or null to use the servers scheduler
* @param pool A buffer pool for this connector or null to use a default {@link ByteBufferPool} * @param pool A buffer pool for this connector or null to use a default {@link ByteBufferPool}
* @param acceptors the number of acceptor threads to use, or 0 for a default value. * @param acceptors the number of acceptor threads to use, or 0 for a default value.
*/ */
public SelectChannelConnector( public SelectChannelConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, int acceptors,int selectors,ConnectionFactory... factories)
@Name("server") Server server,
@Name("executor") Executor executor,
@Name("scheduler") Scheduler scheduler,
@Name("bufferPool") ByteBufferPool pool,
@Name("sslContextFactory") SslContextFactory sslContextFactory,
@Name("acceptors") int acceptors,
@Name("selectors") int selectors)
{ {
super(server, executor, scheduler, pool, sslContextFactory, acceptors); super(server,executor,scheduler,pool,acceptors,factories);
_manager = new ConnectorSelectorManager(selectors > 0 ? selectors : Math.max(1, (Runtime.getRuntime().availableProcessors()) / 4)); _manager = new ConnectorSelectorManager(selectors > 0 ? selectors : Math.max(1, (Runtime.getRuntime().availableProcessors()) / 4));
addBean(_manager, true); addBean(_manager, true);
// TODO: why we need to set the linger time when in SSL mode ?
if (sslContextFactory != null)
setSoLingerTime(30000);
// TODO: we hardcode HTTP, but this is a generic connector that should not hardcode anything
setDefaultConnectionFactory(new HttpServerConnectionFactory(this));
} }
@Override @Override
@ -257,25 +252,7 @@ public class SelectChannelConnector extends AbstractNetworkConnector
protected Connection newConnection(SocketChannel channel, EndPoint endPoint, Object attachment) protected Connection newConnection(SocketChannel channel, EndPoint endPoint, Object attachment)
{ {
SslContextFactory sslContextFactory = getSslContextFactory(); return getDefaultConnectionFactory().newConnection(this, endPoint);
if (sslContextFactory != null)
{
SSLEngine engine = sslContextFactory.newSSLEngine(endPoint.getRemoteAddress());
engine.setUseClientMode(false);
SslConnection sslConnection = new SslConnection(getByteBufferPool(), getExecutor(), endPoint, engine);
EndPoint appEndPoint = sslConnection.getDecryptedEndPoint();
Connection connection = getDefaultConnectionFactory().newConnection(channel, appEndPoint, attachment);
appEndPoint.setConnection(connection);
connection.onOpen();
return sslConnection;
}
else
{
return getDefaultConnectionFactory().newConnection(channel, endPoint, attachment);
}
} }
/** /**

View File

@ -28,6 +28,7 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -94,7 +95,7 @@ public class Server extends HandlerWrapper implements Attributes
public Server(@Name("port")int port) public Server(@Name("port")int port)
{ {
this((ThreadPool)null); this((ThreadPool)null);
SelectChannelConnector connector=new SelectChannelConnector(this); SelectChannelConnector connector=new HttpServerConnector(this);
connector.setPort(port); connector.setPort(port);
setConnectors(new Connector[]{connector}); setConnectors(new Connector[]{connector});
} }
@ -106,7 +107,7 @@ public class Server extends HandlerWrapper implements Attributes
public Server(@Name("address")InetSocketAddress addr) public Server(@Name("address")InetSocketAddress addr)
{ {
this((ThreadPool)null); this((ThreadPool)null);
SelectChannelConnector connector=new SelectChannelConnector(this); SelectChannelConnector connector=new HttpServerConnector(this);
connector.setHost(addr.getHostName()); connector.setHost(addr.getHostName());
connector.setPort(addr.getPort()); connector.setPort(addr.getPort());
setConnectors(new Connector[]{connector}); setConnectors(new Connector[]{connector});

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.security.Principal; import java.security.Principal;
import java.util.Collection; import java.util.Collection;
import java.util.Enumeration; import java.util.Enumeration;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestWrapper; import javax.servlet.ServletRequestWrapper;

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.ServletResponseWrapper; import javax.servlet.ServletResponseWrapper;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.util.EventListener; import java.util.EventListener;
import java.util.Set; import java.util.Set;
import javax.servlet.SessionCookieConfig; import javax.servlet.SessionCookieConfig;
import javax.servlet.SessionTrackingMode; import javax.servlet.SessionTrackingMode;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;

View File

@ -0,0 +1,99 @@
//
// ========================================================================
// Copyright (c) 1995-2012 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 javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSession;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.util.ssl.SslContextFactory;
public class SslConnectionFactory extends AbstractConnectionFactory
{
private final SslContextFactory _sslContextFactory;
private final String _nextProtocol;
public SslConnectionFactory()
{
this(null,HttpVersion.HTTP_1_1.asString());
}
public SslConnectionFactory(String nextProtocol)
{
this(null,nextProtocol);
}
public SslConnectionFactory(SslContextFactory factory,String nextProtocol)
{
super("SSL-"+nextProtocol);
_sslContextFactory=factory==null?new SslContextFactory():factory;
_nextProtocol=nextProtocol;
addBean(_sslContextFactory);
}
public SslContextFactory getSslContextFactory()
{
return _sslContextFactory;
}
@Override
protected void doStart() throws Exception
{
super.doStart();
SSLEngine engine = _sslContextFactory.newSSLEngine();
engine.setUseClientMode(false);
SSLSession session=engine.getSession();
if (session.getPacketBufferSize()>getInputBufferSize())
setInputBufferSize(session.getPacketBufferSize());
}
@Override
public Connection newConnection(Connector connector, EndPoint endPoint)
{
SSLEngine engine = _sslContextFactory.newSSLEngine(endPoint.getRemoteAddress());
engine.setUseClientMode(false);
SslConnection sslConnection = new SslConnection(connector.getByteBufferPool(), connector.getExecutor(), endPoint, engine);
sslConnection.setInputBufferSize(getInputBufferSize());
EndPoint decrypted_endp = sslConnection.getDecryptedEndPoint();
ConnectionFactory next = connector.getConnectionFactory(_nextProtocol);
Connection connection = next.newConnection(connector, decrypted_endp);
decrypted_endp.setConnection(connection);
connection.onOpen();
return sslConnection;
}
@Override
public String toString()
{
return String.format("%s@%x{%s}",this.getClass().getSimpleName(),hashCode(),getProtocol());
}
}

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.security.Principal; import java.security.Principal;
import java.util.Map; import java.util.Map;
import javax.security.auth.Subject; import javax.security.auth.Subject;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */

View File

@ -37,6 +37,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterRegistration; import javax.servlet.FilterRegistration;

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.Locale; import java.util.Locale;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.server.handler; package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.server.handler; package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.server.handler; package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.server.handler; package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.server.handler; package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.server.handler;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;

View File

@ -24,14 +24,20 @@ import java.nio.channels.SocketChannel;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.NetworkTrafficListener; import org.eclipse.jetty.io.NetworkTrafficListener;
import org.eclipse.jetty.io.NetworkTrafficSelectChannelEndPoint; import org.eclipse.jetty.io.NetworkTrafficSelectChannelEndPoint;
import org.eclipse.jetty.io.SelectChannelEndPoint; import org.eclipse.jetty.io.SelectChannelEndPoint;
import org.eclipse.jetty.io.SelectorManager; import org.eclipse.jetty.io.SelectorManager;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.server.SelectChannelConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.Scheduler;
/** /**
* <p>A specialized version of {@link SelectChannelConnector} that supports {@link NetworkTrafficListener}s.</p> * <p>A specialized version of {@link SelectChannelConnector} that supports {@link NetworkTrafficListener}s.</p>
@ -42,10 +48,30 @@ public class NetworkTrafficSelectChannelConnector extends SelectChannelConnector
{ {
private final List<NetworkTrafficListener> listeners = new CopyOnWriteArrayList<NetworkTrafficListener>(); private final List<NetworkTrafficListener> listeners = new CopyOnWriteArrayList<NetworkTrafficListener>();
public NetworkTrafficSelectChannelConnector(Server server) public NetworkTrafficSelectChannelConnector(Server server)
{ {
super(server); this(server,null,null,null,0,0,new HttpConnectionFactory());
}
public NetworkTrafficSelectChannelConnector(Server server, ConnectionFactory connectionFactory, SslContextFactory sslContextFactory)
{
super(server,sslContextFactory,connectionFactory);
}
public NetworkTrafficSelectChannelConnector(Server server, ConnectionFactory connectionFactory)
{
super(server,connectionFactory);
}
public NetworkTrafficSelectChannelConnector(Server server, Executor executor, Scheduler scheduler, ByteBufferPool pool, int acceptors, int selectors,
ConnectionFactory... factories)
{
super(server,executor,scheduler,pool,acceptors,selectors,factories);
}
public NetworkTrafficSelectChannelConnector(Server server, SslContextFactory sslContextFactory)
{
super(server,sslContextFactory);
} }
/** /**

View File

@ -27,6 +27,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSessionActivationListener; import javax.servlet.http.HttpSessionActivationListener;

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server.session;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Random; import java.util.Random;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.server.SessionIdManager; import org.eclipse.jetty.server.SessionIdManager;

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.server.session; package org.eclipse.jetty.server.session;
import static java.lang.Math.round;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
@ -28,6 +30,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import javax.servlet.SessionCookieConfig; import javax.servlet.SessionCookieConfig;
import javax.servlet.SessionTrackingMode; import javax.servlet.SessionTrackingMode;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -51,8 +54,6 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.statistic.CounterStatistic; import org.eclipse.jetty.util.statistic.CounterStatistic;
import org.eclipse.jetty.util.statistic.SampleStatistic; import org.eclipse.jetty.util.statistic.SampleStatistic;
import static java.lang.Math.round;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* An Abstract implementation of SessionManager. The partial implementation of * An Abstract implementation of SessionManager. The partial implementation of

View File

@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;

View File

@ -31,6 +31,7 @@ import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;

View File

@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Enumeration; import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;

View File

@ -35,6 +35,7 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import javax.naming.InitialContext; import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;

View File

@ -35,6 +35,7 @@ import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener; import javax.servlet.http.HttpSessionListener;

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.server.session;
import java.io.IOException; import java.io.IOException;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.EventListener; import java.util.EventListener;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.SessionTrackingMode; import javax.servlet.SessionTrackingMode;

View File

@ -19,15 +19,11 @@
package org.eclipse.jetty.server.ssl; package org.eclipse.jetty.server.ssl;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -35,11 +31,6 @@ public class SslCertificates
{ {
private static final Logger LOG = Log.getLogger(SslCertificates.class); private static final Logger LOG = Log.getLogger(SslCertificates.class);
/**
* The name of the SSLSession attribute that will contain any cached information.
*/
static final String CACHED_INFO_ATTR = CachedInfo.class.getName();
public static X509Certificate[] getCertChain(SSLSession sslSession) public static X509Certificate[] getCertChain(SSLSession sslSession)
{ {
try try
@ -73,105 +64,4 @@ public class SslCertificates
} }
/* ------------------------------------------------------------ */
/**
* Allow the Listener a chance to customise the request. before the server
* does its stuff. <br>
* This allows the required attributes to be set for SSL requests. <br>
* The requirements of the Servlet specs are:
* <ul>
* <li> an attribute named "javax.servlet.request.ssl_session_id" of type
* String (since Servlet Spec 3.0).</li>
* <li> an attribute named "javax.servlet.request.cipher_suite" of type
* String.</li>
* <li> an attribute named "javax.servlet.request.key_size" of type Integer.</li>
* <li> an attribute named "javax.servlet.request.X509Certificate" of type
* java.security.cert.X509Certificate[]. This is an array of objects of type
* X509Certificate, the order of this array is defined as being in ascending
* order of trust. The first certificate in the chain is the one set by the
* client, the next is the one used to authenticate the first, and so on.
* </li>
* </ul>
*
* @param request
* HttpRequest to be customised.
*/
public static void customize(SSLEngine sslEngine, Request request) throws IOException
{
request.setScheme(HttpScheme.HTTPS.asString());
SSLSession sslSession = sslEngine.getSession();
try
{
String cipherSuite=sslSession.getCipherSuite();
Integer keySize;
X509Certificate[] certs;
String idStr;
CachedInfo cachedInfo=(CachedInfo)sslSession.getValue(CACHED_INFO_ATTR);
if (cachedInfo!=null)
{
keySize=cachedInfo.getKeySize();
certs=cachedInfo.getCerts();
idStr=cachedInfo.getIdStr();
}
else
{
keySize=new Integer(ServletSSL.deduceKeyLength(cipherSuite));
certs=SslCertificates.getCertChain(sslSession);
byte[] bytes = sslSession.getId();
idStr = TypeUtil.toHexString(bytes);
cachedInfo=new CachedInfo(keySize,certs,idStr);
sslSession.putValue(CACHED_INFO_ATTR,cachedInfo);
}
if (certs!=null)
request.setAttribute("javax.servlet.request.X509Certificate",certs);
request.setAttribute("javax.servlet.request.cipher_suite",cipherSuite);
request.setAttribute("javax.servlet.request.key_size",keySize);
request.setAttribute("javax.servlet.request.ssl_session_id", idStr);
}
catch (Exception e)
{
LOG.warn(Log.EXCEPTION,e);
}
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/**
* Simple bundle of information that is cached in the SSLSession. Stores the
* effective keySize and the client certificate chain.
*/
private static class CachedInfo
{
private final X509Certificate[] _certs;
private final Integer _keySize;
private final String _idStr;
CachedInfo(Integer keySize, X509Certificate[] certs,String idStr)
{
this._keySize=keySize;
this._certs=certs;
this._idStr=idStr;
}
X509Certificate[] getCerts()
{
return _certs;
}
Integer getKeySize()
{
return _keySize;
}
String getIdStr()
{
return _idStr;
}
}
} }

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.server.ssl;
import java.io.File; import java.io.File;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.Security; import java.security.Security;
import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.server.ssl; package org.eclipse.jetty.server.ssl;
import org.eclipse.jetty.server.AbstractConnectionFactory;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.server.SelectChannelConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.ssl.SslContextFactory;
@ -33,6 +35,6 @@ public class SslSelectChannelConnector extends SelectChannelConnector
{ {
public SslSelectChannelConnector(Server server) public SslSelectChannelConnector(Server server)
{ {
super(server,new SslContextFactory()); super(server,null,null,null,0,0,AbstractConnectionFactory.getFactories(new SslContextFactory(),new HttpConnectionFactory()));
} }
} }

View File

@ -18,6 +18,9 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -25,6 +28,7 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.Socket; import java.net.Socket;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -37,9 +41,6 @@ import org.eclipse.jetty.util.log.StdErrLog;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
public abstract class AbstractHttpTest public abstract class AbstractHttpTest
{ {
protected static Server server; protected static Server server;
@ -56,7 +57,7 @@ public abstract class AbstractHttpTest
public void setUp() throws Exception public void setUp() throws Exception
{ {
server = new Server(); server = new Server();
connector = new SelectChannelConnector(server); connector = new HttpServerConnector(server);
connector.setIdleTimeout(10000); connector.setIdleTimeout(10000);
server.addConnector(connector); server.addConnector(connector);
httpParser = new SimpleHttpParser(); httpParser = new SimpleHttpParser();

View File

@ -18,6 +18,9 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -25,6 +28,7 @@ import java.net.Socket;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.Exchanger; import java.util.concurrent.Exchanger;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -39,9 +43,6 @@ import org.junit.BeforeClass;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class AsyncRequestReadTest public class AsyncRequestReadTest
{ {
private static Server server; private static Server server;
@ -52,7 +53,7 @@ public class AsyncRequestReadTest
public static void startServer() throws Exception public static void startServer() throws Exception
{ {
server = new Server(); server = new Server();
connector = new SelectChannelConnector(server); connector = new HttpServerConnector(server);
connector.setIdleTimeout(10000); connector.setIdleTimeout(10000);
server.addConnector(connector); server.addConnector(connector);
server.setHandler(new EmptyHandler()); server.setHandler(new EmptyHandler());

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.InetAddress; import java.net.InetAddress;
@ -25,6 +27,7 @@ import java.net.Socket;
import java.util.Random; import java.util.Random;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent; import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener; import javax.servlet.AsyncListener;
@ -44,8 +47,6 @@ import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class AsyncStressTest public class AsyncStressTest
{ {
private static final Logger LOG = Log.getLogger(AsyncStressTest.class); private static final Logger LOG = Log.getLogger(AsyncStressTest.class);
@ -72,7 +73,7 @@ public class AsyncStressTest
{ {
_server.manage(_threads); _server.manage(_threads);
_threads.setMaxThreads(50); _threads.setMaxThreads(50);
_connector = new SelectChannelConnector(_server); _connector = new HttpServerConnector(_server);
_connector.setIdleTimeout(120000); _connector.setIdleTimeout(120000);
_server.setConnectors(new Connector[]{ _connector }); _server.setConnectors(new Connector[]{ _connector });
_server.setHandler(_handler); _server.setHandler(_handler);

View File

@ -1,34 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2012 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;
public class ChannelHttpServer
{
public static void main(String[] s) throws Exception
{
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector(server);
connector.setPort(8080);
server.addConnector(connector);
server.setHandler(new DumpHandler());
server.start();
server.dumpStdErr();
server.join();
}
}

View File

@ -18,7 +18,12 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -26,10 +31,6 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/** /**
* *
*/ */
@ -97,11 +98,11 @@ public class CheckReverseProxyHeadersTest
private void testRequest(String headers, RequestValidator requestValidator) throws Exception private void testRequest(String headers, RequestValidator requestValidator) throws Exception
{ {
Server server = new Server(); Server server = new Server();
LocalConnector connector = new LocalConnector(server);
// Activate reverse proxy headers checking // Activate reverse proxy headers checking
HttpConfiguration httpConfiguration = new HttpConfiguration(null, false); HttpConnectionFactory http = new HttpConnectionFactory();
httpConfiguration.setForwarded(true); http.getHttpChannelConfig().addCustomizer(new ForwardedRequestCustomizer());
connector.setDefaultConnectionFactory(new HttpServerConnectionFactory(connector, httpConfiguration));
LocalConnector connector = new LocalConnector(server,http);
server.setConnectors(new Connector[] {connector}); server.setConnectors(new Connector[] {connector});
ValidationHandler validationHandler = new ValidationHandler(requestValidator); ValidationHandler validationHandler = new ValidationHandler(requestValidator);
@ -159,6 +160,7 @@ public class CheckReverseProxyHeadersTest
return _error; return _error;
} }
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{ {
try try

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -28,8 +30,6 @@ import java.util.concurrent.TimeUnit;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertTrue;
/** /**
* HttpServer Tester. * HttpServer Tester.
*/ */

View File

@ -18,6 +18,10 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.matchers.JUnitMatchers.containsString;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -25,6 +29,7 @@ import java.net.Socket;
import java.net.SocketException; import java.net.SocketException;
import java.util.concurrent.Exchanger; import java.util.concurrent.Exchanger;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -37,10 +42,6 @@ import org.eclipse.jetty.util.IO;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.matchers.JUnitMatchers.containsString;
public abstract class ConnectorTimeoutTest extends HttpServerTestFixture public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
{ {
protected static final int MAX_IDLE_TIME=500; protected static final int MAX_IDLE_TIME=500;
@ -243,14 +244,12 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
// further writes will get broken pipe or similar // further writes will get broken pipe or similar
try try
{ {
for (int i=0;i<1000;i++) long end=System.currentTimeMillis()+MAX_IDLE_TIME+3000;
while (System.currentTimeMillis()<end)
{ {
os.write(( os.write("THIS DATA SHOULD NOT BE PARSED!\n\n".getBytes("utf-8"));
"GET / HTTP/1.0\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"connection: keep-alive\r\n"+
"\r\n").getBytes("utf-8"));
os.flush(); os.flush();
Thread.sleep(500);
} }
Assert.fail("half close should have timed out"); Assert.fail("half close should have timed out");
} }
@ -259,8 +258,6 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
// expected // expected
} }
Thread.sleep(2 * MAX_IDLE_TIME);
// check the server side is closed // check the server side is closed
Assert.assertFalse(endPoint.isOpen()); Assert.assertFalse(endPoint.isOpen());
} }
@ -467,6 +464,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
protected static class SlowResponseHandler extends AbstractHandler protected static class SlowResponseHandler extends AbstractHandler
{ {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{ {
baseRequest.setHandled(true); baseRequest.setHandled(true);
@ -485,6 +483,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
protected static class WaitHandler extends AbstractHandler protected static class WaitHandler extends AbstractHandler
{ {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{ {
baseRequest.setHandled(true); baseRequest.setHandled(true);

View File

@ -25,6 +25,7 @@ import java.io.OutputStreamWriter;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.util.Enumeration; import java.util.Enumeration;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;

View File

@ -24,10 +24,16 @@
*/ */
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -44,11 +50,6 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* *
*/ */
@ -63,12 +64,13 @@ public class HttpConnectionTest
public void init() throws Exception public void init() throws Exception
{ {
server = new Server(); server = new Server();
connector = new LocalConnector(server);
HttpConnectionFactory http = new HttpConnectionFactory();
http.getHttpChannelConfig().setRequestHeaderSize(1024);
http.getHttpChannelConfig().setResponseHeaderSize(1024);
connector = new LocalConnector(server,http,null);
server.addConnector(connector); server.addConnector(connector);
HttpConfiguration httpConfiguration = new HttpConfiguration(null, false);
httpConfiguration.setRequestHeaderSize(1024);
httpConfiguration.setResponseHeaderSize(1024);
connector.setDefaultConnectionFactory(new HttpServerConnectionFactory(connector, httpConfiguration));
server.setHandler(new DumpHandler()); server.setHandler(new DumpHandler());
server.start(); server.start();
} }

View File

@ -18,6 +18,9 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -25,6 +28,7 @@ import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier; import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -36,9 +40,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
//TODO: reset buffer tests //TODO: reset buffer tests
//TODO: add protocol specific tests for connection: close and/or chunking //TODO: add protocol specific tests for connection: close and/or chunking

View File

@ -18,9 +18,14 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
@ -33,10 +38,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
//TODO: reset buffer tests //TODO: reset buffer tests
//TODO: add protocol specific tests for connection: close and/or chunking //TODO: add protocol specific tests for connection: close and/or chunking
@RunWith(value = Parameterized.class) @RunWith(value = Parameterized.class)

View File

@ -18,9 +18,14 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -31,10 +36,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
//TODO: reset buffer tests //TODO: reset buffer tests
//TODO: add protocol specific tests for connection: close and/or chunking //TODO: add protocol specific tests for connection: close and/or chunking
@RunWith(value = Parameterized.class) @RunWith(value = Parameterized.class)

View File

@ -18,6 +18,12 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
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.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -30,6 +36,7 @@ import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.Random; import java.util.Random;
import java.util.concurrent.Exchanger; import java.util.concurrent.Exchanger;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -46,12 +53,6 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.matchers.JUnitMatchers; import org.junit.matchers.JUnitMatchers;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* *
*/ */

View File

@ -25,6 +25,7 @@ import java.io.OutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Writer; import java.io.Writer;
import java.net.Socket; import java.net.Socket;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import javax.servlet.ServletException; import javax.servlet.ServletException;

View File

@ -18,22 +18,23 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import junit.framework.Assert; import junit.framework.Assert;
import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class HttpURITest public class HttpURITest
{ {
private final String[][] partial_tests= private final String[][] partial_tests=

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -30,8 +32,6 @@ import org.eclipse.jetty.util.Utf8StringBuilder;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class HttpWriterTest public class HttpWriterTest
{ {
private HttpOutput _httpOut; private HttpOutput _httpOut;
@ -42,16 +42,9 @@ public class HttpWriterTest
{ {
_bytes = BufferUtil.allocate(2048); _bytes = BufferUtil.allocate(2048);
final HttpConfiguration configuration = new HttpConfiguration(null, false);
final ByteBufferPool bufferPool = new MappedByteBufferPool(); final ByteBufferPool bufferPool = new MappedByteBufferPool();
HttpChannel channel = new HttpChannel<ByteBuffer>(null,null,null,null,null) HttpChannel<?> channel = new HttpChannel<ByteBuffer>(null,new HttpChannelConfig(),null,null,null)
{ {
@Override
public HttpConfiguration getHttpConfiguration()
{
return configuration;
}
@Override @Override
public ByteBufferPool getByteBufferPool() public ByteBufferPool getByteBufferPool()
{ {

View File

@ -18,15 +18,15 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.List; import java.util.List;
import java.util.Vector; import java.util.Vector;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
public class InclusiveByteRangeTest public class InclusiveByteRangeTest
{ {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -18,9 +18,12 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent; import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener; import javax.servlet.AsyncListener;
@ -37,8 +40,6 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class LocalAsyncContextTest public class LocalAsyncContextTest
{ {
protected Server _server = new Server(); protected Server _server = new Server();

View File

@ -18,13 +18,13 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
public class LocalConnectorTest public class LocalConnectorTest
{ {
private Server _server; private Server _server;

View File

@ -18,6 +18,9 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -27,6 +30,7 @@ import java.nio.ByteBuffer;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -41,9 +45,6 @@ import org.junit.After;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@Ignore @Ignore
public class NetworkTrafficListenerTest public class NetworkTrafficListenerTest
{ {

View File

@ -24,6 +24,11 @@
*/ */
package org.eclipse.jetty.server; 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.Date;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
@ -37,11 +42,6 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; 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;
/** /**
* *
*/ */

View File

@ -18,6 +18,14 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
@ -29,6 +37,7 @@ import java.util.Arrays;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -48,14 +57,6 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class RequestTest public class RequestTest
{ {
private static final Logger LOG = Log.getLogger(RequestTest.class); private static final Logger LOG = Log.getLogger(RequestTest.class);
@ -67,15 +68,13 @@ public class RequestTest
public void init() throws Exception public void init() throws Exception
{ {
_server = new Server(); _server = new Server();
_connector = new LocalConnector(_server); HttpConnectionFactory http = new HttpConnectionFactory();
HttpConfiguration httpConfiguration = new HttpConfiguration(null, false); http.setInputBufferSize(1024);
httpConfiguration.setRequestHeaderSize(512); http.getHttpChannelConfig().setRequestHeaderSize(512);
httpConfiguration.setRequestBufferSize(1024); http.getHttpChannelConfig().setResponseHeaderSize(512);
httpConfiguration.setResponseHeaderSize(512); http.getHttpChannelConfig().setOutputBufferSize(2048);
httpConfiguration.setResponseBufferSize(2048); http.getHttpChannelConfig().addCustomizer(new ForwardedRequestCustomizer());
httpConfiguration.setForwarded(true); _connector = new LocalConnector(_server,http);
HttpServerConnectionFactory defaultConnectionFactory = new HttpServerConnectionFactory(_connector, httpConfiguration);
_connector.setDefaultConnectionFactory(defaultConnectionFactory);
_server.addConnector(_connector); _server.addConnector(_connector);
_handler = new RequestHandler(); _handler = new RequestHandler();
_server.setHandler(_handler); _server.setHandler(_handler);

View File

@ -18,6 +18,9 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -30,9 +33,6 @@ import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection; import org.eclipse.jetty.util.resource.ResourceCollection;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ResourceCacheTest public class ResourceCacheTest
{ {
@Test @Test

View File

@ -18,6 +18,11 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
@ -26,6 +31,7 @@ import java.net.Socket;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -49,11 +55,6 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class ResponseTest public class ResponseTest
{ {
private Server _server; private Server _server;
@ -65,14 +66,15 @@ public class ResponseTest
{ {
_server = new Server(); _server = new Server();
_scheduler = new TimerScheduler(); _scheduler = new TimerScheduler();
LocalConnector connector = new LocalConnector(_server, null, _scheduler, null, null, 1); HttpChannelConfig config = new HttpChannelConfig();
LocalConnector connector = new LocalConnector(_server,null,_scheduler,null,1,new HttpConnectionFactory(config));
_server.addConnector(connector); _server.addConnector(connector);
_server.setHandler(new DumpHandler()); _server.setHandler(new DumpHandler());
_server.start(); _server.start();
AbstractEndPoint endp = new ByteArrayEndPoint(_scheduler, 5000); AbstractEndPoint endp = new ByteArrayEndPoint(_scheduler, 5000);
ByteBufferHttpInput input = new ByteBufferHttpInput(); ByteBufferHttpInput input = new ByteBufferHttpInput();
_channel = new HttpChannel(connector, new HttpConfiguration(null, false), endp, new HttpTransport() _channel = new HttpChannel<ByteBuffer>(connector, new HttpChannelConfig(), endp, new HttpTransport()
{ {
@Override @Override
public void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent) throws IOException public void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent) throws IOException

View File

@ -18,6 +18,9 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -25,6 +28,7 @@ import java.io.PrintWriter;
import java.net.Socket; import java.net.Socket;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier; import java.util.concurrent.CyclicBarrier;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -41,9 +45,6 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class SelectChannelStatisticsTest public class SelectChannelStatisticsTest
{ {
private static final Logger LOG = Log.getLogger(SelectChannelStatisticsTest.class); private static final Logger LOG = Log.getLogger(SelectChannelStatisticsTest.class);

View File

@ -18,6 +18,8 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@ -28,8 +30,6 @@ import org.eclipse.jetty.util.IO;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class SelectChannelTimeoutTest extends ConnectorTimeoutTest public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
{ {
@Before @Before

Some files were not shown because too many files have changed in this diff Show More