changeset 1000:32d4b569567c

simplify handle()
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 19 Oct 2016 04:22:51 -0600
parents 74b9daf2826c
children 39154cfa58e4
files src/luan/modules/http/AuthenticationHandler.java src/luan/modules/http/HttpServicer.java src/luan/modules/http/LuanHandler.java src/luan/modules/http/NotFound.java src/org/eclipse/jetty/server/Handler.java src/org/eclipse/jetty/server/Request.java src/org/eclipse/jetty/server/Server.java src/org/eclipse/jetty/server/handler/ContextHandler.java src/org/eclipse/jetty/server/handler/DefaultHandler.java src/org/eclipse/jetty/server/handler/GzipHandler.java src/org/eclipse/jetty/server/handler/HandlerCollection.java src/org/eclipse/jetty/server/handler/HandlerList.java src/org/eclipse/jetty/server/handler/HandlerWrapper.java src/org/eclipse/jetty/server/handler/RequestLogHandler.java src/org/eclipse/jetty/server/handler/ResourceHandler.java src/org/eclipse/jetty/server/handler/ShutdownHandler.java
diffstat 16 files changed, 187 insertions(+), 227 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/http/AuthenticationHandler.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/luan/modules/http/AuthenticationHandler.java	Wed Oct 19 04:22:51 2016 -0600
@@ -2,7 +2,6 @@
 
 import java.io.IOException;
 import java.util.Base64;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.eclipse.jetty.server.Request;
 import org.eclipse.jetty.server.handler.AbstractHandler;
@@ -20,7 +19,8 @@
 		this.password = password;
 	}
 
-	public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) 
+	@Override
+	public void handle(String target,Request request,HttpServletResponse response) 
 		throws IOException
 	{
 		if( !target.startsWith(path) )
@@ -30,10 +30,10 @@
 			return;
 		response.setHeader("WWW-Authenticate","Basic realm=\""+path+"\"");
 		response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
-		baseRequest.setHandled(true);
+		request.setHandled(true);
 	}
 
-	private static String getPassword(HttpServletRequest request) {
+	private static String getPassword(Request request) {
 		String auth = request.getHeader("Authorization");
 		if( auth==null )
 			return null;
--- a/src/luan/modules/http/HttpServicer.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/luan/modules/http/HttpServicer.java	Wed Oct 19 04:22:51 2016 -0600
@@ -18,7 +18,7 @@
 import javax.servlet.ServletOutputStream;
 import javax.servlet.ServletException;
 import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
+import org.eclipse.jetty.server.Request;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.Part;
 import org.slf4j.Logger;
@@ -49,7 +49,7 @@
 		}
 	};
 
-	public static boolean service(LuanState luan,HttpServletRequest request,HttpServletResponse response,String modName)
+	public static boolean service(LuanState luan,Request request,HttpServletResponse response,String modName)
 		throws LuanException
 	{
 		LuanFunction fn;
@@ -265,7 +265,7 @@
 		return value.replaceAll("%3B", ";");
 	}
 
-	private static Cookie getCookie(HttpServletRequest request,String name) {
+	private static Cookie getCookie(Request request,String name) {
 		Cookie[] cookies = request.getCookies();
 		if( cookies == null )
 			return null;
@@ -276,7 +276,7 @@
 		return null;
 	}
 
-	public static void setCookie(HttpServletRequest request,HttpServletResponse response,String name,String value,boolean isPersistent, String domain) {
+	public static void setCookie(Request request,HttpServletResponse response,String name,String value,boolean isPersistent, String domain) {
 		Cookie cookie = getCookie(request,name);
 		if( cookie==null || !cookie.getValue().equals(value) ) {
 			cookie = new Cookie(name, escape(value));
@@ -289,7 +289,7 @@
 		}
 	}
 
-	public static void removeCookie(HttpServletRequest request,
+	public static void removeCookie(Request request,
 									HttpServletResponse response,
 									String name,
 									String domain
--- a/src/luan/modules/http/LuanHandler.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Wed Oct 19 04:22:51 2016 -0600
@@ -4,7 +4,6 @@
 import java.lang.reflect.Method;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,7 +48,8 @@
 		}
 	}
 
-	@Override public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) 
+	@Override
+	public void handle(String target,Request request,HttpServletResponse response) 
 		throws IOException
 	{
 //Thread.dumpStack();
@@ -71,7 +71,7 @@
 			lock.readLock().unlock();
 			thread.setName(oldName);
 		}
-		baseRequest.setHandled(true);
+		request.setHandled(true);
 	}
 
 	public void setWelcomeFile(String welcomeFile) {
--- a/src/luan/modules/http/NotFound.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/luan/modules/http/NotFound.java	Wed Oct 19 04:22:51 2016 -0600
@@ -1,7 +1,6 @@
 package luan.modules.http;
 
 import java.io.IOException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.eclipse.jetty.server.Request;
 import org.eclipse.jetty.server.handler.AbstractHandler;
@@ -14,10 +13,11 @@
 		this.luanHandler = luanHandler;
 	}
 
