Merge branch 'master' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project
This commit is contained in:
commit
2a2eb9cd38
|
@ -147,7 +147,8 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
||||||
HttpConversation conversation = exchange.getConversation();
|
HttpConversation conversation = exchange.getConversation();
|
||||||
HttpResponse response = exchange.getResponse();
|
HttpResponse response = exchange.getResponse();
|
||||||
|
|
||||||
parser.setHeadResponse(HttpMethod.HEAD.is(exchange.getRequest().method()));
|
String method = exchange.getRequest().method();
|
||||||
|
parser.setHeadResponse(HttpMethod.HEAD.is(method) || HttpMethod.CONNECT.is(method));
|
||||||
response.version(version).status(status).reason(reason);
|
response.version(version).status(status).reason(reason);
|
||||||
|
|
||||||
// Probe the protocol handlers
|
// Probe the protocol handlers
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-project</artifactId>
|
<artifactId>jetty-project</artifactId>
|
||||||
<version>9.0.0-SNAPSHOT</version>
|
<version>9.0.5-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>jetty-http-spi</artifactId>
|
<artifactId>jetty-http-spi</artifactId>
|
||||||
|
|
|
@ -0,0 +1,160 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2013 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.http.spi;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||||
|
import org.eclipse.jetty.util.component.LifeCycle;
|
||||||
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||||
|
|
||||||
|
public class DelegatingThreadPool extends ContainerLifeCycle implements ThreadPool
|
||||||
|
{
|
||||||
|
private static final Logger LOG = Log.getLogger(DelegatingThreadPool.class);
|
||||||
|
|
||||||
|
private Executor _executor; // memory barrier provided by start/stop semantics
|
||||||
|
|
||||||
|
public DelegatingThreadPool(Executor executor)
|
||||||
|
{
|
||||||
|
_executor=executor;
|
||||||
|
addBean(_executor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
public Executor getExecutor()
|
||||||
|
{
|
||||||
|
return _executor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
public void setExecutor(Executor executor)
|
||||||
|
{
|
||||||
|
if (isRunning())
|
||||||
|
throw new IllegalStateException(getState());
|
||||||
|
updateBean(_executor,executor);
|
||||||
|
_executor=executor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Override
|
||||||
|
public void execute(Runnable job)
|
||||||
|
{
|
||||||
|
_executor.execute(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Override
|
||||||
|
public boolean dispatch(Runnable job)
|
||||||
|
{
|
||||||
|
final Executor executor=_executor;
|
||||||
|
if (executor instanceof ThreadPool)
|
||||||
|
return ((ThreadPool)executor).dispatch(job);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_executor.execute(job);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(RejectedExecutionException e)
|
||||||
|
{
|
||||||
|
LOG.warn(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Override
|
||||||
|
public int getIdleThreads()
|
||||||
|
{
|
||||||
|
final Executor executor=_executor;
|
||||||
|
if (executor instanceof ThreadPool)
|
||||||
|
return ((ThreadPool)executor).getIdleThreads();
|
||||||
|
|
||||||
|
if (executor instanceof ThreadPoolExecutor)
|
||||||
|
{
|
||||||
|
final ThreadPoolExecutor tpe = (ThreadPoolExecutor)executor;
|
||||||
|
return tpe.getPoolSize() - tpe.getActiveCount();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Override
|
||||||
|
public int getThreads()
|
||||||
|
{
|
||||||
|
final Executor executor=_executor;
|
||||||
|
if (executor instanceof ThreadPool)
|
||||||
|
return ((ThreadPool)executor).getThreads();
|
||||||
|
|
||||||
|
if (executor instanceof ThreadPoolExecutor)
|
||||||
|
{
|
||||||
|
final ThreadPoolExecutor tpe = (ThreadPoolExecutor)executor;
|
||||||
|
return tpe.getPoolSize();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Override
|
||||||
|
public boolean isLowOnThreads()
|
||||||
|
{
|
||||||
|
final Executor executor=_executor;
|
||||||
|
if (executor instanceof ThreadPool)
|
||||||
|
return ((ThreadPool)executor).isLowOnThreads();
|
||||||
|
|
||||||
|
if (executor instanceof ThreadPoolExecutor)
|
||||||
|
{
|
||||||
|
final ThreadPoolExecutor tpe = (ThreadPoolExecutor)executor;
|
||||||
|
// getActiveCount() locks the thread pool, so execute it last
|
||||||
|
return tpe.getPoolSize() == tpe.getMaximumPoolSize() &&
|
||||||
|
tpe.getQueue().size() >= tpe.getPoolSize() - tpe.getActiveCount();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Override
|
||||||
|
public void join() throws InterruptedException
|
||||||
|
{
|
||||||
|
final Executor executor=_executor;
|
||||||
|
if (executor instanceof ThreadPool)
|
||||||
|
((ThreadPool)executor).join();
|
||||||
|
else if (executor instanceof ExecutorService)
|
||||||
|
((ExecutorService)executor).awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||||
|
else
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
@Override
|
||||||
|
protected void doStop() throws Exception
|
||||||
|
{
|
||||||
|
super.doStop();
|
||||||
|
if (!(_executor instanceof LifeCycle) && (_executor instanceof ExecutorService))
|
||||||
|
((ExecutorService)_executor).shutdownNow();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -20,18 +20,26 @@ package org.eclipse.jetty.http.spi;
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpContext;
|
import com.sun.net.httpserver.HttpContext;
|
||||||
import com.sun.net.httpserver.HttpHandler;
|
import com.sun.net.httpserver.HttpHandler;
|
||||||
|
|
||||||
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.NetworkConnector;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.server.ServerConnector;
|
||||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
|
||||||
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
@ -68,10 +76,10 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer
|
||||||
public void bind(InetSocketAddress addr, int backlog) throws IOException
|
public void bind(InetSocketAddress addr, int backlog) throws IOException
|
||||||
{
|
{
|
||||||
// check if there is already a connector listening
|
// check if there is already a connector listening
|
||||||
Connector[] connectors = _server.getConnectors();
|
Collection<NetworkConnector> connectors = _server.getBeans(NetworkConnector.class);
|
||||||
if (connectors != null)
|
if (connectors != null)
|
||||||
{
|
{
|
||||||
for (Connector connector : connectors)
|
for (NetworkConnector connector : connectors)
|
||||||
{
|
{
|
||||||
if (connector.getPort() == addr.getPort()) {
|
if (connector.getPort() == addr.getPort()) {
|
||||||
if (LOG.isDebugEnabled()) LOG.debug("server already bound to port " + addr.getPort() + ", no need to rebind");
|
if (LOG.isDebugEnabled()) LOG.debug("server already bound to port " + addr.getPort() + ", no need to rebind");
|
||||||
|
@ -86,8 +94,7 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer
|
||||||
this._addr = addr;
|
this._addr = addr;
|
||||||
|
|
||||||
if (LOG.isDebugEnabled()) LOG.debug("binding server to port " + addr.getPort());
|
if (LOG.isDebugEnabled()) LOG.debug("binding server to port " + addr.getPort());
|
||||||
SelectChannelConnector connector = new SelectChannelConnector();
|
ServerConnector connector = new ServerConnector(_server);
|
||||||
connector.setAcceptors(1);
|
|
||||||
connector.setPort(addr.getPort());
|
connector.setPort(addr.getPort());
|
||||||
connector.setHost(addr.getHostName());
|
connector.setHost(addr.getHostName());
|
||||||
_server.addConnector(connector);
|
_server.addConnector(connector);
|
||||||
|
@ -121,19 +128,20 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer
|
||||||
{
|
{
|
||||||
if (executor == null)
|
if (executor == null)
|
||||||
throw new IllegalArgumentException("missing required 'executor' argument");
|
throw new IllegalArgumentException("missing required 'executor' argument");
|
||||||
|
ThreadPool threadPool = _server.getThreadPool();
|
||||||
if (!(executor instanceof ThreadPoolExecutor))
|
if (threadPool instanceof DelegatingThreadPool)
|
||||||
throw new IllegalArgumentException("only java.util.concurrent.ThreadPoolExecutor instances are allowed, got: " + executor.getClass().getName());
|
((DelegatingThreadPool)_server.getThreadPool()).setExecutor(executor);
|
||||||
|
else
|
||||||
if (LOG.isDebugEnabled()) LOG.debug("using ThreadPoolExecutor for server thread pool");
|
throw new UnsupportedOperationException("!DelegatingThreadPool");
|
||||||
this._executor = (ThreadPoolExecutor) executor;
|
|
||||||
_server.setThreadPool(new ThreadPoolExecutorAdapter(_executor));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Executor getExecutor()
|
public Executor getExecutor()
|
||||||
{
|
{
|
||||||
return _executor;
|
ThreadPool threadPool = _server.getThreadPool();
|
||||||
|
if (threadPool instanceof DelegatingThreadPool)
|
||||||
|
return ((DelegatingThreadPool)_server.getThreadPool()).getExecutor();
|
||||||
|
return threadPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,6 +26,9 @@ import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||||
|
import org.eclipse.jetty.util.thread.ExecutorThreadPool;
|
||||||
|
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||||
|
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpServer;
|
import com.sun.net.httpserver.HttpServer;
|
||||||
import com.sun.net.httpserver.HttpsServer;
|
import com.sun.net.httpserver.HttpsServer;
|
||||||
|
@ -53,11 +56,12 @@ public class JettyHttpServerProvider extends HttpServerProvider
|
||||||
|
|
||||||
if (server == null)
|
if (server == null)
|
||||||
{
|
{
|
||||||
server = new Server();
|
ThreadPool threadPool = new DelegatingThreadPool(new QueuedThreadPool());
|
||||||
|
server = new Server(threadPool);
|
||||||
HandlerCollection handlerCollection = new HandlerCollection();
|
|
||||||
handlerCollection.setHandlers(new Handler[] {new ContextHandlerCollection(), new DefaultHandler()});
|
HandlerCollection handlerCollection = new HandlerCollection();
|
||||||
server.setHandler(handlerCollection);
|
handlerCollection.setHandlers(new Handler[] {new ContextHandlerCollection(), new DefaultHandler()});
|
||||||
|
server.setHandler(handlerCollection);
|
||||||
|
|
||||||
shared = false;
|
shared = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,124 +0,0 @@
|
||||||
//
|
|
||||||
// ========================================================================
|
|
||||||
// Copyright (c) 1995-2013 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.http.spi;
|
|
||||||
|
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
|
||||||
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.util.thread.ThreadPool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Jetty {@link ThreadPool} that bridges requests to a {@link ThreadPoolExecutor}.
|
|
||||||
*/
|
|
||||||
public class ThreadPoolExecutorAdapter extends AbstractLifeCycle implements ThreadPool
|
|
||||||
{
|
|
||||||
private static final Logger LOG = Log.getLogger(ThreadPoolExecutorAdapter.class);
|
|
||||||
|
|
||||||
|
|
||||||
private ThreadPoolExecutor executor;
|
|
||||||
|
|
||||||
public ThreadPoolExecutorAdapter(ThreadPoolExecutor executor)
|
|
||||||
{
|
|
||||||
this.executor = executor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean dispatch(Runnable job)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
executor.execute(job);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch(RejectedExecutionException e)
|
|
||||||
{
|
|
||||||
LOG.warn(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIdleThreads()
|
|
||||||
{
|
|
||||||
return executor.getPoolSize()-executor.getActiveCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getThreads()
|
|
||||||
{
|
|
||||||
return executor.getPoolSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLowOnThreads()
|
|
||||||
{
|
|
||||||
return executor.getActiveCount()>=executor.getMaximumPoolSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void join() throws InterruptedException
|
|
||||||
{
|
|
||||||
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean isFailed()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRunning()
|
|
||||||
{
|
|
||||||
return !executor.isTerminated() && !executor.isTerminating();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStarted()
|
|
||||||
{
|
|
||||||
return !executor.isTerminated() && !executor.isTerminating();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStarting()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStopped()
|
|
||||||
{
|
|
||||||
return executor.isTerminated();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStopping()
|
|
||||||
{
|
|
||||||
return executor.isTerminating();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void doStart() throws Exception
|
|
||||||
{
|
|
||||||
if (executor.isTerminated() || executor.isTerminating() || executor.isShutdown())
|
|
||||||
throw new IllegalStateException("Cannot restart");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void doStop() throws Exception
|
|
||||||
{
|
|
||||||
executor.shutdown();
|
|
||||||
if (!executor.awaitTermination(60, TimeUnit.SECONDS))
|
|
||||||
executor.shutdownNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -20,11 +20,13 @@ package org.eclipse.jetty.proxy;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
|
import java.net.Socket;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
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;
|
||||||
|
@ -55,6 +57,8 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Assume;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -116,14 +120,20 @@ public class ProxyTunnellingTest
|
||||||
|
|
||||||
protected void stopServer() throws Exception
|
protected void stopServer() throws Exception
|
||||||
{
|
{
|
||||||
server.stop();
|
if (server != null)
|
||||||
server.join();
|
{
|
||||||
|
server.stop();
|
||||||
|
server.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stopProxy() throws Exception
|
protected void stopProxy() throws Exception
|
||||||
{
|
{
|
||||||
proxy.stop();
|
if (proxy != null)
|
||||||
proxy.join();
|
{
|
||||||
|
proxy.stop();
|
||||||
|
proxy.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -364,6 +374,43 @@ public class ProxyTunnellingTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore // to delicate to rely on external proxy.
|
||||||
|
public void testExternalProxy() throws Exception
|
||||||
|
{
|
||||||
|
// Free proxy server obtained from http://hidemyass.com/proxy-list/
|
||||||
|
String proxyHost = "81.208.25.53";
|
||||||
|
int proxyPort = 3128;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
new Socket(proxyHost, proxyPort).close();
|
||||||
|
}
|
||||||
|
catch (IOException x)
|
||||||
|
{
|
||||||
|
Assume.assumeNoException(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
SslContextFactory sslContextFactory = new SslContextFactory();
|
||||||
|
sslContextFactory.start();
|
||||||
|
|
||||||
|
HttpClient httpClient = new HttpClient(sslContextFactory);
|
||||||
|
httpClient.setProxyConfiguration(new ProxyConfiguration(proxyHost, proxyPort));
|
||||||
|
httpClient.start();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ContentResponse response = httpClient.newRequest("https://www.google.com")
|
||||||
|
// Use a longer timeout, sometimes the proxy takes a while to answer
|
||||||
|
.timeout(20, TimeUnit.SECONDS)
|
||||||
|
.send();
|
||||||
|
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
httpClient.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class ServerHandler extends AbstractHandler
|
private static class ServerHandler extends AbstractHandler
|
||||||
{
|
{
|
||||||
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
|
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
|
||||||
|
|
|
@ -98,6 +98,23 @@ public class ServerConnector extends AbstractNetworkConnector
|
||||||
{
|
{
|
||||||
this(server,null,null,null,0,0,new HttpConnectionFactory());
|
this(server,null,null,null,0,0,new HttpConnectionFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
/** HTTP Server Connection.
|
||||||
|
* <p>Construct a ServerConnector with a private instance of {@link HttpConnectionFactory} as the only factory.</p>
|
||||||
|
* @param server The {@link Server} this connector will accept connection for.
|
||||||
|
* @param acceptors
|
||||||
|
* the number of acceptor threads to use, or 0 for a default value. Acceptors accept new TCP/IP connections.
|
||||||
|
* @param selectors
|
||||||
|
* the number of selector threads, or 0 for a default value. Selectors notice and schedule established connection that can make IO progress.
|
||||||
|
*/
|
||||||
|
public ServerConnector(
|
||||||
|
@Name("server") Server server,
|
||||||
|
@Name("acceptors") int acceptors,
|
||||||
|
@Name("selectors") int selectors)
|
||||||
|
{
|
||||||
|
this(server,null,null,null,acceptors,selectors,new HttpConnectionFactory());
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/** Generic Server Connection with default configuration.
|
/** Generic Server Connection with default configuration.
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -451,10 +451,10 @@
|
||||||
<module>jetty-distribution</module>
|
<module>jetty-distribution</module>
|
||||||
<module>jetty-runner</module>
|
<module>jetty-runner</module>
|
||||||
<module>jetty-monitor</module>
|
<module>jetty-monitor</module>
|
||||||
|
<module>jetty-http-spi</module>
|
||||||
|
|
||||||
<!-- modules that need fixed and added back, or simply dropped and not maintained
|
<!-- modules that need fixed and added back, or simply dropped and not maintained
|
||||||
<module>jetty-rhttp</module>
|
<module>jetty-rhttp</module>
|
||||||
<module>jetty-http-spi</module>
|
|
||||||
-->
|
-->
|
||||||
<module>jetty-overlay-deployer</module>
|
<module>jetty-overlay-deployer</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
Loading…
Reference in New Issue