Merge branch 'jetty-9.1' into release-9.1
This commit is contained in:
commit
80212c1648
|
@ -2,6 +2,12 @@
|
|||
#
|
||||
# Startup script for jetty under *nix systems (it works under NT/cygwin too).
|
||||
|
||||
##################################################
|
||||
# Set the name which is used by other variables.
|
||||
# Defaults to the file name without extension.
|
||||
##################################################
|
||||
NAME=$(echo $(basename $0) | sed -e 's/^[SK][0-9]+//' -e 's/\.sh$//')
|
||||
|
||||
# To get the service to restart correctly on reboot, uncomment below (3 lines):
|
||||
# ========================
|
||||
# chkconfig: 3 99 99
|
||||
|
@ -11,15 +17,15 @@
|
|||
|
||||
# Configuration files
|
||||
#
|
||||
# /etc/default/jetty
|
||||
# /etc/default/$NAME
|
||||
# If it exists, this is read at the start of script. It may perform any
|
||||
# sequence of shell commands, like setting relevant environment variables.
|
||||
#
|
||||
# $HOME/.jettyrc
|
||||
# $HOME/.$NAMErc (e.g. $HOME/.jettyrc)
|
||||
# If it exists, this is read at the start of script. It may perform any
|
||||
# sequence of shell commands, like setting relevant environment variables.
|
||||
#
|
||||
# /etc/jetty.conf
|
||||
# /etc/$NAME.conf
|
||||
# If found, and no configurations were given on the command line,
|
||||
# the file will be used as this script's configuration.
|
||||
# Each line in the file may contain:
|
||||
|
@ -31,10 +37,6 @@
|
|||
#
|
||||
# The files will be checked for existence before being passed to jetty.
|
||||
#
|
||||
# $JETTY_HOME/etc/jetty.xml
|
||||
# If found, used as this script's configuration file, but only if
|
||||
# /etc/jetty.conf was not present. See above.
|
||||
#
|
||||
# Configuration variables
|
||||
#
|
||||
# JAVA
|
||||
|
@ -67,12 +69,12 @@
|
|||
# <Set name="Port">8080</Set>
|
||||
#
|
||||
# JETTY_RUN
|
||||
# Where the jetty.pid file should be stored. It defaults to the
|
||||
# first available of /var/run, /usr/var/run, JETTY_HOME and /tmp
|
||||
# Where the $NAME.pid file should be stored. It defaults to the
|
||||
# first available of /var/run, /usr/var/run, JETTY_BASE and /tmp
|
||||
# if not set.
|
||||
#
|
||||
# JETTY_PID
|
||||
# The Jetty PID file, defaults to $JETTY_RUN/jetty.pid
|
||||
# The Jetty PID file, defaults to $JETTY_RUN/$NAME.pid
|
||||
#
|
||||
# JETTY_ARGS
|
||||
# The default arguments to pass to jetty.
|
||||
|
@ -81,7 +83,6 @@
|
|||
#
|
||||
# JETTY_USER
|
||||
# if set, then used as a username to run the server as
|
||||
#
|
||||
|
||||
usage()
|
||||
{
|
||||
|
@ -92,12 +93,6 @@ usage()
|
|||
[ $# -gt 0 ] || usage
|
||||
|
||||
|
||||
##################################################
|
||||
# Set the name
|
||||
##################################################
|
||||
JETTY=jetty
|
||||
|
||||
|
||||
##################################################
|
||||
# Some utility functions
|
||||
##################################################
|
||||
|
@ -169,7 +164,7 @@ then
|
|||
ETC=$HOME/etc
|
||||
fi
|
||||
|
||||
for CONFIG in $ETC/default/${JETTY}{,9} $HOME/.${JETTY}rc; do
|
||||
for CONFIG in $ETC/default/${NAME}{,9} $HOME/.${NAME}rc; do
|
||||
if [ -f "$CONFIG" ] ; then
|
||||
readConfig "$CONFIG"
|
||||
fi
|
||||
|
@ -249,9 +244,9 @@ fi
|
|||
##################################################
|
||||
if [ -z "$JETTY_CONF" ]
|
||||
then
|
||||
if [ -f $ETC/${JETTY}.conf ]
|
||||
if [ -f $ETC/${NAME}.conf ]
|
||||
then
|
||||
JETTY_CONF=$ETC/${JETTY}.conf
|
||||
JETTY_CONF=$ETC/${NAME}.conf
|
||||
elif [ -f "$JETTY_BASE/etc/jetty.conf" ]
|
||||
then
|
||||
JETTY_CONF=$JETTY_BASE/etc/jetty.conf
|
||||
|
@ -298,7 +293,7 @@ fi
|
|||
#####################################################
|
||||
if [ -z "$JETTY_RUN" ]
|
||||
then
|
||||
JETTY_RUN=$(findDirectory -w /var/run /usr/var/run $JETTY_HOME /tmp)
|
||||
JETTY_RUN=$(findDirectory -w /var/run /usr/var/run $JETTY_BASE /tmp)
|
||||
fi
|
||||
|
||||
#####################################################
|
||||
|
@ -306,12 +301,12 @@ fi
|
|||
#####################################################
|
||||
if [ -z "$JETTY_PID" ]
|
||||
then
|
||||
JETTY_PID="$JETTY_RUN/${JETTY}.pid"
|
||||
JETTY_PID="$JETTY_RUN/${NAME}.pid"
|
||||
fi
|
||||
|
||||
if [ -z "$JETTY_STATE" ]
|
||||
then
|
||||
JETTY_STATE=$JETTY_HOME/${JETTY}.state
|
||||
JETTY_STATE=$JETTY_BASE/${NAME}.state
|
||||
fi
|
||||
JAVA_OPTIONS+=("-Djetty.state=$JETTY_STATE")
|
||||
rm -f $JETTY_STATE
|
||||
|
@ -409,7 +404,7 @@ case "$ACTION" in
|
|||
echo -n "Starting Jetty: "
|
||||
|
||||
if (( NO_START )); then
|
||||
echo "Not starting ${JETTY} - NO_START=1";
|
||||
echo "Not starting ${NAME} - NO_START=1";
|
||||
exit
|
||||
fi
|
||||
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.eclipse.org/configure.dtd">
|
||||
|
||||
<!--
|
||||
Configure a custom context for serving javadoc as static resources
|
||||
-->
|
||||
|
||||
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
|
||||
<Set name="contextPath">/javadoc</Set>
|
||||
<Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc/</Set>
|
||||
<Set name="handler">
|
||||
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
|
||||
<Set name="welcomeFiles">
|
||||
<Array type="String">
|
||||
<Item>index.html</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
<Set name="cacheControl">max-age=3600,public</Set>
|
||||
</New>
|
||||
</Set>
|
||||
</Configure>
|
||||
|
|
@ -31,6 +31,7 @@ import org.eclipse.jetty.server.handler.ContextHandler;
|
|||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.Constants;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
|
@ -120,7 +121,7 @@ public class ServiceContextProvider extends AbstractContextProvider implements S
|
|||
properties.put(key, serviceRef.getProperty(key));
|
||||
}
|
||||
Bundle bundle = serviceRef.getBundle();
|
||||
String originId = bundle.getSymbolicName() + "-" + bundle.getVersion().toString() + "-"+contextFile;
|
||||
String originId = bundle.getSymbolicName() + "-" + bundle.getVersion().toString() + "-"+(contextFile!=null?contextFile:serviceRef.getProperty(Constants.SERVICE_ID));
|
||||
ServiceApp app = new ServiceApp(getDeploymentManager(), this, bundle, properties, contextFile, originId);
|
||||
app.setHandler(context); //set the pre=made ContextHandler instance
|
||||
_serviceMap.put(serviceRef, app);
|
||||
|
|
|
@ -35,7 +35,7 @@ public class AsyncContextEvent extends AsyncEvent
|
|||
final private AsyncContextState _asyncContext;
|
||||
volatile HttpChannelState _state;
|
||||
private ServletContext _dispatchContext;
|
||||
private String _pathInContext;
|
||||
private String _dispatchPath;
|
||||
private Scheduler.Task _timeoutTask;
|
||||
private Throwable _throwable;
|
||||
|
||||
|
@ -98,7 +98,7 @@ public class AsyncContextEvent extends AsyncEvent
|
|||
*/
|
||||
public String getPath()
|
||||
{
|
||||
return _pathInContext;
|
||||
return _dispatchPath;
|
||||
}
|
||||
|
||||
public void setTimeoutTask(Scheduler.Task task)
|
||||
|
@ -131,14 +131,15 @@ public class AsyncContextEvent extends AsyncEvent
|
|||
_throwable=throwable;
|
||||
}
|
||||
|
||||
public void setDispatchTarget(ServletContext context, String path)
|
||||
public void setDispatchContext(ServletContext context)
|
||||
{
|
||||
if (context!=null)
|
||||
_dispatchContext=context;
|
||||
if (path!=null)
|
||||
_pathInContext=path;
|
||||
_dispatchContext=context;
|
||||
}
|
||||
|
||||
public void setDispatchPath(String path)
|
||||
{
|
||||
_dispatchPath=path;
|
||||
}
|
||||
|
||||
|
||||
public void completed()
|
||||
{
|
||||
|
|
|
@ -262,6 +262,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
|
|||
HttpChannelState.Action action = _state.handling();
|
||||
loop: while (action.ordinal()<HttpChannelState.Action.WAIT.ordinal() && getServer().isRunning())
|
||||
{
|
||||
boolean error=false;
|
||||
try
|
||||
{
|
||||
LOG.debug("{} action {}",this,action);
|
||||
|
@ -309,7 +310,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
|
|||
{
|
||||
String error_page=((ErrorHandler.ErrorPageMapper)eh).getErrorPage((HttpServletRequest)_state.getAsyncContextEvent().getSuppliedRequest());
|
||||
if (error_page!=null)
|
||||
_state.getAsyncContextEvent().setDispatchTarget(_state.getContextHandler().getServletContext(),error_page);
|
||||
_state.getAsyncContextEvent().setDispatchPath(error_page);
|
||||
}
|
||||
|
||||
getServer().handleAsync(this);
|
||||
|
@ -346,10 +347,14 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
|
|||
if ("ContinuationThrowable".equals(e.getClass().getSimpleName()))
|
||||
LOG.ignore(e);
|
||||
else
|
||||
{
|
||||
error=true;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
error=true;
|
||||
if (e instanceof EofException)
|
||||
LOG.debug(e);
|
||||
else
|
||||
|
@ -360,6 +365,8 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
|
|||
}
|
||||
finally
|
||||
{
|
||||
if (error && _state.isAsyncStarted())
|
||||
_state.errorComplete();
|
||||
action = _state.unhandle();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -351,7 +351,11 @@ public class HttpChannelState
|
|||
if (_async!=Async.STARTED && _async!=Async.EXPIRING)
|
||||
throw new IllegalStateException("AsyncContext#dispath "+this.getStatusString());
|
||||
_async=Async.DISPATCH;
|
||||
_event.setDispatchTarget(context,path);
|
||||
|
||||
if (context!=null)
|
||||
_event.setDispatchContext(context);
|
||||
if (path!=null)
|
||||
_event.setDispatchPath(path);
|
||||
|
||||
switch(_state)
|
||||
{
|
||||
|
@ -439,6 +443,18 @@ public class HttpChannelState
|
|||
}
|
||||
}
|
||||
|
||||
public void errorComplete()
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
_async=Async.COMPLETE;
|
||||
_event.setDispatchContext(null);
|
||||
_event.setDispatchPath(null);
|
||||
}
|
||||
|
||||
cancelTimeout();
|
||||
}
|
||||
|
||||
protected void completed()
|
||||
{
|
||||
final List<AsyncListener> aListeners;
|
||||
|
|
|
@ -2044,7 +2044,8 @@ public class Request implements HttpServletRequest
|
|||
if (_async==null)
|
||||
_async=new AsyncContextState(state);
|
||||
AsyncContextEvent event = new AsyncContextEvent(_context,_async,state,this,servletRequest,servletResponse);
|
||||
event.setDispatchTarget(getServletContext(),URIUtil.addPaths(getServletPath(),getPathInfo()));
|
||||
event.setDispatchContext(getServletContext());
|
||||
event.setDispatchPath(URIUtil.addPaths(getServletPath(),getPathInfo()));
|
||||
state.startAsync(event);
|
||||
return _async;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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.server.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.AsyncEvent;
|
||||
import javax.servlet.AsyncListener;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.server.HttpConnection;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
|
||||
/**
|
||||
* Handler to adjust the idle timeout of requests while dispatched.
|
||||
* Can be applied in jetty.xml with
|
||||
* <pre>
|
||||
* <Get id='handler' name='Handler'/>
|
||||
* <Set name='Handler'>
|
||||
* <New id='idleTimeoutHandler' class='org.eclipse.jetty.server.handler.IdleTimeoutHandler'>
|
||||
* <Set name='Handler'><Ref id='handler'/></Set>
|
||||
* <Set name='IdleTimeoutMs'>5000</Set>
|
||||
* </New>
|
||||
* </Set>
|
||||
* </pre>
|
||||
*/
|
||||
public class IdleTimeoutHandler extends HandlerWrapper
|
||||
{
|
||||
private long _idleTimeoutMs = 1000;
|
||||
private boolean _applyToAsync = false;
|
||||
|
||||
public boolean isApplyToAsync()
|
||||
{
|
||||
return _applyToAsync;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the adjusted idle time be maintained for asynchronous requests
|
||||
* @param applyToAsync true if alternate idle timeout is applied to asynchronous requests
|
||||
*/
|
||||
public void setApplyToAsync(boolean applyToAsync)
|
||||
{
|
||||
_applyToAsync = applyToAsync;
|
||||
}
|
||||
|
||||
public long getIdleTimeoutMs()
|
||||
{
|
||||
return _idleTimeoutMs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param idleTimeoutMs The idle timeout in MS to apply while dispatched or async
|
||||
*/
|
||||
public void setIdleTimeoutMs(long idleTimeoutMs)
|
||||
{
|
||||
this._idleTimeoutMs = idleTimeoutMs;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
HttpConnection connection = HttpConnection.getCurrentConnection();
|
||||
final EndPoint endp = connection==null?null:connection.getEndPoint();
|
||||
|
||||
final long idle_timeout;
|
||||
if (endp==null)
|
||||
idle_timeout=-1;
|
||||
else
|
||||
{
|
||||
idle_timeout=endp.getIdleTimeout();
|
||||
endp.setIdleTimeout(_idleTimeoutMs);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
super.handle(target,baseRequest,request,response);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (endp!=null)
|
||||
{
|
||||
if (_applyToAsync && request.isAsyncStarted())
|
||||
{
|
||||
request.getAsyncContext().addListener(new AsyncListener()
|
||||
{
|
||||
@Override
|
||||
public void onTimeout(AsyncEvent event) throws IOException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartAsync(AsyncEvent event) throws IOException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(AsyncEvent event) throws IOException
|
||||
{
|
||||
endp.setIdleTimeout(idle_timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(AsyncEvent event) throws IOException
|
||||
{
|
||||
endp.setIdleTimeout(idle_timeout);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
endp.setIdleTimeout(idle_timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -613,7 +613,7 @@ public class ServletHandler extends ScopedHandler
|
|||
{
|
||||
// Complete async errored requests
|
||||
if (th!=null && request.isAsyncStarted())
|
||||
request.getAsyncContext().complete();
|
||||
baseRequest.getHttpChannelState().errorComplete();
|
||||
|
||||
if (servlet_holder!=null)
|
||||
baseRequest.setHandled(true);
|
||||
|
|
|
@ -122,8 +122,11 @@ public class AsyncContextTest
|
|||
@Test
|
||||
public void testStartThrow() throws Exception
|
||||
{
|
||||
String request = "GET /ctx/startthrow HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
|
||||
+ "Connection: close\r\n" + "\r\n";
|
||||
String request =
|
||||
"GET /ctx/startthrow HTTP/1.1\r\n" +
|
||||
"Host: localhost\r\n" +
|
||||
"Connection: close\r\n" +
|
||||
"\r\n";
|
||||
String responseString = _connector.getResponses(request);
|
||||
|
||||
BufferedReader br = new BufferedReader(new StringReader(responseString));
|
||||
|
@ -137,6 +140,68 @@ public class AsyncContextTest
|
|||
Assert.assertEquals("error servlet","PathInfo= /IOE",br.readLine());
|
||||
Assert.assertEquals("error servlet","EXCEPTION: org.eclipse.jetty.server.QuietServletException: java.io.IOException: Test",br.readLine());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartDispatchThrow() throws Exception
|
||||
{
|
||||
String request = "GET /ctx/startthrow?dispatch=true HTTP/1.1\r\n" +
|
||||
"Host: localhost\r\n" +
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n" +
|
||||
"Connection: close\r\n" +
|
||||
"\r\n";
|
||||
String responseString = _connector.getResponses(request);
|
||||
|
||||
BufferedReader br = new BufferedReader(new StringReader(responseString));
|
||||
|
||||
assertEquals("HTTP/1.1 500 Server Error",br.readLine());
|
||||
br.readLine();// connection close
|
||||
br.readLine();// server
|
||||
br.readLine();// empty
|
||||
Assert.assertEquals("error servlet","ERROR: /error",br.readLine());
|
||||
Assert.assertEquals("error servlet","PathInfo= /IOE",br.readLine());
|
||||
Assert.assertEquals("error servlet","EXCEPTION: org.eclipse.jetty.server.QuietServletException: java.io.IOException: Test",br.readLine());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartCompleteThrow() throws Exception
|
||||
{
|
||||
String request = "GET /ctx/startthrow?complete=true HTTP/1.1\r\n" +
|
||||
"Host: localhost\r\n" +
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n" +
|
||||
"Connection: close\r\n" +
|
||||
"\r\n";
|
||||
String responseString = _connector.getResponses(request);
|
||||
|
||||
BufferedReader br = new BufferedReader(new StringReader(responseString));
|
||||
|
||||
assertEquals("HTTP/1.1 500 Server Error",br.readLine());
|
||||
br.readLine();// connection close
|
||||
br.readLine();// server
|
||||
br.readLine();// empty
|
||||
Assert.assertEquals("error servlet","ERROR: /error",br.readLine());
|
||||
Assert.assertEquals("error servlet","PathInfo= /IOE",br.readLine());
|
||||
Assert.assertEquals("error servlet","EXCEPTION: org.eclipse.jetty.server.QuietServletException: java.io.IOException: Test",br.readLine());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartFlushCompleteThrow() throws Exception
|
||||
{
|
||||
String request = "GET /ctx/startthrow?flush=true&complete=true HTTP/1.1\r\n" +
|
||||
"Host: localhost\r\n" +
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n" +
|
||||
"Connection: close\r\n" +
|
||||
"\r\n";
|
||||
String responseString = _connector.getResponses(request);
|
||||
|
||||
BufferedReader br = new BufferedReader(new StringReader(responseString));
|
||||
|
||||
assertEquals("HTTP/1.1 200 OK",br.readLine());
|
||||
br.readLine();// connection close
|
||||
br.readLine();// server
|
||||
br.readLine();// empty
|
||||
|
||||
Assert.assertEquals("error servlet","completeBeforeThrow",br.readLine());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDispatchAsyncContext() throws Exception
|
||||
|
@ -497,6 +562,20 @@ public class AsyncContextTest
|
|||
if (request.getDispatcherType()==DispatcherType.REQUEST)
|
||||
{
|
||||
request.startAsync(request, response);
|
||||
|
||||
if (Boolean.valueOf(request.getParameter("dispatch")))
|
||||
{
|
||||
request.getAsyncContext().dispatch();
|
||||
}
|
||||
|
||||
if (Boolean.valueOf(request.getParameter("complete")))
|
||||
{
|
||||
response.getOutputStream().write("completeBeforeThrow".getBytes());
|
||||
if (Boolean.valueOf(request.getParameter("flush")))
|
||||
response.flushBuffer();
|
||||
request.getAsyncContext().complete();
|
||||
}
|
||||
|
||||
throw new QuietServletException(new IOException("Test"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,42 +18,68 @@
|
|||
|
||||
package org.eclipse.jetty.spdy.client.http;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.http.HttpScheme;
|
||||
import org.eclipse.jetty.server.AbstractConnectionFactory;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.NetworkConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.spdy.api.SPDY;
|
||||
import org.eclipse.jetty.spdy.client.SPDYClient;
|
||||
import org.eclipse.jetty.spdy.server.http.HTTPSPDYServerConnectionFactory;
|
||||
import org.eclipse.jetty.spdy.server.http.PushStrategy;
|
||||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public abstract class AbstractHttpClientServerTest
|
||||
{
|
||||
@Parameterized.Parameters
|
||||
public static Collection<SslContextFactory[]> parameters()
|
||||
{
|
||||
return Arrays.asList(new SslContextFactory[]{null}, new SslContextFactory[]{new SslContextFactory()});
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final TestTracker tracker = new TestTracker();
|
||||
|
||||
protected SslContextFactory sslContextFactory;
|
||||
protected String scheme;
|
||||
protected Server server;
|
||||
protected NetworkConnector connector;
|
||||
protected ServerConnector connector;
|
||||
protected SPDYClient.Factory factory;
|
||||
protected HttpClient client;
|
||||
protected String scheme = HttpScheme.HTTP.asString();
|
||||
|
||||
public AbstractHttpClientServerTest(SslContextFactory sslContextFactory)
|
||||
{
|
||||
this.sslContextFactory = sslContextFactory;
|
||||
this.scheme = (sslContextFactory == null ? HttpScheme.HTTP : HttpScheme.HTTPS).asString();
|
||||
}
|
||||
|
||||
public void start(Handler handler) throws Exception
|
||||
{
|
||||
server = new Server();
|
||||
|
||||
short version = SPDY.V3;
|
||||
|
||||
HTTPSPDYServerConnectionFactory spdyConnectionFactory = new HTTPSPDYServerConnectionFactory(version, new HttpConfiguration(), new PushStrategy.None());
|
||||
connector = new ServerConnector(server, spdyConnectionFactory);
|
||||
HTTPSPDYServerConnectionFactory httpSPDY = new HTTPSPDYServerConnectionFactory(version, new HttpConfiguration());
|
||||
if (sslContextFactory != null)
|
||||
{
|
||||
sslContextFactory.setEndpointIdentificationAlgorithm("");
|
||||
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
|
||||
sslContextFactory.setKeyStorePassword("storepwd");
|
||||
sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks");
|
||||
sslContextFactory.setTrustStorePassword("storepwd");
|
||||
}
|
||||
|
||||
server = new Server();
|
||||
connector = new ServerConnector(server, AbstractConnectionFactory.getFactories(sslContextFactory, httpSPDY));
|
||||
server.addConnector(connector);
|
||||
server.setHandler(handler);
|
||||
server.start();
|
||||
|
@ -63,8 +89,7 @@ public abstract class AbstractHttpClientServerTest
|
|||
|
||||
factory = new SPDYClient.Factory(executor);
|
||||
factory.start();
|
||||
|
||||
client = new HttpClient(new HttpClientTransportOverSPDY(factory.newSPDYClient(version)), null);
|
||||
client = new HttpClient(new HttpClientTransportOverSPDY(factory.newSPDYClient(version)), sslContextFactory);
|
||||
client.setExecutor(executor);
|
||||
client.start();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -41,11 +40,17 @@ import org.eclipse.jetty.client.util.BytesContentProvider;
|
|||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.toolchain.test.annotation.Slow;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpClientTest extends AbstractHttpClientServerTest
|
||||
{
|
||||
public HttpClientTest(SslContextFactory sslContextFactory)
|
||||
{
|
||||
super(sslContextFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_GET_ResponseWithoutContent() throws Exception
|
||||
{
|
||||
|
|
|
@ -321,6 +321,17 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
|
|||
{
|
||||
return _priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the job queue.
|
||||
*
|
||||
* @return Number of jobs queued waiting for a thread
|
||||
*/
|
||||
@ManagedAttribute("Size of the job queue")
|
||||
public int getQueueSize()
|
||||
{
|
||||
return _jobs.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegated to the named or anonymous Pool.
|
||||
|
@ -517,12 +528,14 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
|
|||
startThreads(1);
|
||||
}
|
||||
|
||||
while (isRunning())
|
||||
loop: while (isRunning())
|
||||
{
|
||||
// Job loop
|
||||
while (job != null && isRunning())
|
||||
{
|
||||
runJob(job);
|
||||
if (Thread.interrupted())
|
||||
break loop;
|
||||
job = _jobs.poll();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-sessions-parent</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
<version>9.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-mongodb-sessions</artifactId>
|
||||
<name>Jetty Tests :: Sessions :: Mongo</name>
|
||||
|
|
|
@ -31,9 +31,9 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.eclipse.jetty.client.ContentExchange;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.http.HttpMethods;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -88,41 +88,30 @@ public class PurgeInvalidSessionTest
|
|||
try
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
client.setConnectorType(HttpClient.CONNECTOR_SOCKET);
|
||||
client.start();
|
||||
try
|
||||
{
|
||||
//Create a session
|
||||
ContentExchange exchange = new ContentExchange(true);
|
||||
exchange.setMethod(HttpMethods.GET);
|
||||
exchange.setURL("http://localhost:" + port + contextPath + servletMapping + "?action=create");
|
||||
client.send(exchange);
|
||||
exchange.waitForDone();
|
||||
assertEquals(HttpServletResponse.SC_OK,exchange.getResponseStatus());
|
||||
String sessionCookie = exchange.getResponseFields().getStringField("Set-Cookie");
|
||||
ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create");
|
||||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
|
||||
assertTrue(sessionCookie != null);
|
||||
// Mangle the cookie, replacing Path with $Path, etc.
|
||||
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
|
||||
|
||||
//make a request to invalidate the session
|
||||
exchange = new ContentExchange(true);
|
||||
exchange.setMethod(HttpMethods.GET);
|
||||
exchange.setURL("http://localhost:" + port + contextPath + servletMapping + "?action=invalidate");
|
||||
exchange.getRequestFields().add("Cookie", sessionCookie);
|
||||
client.send(exchange);
|
||||
exchange.waitForDone();
|
||||
assertEquals(HttpServletResponse.SC_OK,exchange.getResponseStatus());
|
||||
Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=invalidate");
|
||||
request.header("Cookie", sessionCookie);
|
||||
response = request.send();
|
||||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||
|
||||
Thread.currentThread().sleep(3*purgeDelay); //sleep long enough for purger to have run
|
||||
|
||||
//make a request using previous session to test if its still there
|
||||
exchange = new ContentExchange(true);
|
||||
exchange.setMethod(HttpMethods.GET);
|
||||
exchange.setURL("http://localhost:" + port + contextPath + servletMapping + "?action=test");
|
||||
exchange.getRequestFields().add("Cookie", sessionCookie);
|
||||
client.send(exchange);
|
||||
exchange.waitForDone();
|
||||
assertEquals(HttpServletResponse.SC_OK,exchange.getResponseStatus());
|
||||
//make a request using previous session to test if its still there
|
||||
request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=test");
|
||||
request.header("Cookie", sessionCookie);
|
||||
response = request.send();
|
||||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -31,9 +31,10 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.eclipse.jetty.client.ContentExchange;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.http.HttpMethods;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -90,18 +91,13 @@ public class PurgeValidSessionTest
|
|||
try
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
client.setConnectorType(HttpClient.CONNECTOR_SOCKET);
|
||||
client.start();
|
||||
try
|
||||
{
|
||||
//Create a session
|
||||
ContentExchange exchange = new ContentExchange(true);
|
||||
exchange.setMethod(HttpMethods.GET);
|
||||
exchange.setURL("http://localhost:" + port + contextPath + servletMapping + "?action=create");
|
||||
client.send(exchange);
|
||||
exchange.waitForDone();
|
||||
assertEquals(HttpServletResponse.SC_OK,exchange.getResponseStatus());
|
||||
String sessionCookie = exchange.getResponseFields().getStringField("Set-Cookie");
|
||||
ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create");
|
||||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||
String sessionCookie = response.getHeaders().getStringField("Set-Cookie");
|
||||
assertTrue(sessionCookie != null);
|
||||
// Mangle the cookie, replacing Path with $Path, etc.
|
||||
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
|
||||
|
@ -110,13 +106,10 @@ public class PurgeValidSessionTest
|
|||
Thread.currentThread().sleep(3*purgeDelay); //sleep long enough for purger to have run
|
||||
|
||||
//make a request using previous session to test if its still there
|
||||
exchange = new ContentExchange(true);
|
||||
exchange.setMethod(HttpMethods.GET);
|
||||
exchange.setURL("http://localhost:" + port + contextPath + servletMapping + "?action=test");
|
||||
exchange.getRequestFields().add("Cookie", sessionCookie);
|
||||
client.send(exchange);
|
||||
exchange.waitForDone();
|
||||
assertEquals(HttpServletResponse.SC_OK,exchange.getResponseStatus());
|
||||
Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=test");
|
||||
request.header("Cookie", sessionCookie);
|
||||
ContentResponse response2 = request.send();
|
||||
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -108,9 +108,8 @@ public class SessionSavingValueTest extends AbstractSessionValueSavingTest
|
|||
{ "0", "null" };
|
||||
|
||||
// Perform one request to server1 to create a session
|
||||
Request request = client.newRequest("http://localhost:" + port1 + contextPath + servletMapping + "?action=init");
|
||||
Future<ContentResponse> future = request.send();
|
||||
ContentResponse response = future.get();
|
||||
ContentResponse response = client.GET("http://localhost:" + port1 + contextPath + servletMapping + "?action=init");
|
||||
|
||||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||
|
||||
String[] sessionTestResponse = response.getContentAsString().split("/");
|
||||
|
@ -134,8 +133,7 @@ public class SessionSavingValueTest extends AbstractSessionValueSavingTest
|
|||
{
|
||||
Request request2 = client.newRequest("http://localhost:" + port1 + contextPath + servletMapping);
|
||||
request2.header("Cookie",sessionCookie);
|
||||
Future<ContentResponse> future2 = request2.send();
|
||||
ContentResponse response2 = future2.get();
|
||||
ContentResponse response2 = request2.send();
|
||||
|
||||
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
</servlet>
|
||||
|
||||
<!-- Allow remote access to test webapp -->
|
||||
<!--
|
||||
<filter>
|
||||
<filter-name>TestFilter</filter-name>
|
||||
<filter-class>com.acme.TestFilter</filter-class>
|
||||
|
@ -48,6 +49,7 @@
|
|||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
-->
|
||||
|
||||
</web-app>
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@ cross domain scripting vulnerabilities and reveal private information. This pag
|
|||
is displayed because you have accessed this context from a non local IP address.
|
||||
</p>
|
||||
<p>
|
||||
You can disable the remote address checking by editing webapps/test.d/override-web.xml, uncommenting the declaration of the TestFilter, and changing the
|
||||
You can disable the remote address checking by editing demo-base/webapps/test.d/override-web.xml, uncommenting the declaration of the TestFilter, and changing the
|
||||
"remote" init parameter to "true".
|
||||
</p>
|
||||
<p>
|
||||
This webapp is deployed in $JETTY_HOME/webapps/test and configured by $JETTY_HOME/webapps/test.xml and $JETTY_HOME/webapps/test.d/override-web.xml
|
||||
This webapp is deployed in $JETTY_HOME/demo-base/webapps/test.war and configured by $JETTY_HOME/demo-base/webapps/test.xml and $JETTY_HOME/demo-base/webapps/test.d/override-web.xml
|
||||
</p>
|
||||
|
||||
</BODY>
|
||||
|
|
Loading…
Reference in New Issue