-	@Override public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) 
+	@Override
+	public void handle(String target,Request request,HttpServletResponse response) 
 		throws IOException
 	{
-		luanHandler.handle("/not_found",baseRequest,request,response);
+		luanHandler.handle("/not_found",request,response);
 	}
 
 }
--- a/src/org/eclipse/jetty/server/Handler.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/Handler.java	Wed Oct 19 04:22:51 2016 -0600
@@ -21,7 +21,6 @@
 import java.io.IOException;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.server.handler.HandlerCollection;
@@ -60,7 +59,7 @@
      * @throws IOException
      * @throws ServletException
      */
-    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
+    public void handle(String target, Request request, HttpServletResponse response)
         throws IOException, ServletException;
     
     public void setServer(Server server);
--- a/src/org/eclipse/jetty/server/Request.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/Request.java	Wed Oct 19 04:22:51 2016 -0600
@@ -490,7 +490,7 @@
 	}
 
 	@Override
-	public Map getParameterMap()
+	public Map<String,String[]> getParameterMap()
 	{
 		if (!_paramsExtracted)
 			extractParameters();
--- a/src/org/eclipse/jetty/server/Server.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/Server.java	Wed Oct 19 04:22:51 2016 -0600
@@ -29,8 +29,6 @@
 import java.util.concurrent.TimeUnit;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.http.HttpURI;
 import org.eclipse.jetty.server.handler.HandlerWrapper;
@@ -145,15 +143,7 @@
 		final String target = connection.getRequest().getPathInfo();
 		final Request request = connection.getRequest();
 		final Response response = connection.getResponse();
-
-		if (LOG.isDebugEnabled())
-		{
-			LOG.debug("REQUEST "+target+" on "+connection);
-			handle(target, request, request, response);
-			LOG.debug("RESPONSE "+target+"  "+connection.getResponse().getStatus()+" handled="+request.isHandled());
-		}
-		else
-			handle(target, request, request, response);
+		handle(target, request, response);
 	}
 /*
 	public void join() throws InterruptedException
--- a/src/org/eclipse/jetty/server/handler/ContextHandler.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/ContextHandler.java	Wed Oct 19 04:22:51 2016 -0600
@@ -57,7 +57,6 @@
 import javax.servlet.FilterRegistration;
 import javax.servlet.FilterRegistration.Dynamic;
 import javax.servlet.descriptor.JspConfigDescriptor;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.http.HttpException;
@@ -151,9 +150,9 @@
 		LOG.info("stopped {}",this);
 	}
 
-	private boolean checkContext(final String target, final Request baseRequest, final HttpServletResponse response) throws IOException, ServletException
+	private boolean checkContext(final String target, final Request request, final HttpServletResponse response) throws IOException, ServletException
 	{
-		if (baseRequest.isHandled())
+		if (request.isHandled())
 			return false;
 
 		// Are we not the root context?
@@ -169,11 +168,11 @@
 			if (_contextPath.length() == target.length())
 			{
 				// context request must end with /
-				baseRequest.setHandled(true);
-				if (baseRequest.getQueryString() != null)
-					response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(),URIUtil.SLASH) + "?" + baseRequest.getQueryString());
+				request.setHandled(true);
+				if (request.getQueryString() != null)
+					response.sendRedirect(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH) + "?" + request.getQueryString());
 				else
-					response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(),URIUtil.SLASH));
+					response.sendRedirect(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH));
 				return false;
 			}
 		}
@@ -182,18 +181,18 @@
 	}
 
 	@Override
-	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+	public void handle(String target, Request request, HttpServletResponse response) throws IOException, ServletException
 	{
 		String old_context_path = null;
 		String old_path_info = null;
 		String pathInfo = target;
 
-		ContextHandler oldContextHandler = baseRequest._contextHandler;
+		ContextHandler oldContextHandler = request._contextHandler;
 
 		// Are we already in this context?
 		if (oldContextHandler != this)
 		{
-			if (!checkContext(target,baseRequest,response))
+			if (!checkContext(target,request,response))
 				return;
 
 			if (target.length() > _contextPath.length())
@@ -216,28 +215,28 @@
 
 		try
 		{
-			old_context_path = baseRequest.getContextPath();
-			old_path_info = baseRequest.getPathInfo();
+			old_context_path = request.getContextPath();
+			old_path_info = request.getPathInfo();
 
 			// Update the paths
-			baseRequest._contextHandler = this;
+			request._contextHandler = this;
 			if (target.startsWith("/"))
 			{
 				if (_contextPath.length() == 1)
-					baseRequest.setContextPath("");
+					request.setContextPath("");
 				else
-					baseRequest.setContextPath(_contextPath);
-				baseRequest.setPathInfo(pathInfo);
+					request.setContextPath(_contextPath);
+				request.setPathInfo(pathInfo);
 			}
 
 			try
 			{
-				super.handle(target,baseRequest,request,response);
+				super.handle(target,request,response);
 			}
 			catch (HttpException e)
 			{
 				LOG.debug("",e);
-				baseRequest.setHandled(true);
+				request.setHandled(true);
 				response.sendError(e.getStatus(),e.getReason());
 			}
 		}
@@ -246,9 +245,9 @@
 			if (oldContextHandler != this)
 			{
 				// reset the context and servlet path.
-				baseRequest._contextHandler = oldContextHandler;
-				baseRequest.setContextPath(old_context_path);
-				baseRequest.setPathInfo(old_path_info);
+				request._contextHandler = oldContextHandler;
+				request.setContextPath(old_context_path);
+				request.setPathInfo(old_path_info);
 			}
 		}
 	}
--- a/src/org/eclipse/jetty/server/handler/DefaultHandler.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/DefaultHandler.java	Wed Oct 19 04:22:51 2016 -0600
@@ -23,7 +23,6 @@
 import java.net.URL;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.http.HttpHeaders;
@@ -57,16 +56,13 @@
 
 	boolean _showContexts=true;
 	
-	/* ------------------------------------------------------------ */
-	/* 
-	 * @see org.eclipse.jetty.server.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
-	 */
-	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+	@Override
+	public void handle(String target, Request request, HttpServletResponse response) throws IOException, ServletException
 	{              
-		if (response.isCommitted() || baseRequest.isHandled())
+		if (response.isCommitted() || request.isHandled())
 			return;
 		
-		baseRequest.setHandled(true);
+		request.setHandled(true);
 		
 		String method=request.getMethod();
 		
--- a/src/org/eclipse/jetty/server/handler/GzipHandler.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/GzipHandler.java	Wed Oct 19 04:22:51 2016 -0600
@@ -230,12 +230,8 @@
 		_minGzipSize = minGzipSize;
 	}
 
-	/* ------------------------------------------------------------ */
-	/**
-	 * @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
-	 */
 	@Override
-	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+	public void handle(String target, Request request, HttpServletResponse response) throws IOException, ServletException
 	{
 		if (_handler!=null && isStarted())
 		{
@@ -248,7 +244,7 @@
 					String ua = request.getHeader("User-Agent");
 					if (_excluded.contains(ua))
 					{
-						_handler.handle(target,baseRequest, request, response);
+						_handler.handle(target, request, response);
 						return;
 					}
 				}
@@ -258,7 +254,7 @@
 				boolean exceptional=true;
 				try
 				{
-					_handler.handle(target, baseRequest, request, wrappedResponse);
+					_handler.handle(target, request, wrappedResponse);
 					exceptional=false;
 				}
 				finally
@@ -274,7 +270,7 @@
 			}
 			else
 			{
-				_handler.handle(target,baseRequest, request, response);
+				_handler.handle(target, request, response);
 			}
 		}
 	}
--- a/src/org/eclipse/jetty/server/handler/HandlerCollection.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/HandlerCollection.java	Wed Oct 19 04:22:51 2016 -0600
@@ -22,7 +22,6 @@
 import java.util.concurrent.CountDownLatch;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.server.Handler;
@@ -132,12 +131,8 @@
 		this._parallelStart = parallelStart;
 	}
 
-
-	/* ------------------------------------------------------------ */
-	/**
-	 * @see Handler#handle(String, Request, HttpServletRequest, HttpServletResponse)
-	 */
-	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) 
+	@Override
+	public void handle(String target, Request request, HttpServletResponse response) 
 		throws IOException, ServletException
 	{
 		if (_handlers!=null && isStarted())
@@ -148,7 +143,7 @@
 			{
 				try
 				{
-					_handlers[i].handle(target,baseRequest, request, response);
+					_handlers[i].handle(target, request, response);
 				}
 				catch(IOException e)
 				{
--- a/src/org/eclipse/jetty/server/handler/HandlerList.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/HandlerList.java	Wed Oct 19 04:22:51 2016 -0600
@@ -21,7 +21,6 @@
 import java.io.IOException;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.server.Handler;
@@ -35,24 +34,20 @@
  */
 public class HandlerList extends HandlerCollection
 {
-    /* ------------------------------------------------------------ */
-    /**
-     * @see Handler#handle(String, Request, HttpServletRequest, HttpServletResponse)
-     */
-    @Override
-    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) 
-        throws IOException, ServletException
-    {
-        Handler[] handlers = getHandlers();
-        
-        if (handlers!=null && isStarted())
-        {
-            for (int i=0;i<handlers.length;i++)
-            {
-                handlers[i].handle(target,baseRequest, request, response);
-                if ( baseRequest.isHandled())
-                    return;
-            }
-        }
-    }
+	@Override
+	public void handle(String target, Request request, HttpServletResponse response) 
+		throws IOException, ServletException
+	{
+		Handler[] handlers = getHandlers();
+		
+		if (handlers!=null && isStarted())
+		{
+			for (int i=0;i<handlers.length;i++)
+			{
+				handlers[i].handle(target, request, response);
+				if ( request.isHandled())
+					return;
+			}
+		}
+	}
 }
--- a/src/org/eclipse/jetty/server/handler/HandlerWrapper.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/HandlerWrapper.java	Wed Oct 19 04:22:51 2016 -0600
@@ -21,7 +21,6 @@
 import java.io.IOException;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.server.Handler;
@@ -105,12 +104,12 @@
 		super.doStop();
 	}
 
-	/* ------------------------------------------------------------ */
-	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+	@Override
+	public void handle(String target, Request request, HttpServletResponse response) throws IOException, ServletException
 	{
 		if (_handler!=null && isStarted())
 		{
-			_handler.handle(target,baseRequest, request, response);
+			_handler.handle(target, request, response);
 		}
 	}
 
--- a/src/org/eclipse/jetty/server/handler/RequestLogHandler.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/RequestLogHandler.java	Wed Oct 19 04:22:51 2016 -0600
@@ -31,7 +31,6 @@
 
 import javax.servlet.ServletException;
 import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.http.HttpHeaders;
@@ -53,21 +52,17 @@
 {
 	private static final Logger LOG = LoggerFactory.getLogger(RequestLogHandler.class);
 	
-	/* ------------------------------------------------------------ */
-	/* 
-	 * @see org.eclipse.jetty.server.server.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
-	 */
 	@Override
-	public void handle(String target, final Request baseRequest, HttpServletRequest request, final HttpServletResponse response)
+	public void handle(String target, final Request request, final HttpServletResponse response)
 			throws IOException, ServletException
 	{
 		try
 		{
-			super.handle(target, baseRequest, request, response);
+			super.handle(target, request, response);
 		}
 		finally
 		{
-			log(baseRequest, (Response)response);
+			log(request, (Response)response);
 		}
 	}
 
--- a/src/org/eclipse/jetty/server/handler/ResourceHandler.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/ResourceHandler.java	Wed Oct 19 04:22:51 2016 -0600
@@ -23,7 +23,6 @@
 import java.net.MalformedURLException;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.http.HttpFields;
@@ -308,13 +307,10 @@
 		return null;
 	}
 
-	/* ------------------------------------------------------------ */
-	/*
-	 * @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
-	 */
-	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+	@Override
+	public void handle(String target, Request request, HttpServletResponse response) throws IOException, ServletException
 	{
-		if (baseRequest.isHandled())
+		if (request.isHandled())
 			return;
 
 		boolean skipContentBody = false;
@@ -324,13 +320,13 @@
 			if(!HttpMethods.HEAD.equals(request.getMethod()))
 			{
 				//try another handler
-				super.handle(target, baseRequest, request, response);
+				super.handle(target, request, response);
 				return;
 			}
 			skipContentBody = true;
 		}
 		
-		Resource resource = getResource(baseRequest);
+		Resource resource = getResource(request);
 		
 		if (resource==null || !resource.exists())
 		{
@@ -344,7 +340,7 @@
 			else 
 			{
 				//no resource - try other handlers
-				super.handle(target, baseRequest, request, response);
+				super.handle(target, request, response);
 				return;
 			}
 		}
@@ -356,7 +352,7 @@
 		}
 
 		// We are going to serve something
-		baseRequest.setHandled(true);
+		request.setHandled(true);
 
 		if (resource.isDirectory())
 		{
@@ -372,7 +368,7 @@
 			else
 			{
 				doDirectory(request,response,resource);
-				baseRequest.setHandled(true);
+				request.setHandled(true);
 				return;
 			}
 		}
@@ -418,7 +414,7 @@
 	}
 
 	/* ------------------------------------------------------------ */
-	protected void doDirectory(HttpServletRequest request,HttpServletResponse response, Resource resource)
+	protected void doDirectory(Request request,HttpServletResponse response, Resource resource)
 		throws IOException
 	{
 		if (_directory)
--- a/src/org/eclipse/jetty/server/handler/ShutdownHandler.java	Wed Oct 19 00:59:46 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/ShutdownHandler.java	Wed Oct 19 04:22:51 2016 -0600
@@ -21,7 +21,6 @@
 import java.io.IOException;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.server.Request;
@@ -39,132 +38,133 @@
  * Usage:
  *
  * <pre>
-    Server server = new Server(8080);
-    HandlerList handlers = new HandlerList();
-    handlers.setHandlers(new Handler[]
-    { someOtherHandler, new ShutdownHandler(server,&quot;secret password&quot;) });
-    server.setHandler(handlers);
-    server.start();
+	Server server = new Server(8080);
+	HandlerList handlers = new HandlerList();
+	handlers.setHandlers(new Handler[]
+	{ someOtherHandler, new ShutdownHandler(server,&quot;secret password&quot;) });
+	server.setHandler(handlers);
+	server.start();
    </pre>
  * 
    <pre>
    public static void attemptShutdown(int port, String shutdownCookie) {
-        try {
-            URL url = new URL("http://localhost:" + port + "/shutdown?token=" + shutdownCookie);
-            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
-            connection.setRequestMethod("POST");
-            connection.getResponseCode();
-            logger.info("Shutting down " + url + ": " + connection.getResponseMessage());
-        } catch (SocketException e) {
-            logger.debug("Not running");
-            // Okay - the server is not running
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-    }
+		try {
+			URL url = new URL("http://localhost:" + port + "/shutdown?token=" + shutdownCookie);
+			HttpURLConnection connection = (HttpURLConnection)url.openConnection();
+			connection.setRequestMethod("POST");
+			connection.getResponseCode();
+			logger.info("Shutting down " + url + ": " + connection.getResponseMessage());
+		} catch (SocketException e) {
+			logger.debug("Not running");
+			// Okay - the server is not running
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
   </pre>
  */
 public class ShutdownHandler extends AbstractHandler
 {
-    private static final Logger LOG = LoggerFactory.getLogger(ShutdownHandler.class);
+	private static final Logger LOG = LoggerFactory.getLogger(ShutdownHandler.class);
 
-    private final String _shutdownToken;
+	private final String _shutdownToken;
 
-    private final Server _server;
+	private final Server _server;
 
-    private boolean _exitJvm = false;
+	private boolean _exitJvm = false;
   
-    
+	
 
-    /**
-     * Creates a listener that lets the server be shut down remotely (but only from localhost).
-     *
-     * @param server
-     *            the Jetty instance that should be shut down
-     * @param shutdownToken
-     *            a secret password to avoid unauthorized shutdown attempts
-     */
-    public ShutdownHandler(Server server, String shutdownToken)
-    {
-        this._server = server;
-        this._shutdownToken = shutdownToken;
-    }
+	/**
+	 * Creates a listener that lets the server be shut down remotely (but only from localhost).
+	 *
+	 * @param server
+	 *            the Jetty instance that should be shut down
+	 * @param shutdownToken
+	 *            a secret password to avoid unauthorized shutdown attempts
+	 */
+	public ShutdownHandler(Server server, String shutdownToken)
+	{
+		this._server = server;
+		this._shutdownToken = shutdownToken;
+	}
 
-    public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
-    {
-        if (!target.equals("/shutdown"))
-        {
-            return;
-        }
+	@Override
+	public void handle(String target, Request request, HttpServletResponse response) throws IOException, ServletException
+	{
+		if (!target.equals("/shutdown"))
+		{
+			return;
+		}
 
-        if (!request.getMethod().equals("POST"))
-        {
-            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
-            return;
-        }
-        if (!hasCorrectSecurityToken(request))
-        {
-            LOG.warn("Unauthorized shutdown attempt from " + getRemoteAddr(request));
-            response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
-            return;
-        }
-        if (!requestFromLocalhost(request))
-        {
-            LOG.warn("Unauthorized shutdown attempt from " + getRemoteAddr(request));
-            response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
-            return;
-        }
+		if (!request.getMethod().equals("POST"))
+		{
+			response.sendError(HttpServletResponse.SC_BAD_REQUEST);
+			return;
+		}
+		if (!hasCorrectSecurityToken(request))
+		{
+			LOG.warn("Unauthorized shutdown attempt from " + getRemoteAddr(request));
+			response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+			return;
+		}
+		if (!requestFromLocalhost(request))
+		{
+			LOG.warn("Unauthorized shutdown attempt from " + getRemoteAddr(request));
+			response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+			return;
+		}
 
-        LOG.info("Shutting down by request from " + getRemoteAddr(request));
-        
-        new Thread()
-        {
-            public void run ()
-            {
-                try
-                {
-                    shutdownServer();
-                }
-                catch (InterruptedException e)
-                {
-                    LOG.trace("",e);
-                }
-                catch (Exception e)
-                {
-                    throw new RuntimeException("Shutting down server",e);
-                }
-            }
-        }.start();
-    }
+		LOG.info("Shutting down by request from " + getRemoteAddr(request));
+		
+		new Thread()
+		{
+			public void run ()
+			{
+				try
+				{
+					shutdownServer();
+				}
+				catch (InterruptedException e)
+				{
+					LOG.trace("",e);
+				}
+				catch (Exception e)
+				{
+					throw new RuntimeException("Shutting down server",e);
+				}
+			}
+		}.start();
+	}
 
-    private boolean requestFromLocalhost(HttpServletRequest request)
-    {
-        return "127.0.0.1".equals(getRemoteAddr(request));
-    }
+	private boolean requestFromLocalhost(Request request)
+	{
+		return "127.0.0.1".equals(getRemoteAddr(request));
+	}
 
-    protected String getRemoteAddr(HttpServletRequest request)
-    {
-        return request.getRemoteAddr();
-    }
+	protected String getRemoteAddr(Request request)
+	{
+		return request.getRemoteAddr();
+	}
 
-    private boolean hasCorrectSecurityToken(HttpServletRequest request)
-    {
-        return _shutdownToken.equals(request.getParameter("token"));
-    }
+	private boolean hasCorrectSecurityToken(Request request)
+	{
+		return _shutdownToken.equals(request.getParameter("token"));
+	}
 
-    private void shutdownServer() throws Exception
-    {
-        _server.stop();
-        
-        if (_exitJvm)
-        {
-            System.exit(0);
-        }
-    }
+	private void shutdownServer() throws Exception
+	{
+		_server.stop();
+		
+		if (_exitJvm)
+		{
+			System.exit(0);
+		}
+	}
 
-    public void setExitJvm(boolean exitJvm)
-    {
-        this._exitJvm = exitJvm;
-    }
+	public void setExitJvm(boolean exitJvm)
+	{
+		this._exitJvm = exitJvm;
+	}
 
 }