changeset 916:4de7f6e9c453

remove ContinuationSupport
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 09 Oct 2016 02:08:40 -0600
parents 65e0fba5861a
children 1fc8ee20cb18
files src/luan/modules/http/LuanHandler.java src/org/eclipse/jetty/continuation/ContinuationSupport.java src/org/eclipse/jetty/server/handler/GzipHandler.java
diffstat 3 files changed, 253 insertions(+), 331 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/http/LuanHandler.java	Sun Oct 09 01:52:29 2016 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Sun Oct 09 02:08:40 2016 -0600
@@ -10,7 +10,6 @@
 import org.slf4j.LoggerFactory;
 import org.eclipse.jetty.server.Request;
 import org.eclipse.jetty.server.handler.AbstractHandler;
-import org.eclipse.jetty.continuation.ContinuationSupport;
 import luan.Luan;
 import luan.LuanState;
 import luan.LuanTable;
@@ -54,7 +53,6 @@
 		throws IOException
 	{
 //Thread.dumpStack();
-//System.out.println("getContinuation = "+ContinuationSupport.getContinuation(request));
 		if( target.endsWith("/") )
 			target += welcomeFile;
 		Thread thread = Thread.currentThread();
--- a/src/org/eclipse/jetty/continuation/ContinuationSupport.java	Sun Oct 09 01:52:29 2016 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-//
-//  ========================================================================
-//  Copyright (c) 1995-2014 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.continuation;
-
-import java.lang.reflect.Constructor;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletRequestWrapper;
-import javax.servlet.ServletResponse;
-
-/* ------------------------------------------------------------ */
-/** ContinuationSupport.
- *
- * Factory class for accessing Continuation instances, which with either be
- * native to the container (jetty >= 6), a servlet 3.0 or a faux continuation.
- *
- */
-public class ContinuationSupport
-{
-	/* ------------------------------------------------------------ */
-	/**
-	 * Get a Continuation.  The type of the Continuation returned may
-	 * vary depending on the container in which the application is
-	 * deployed. It may be an implementation native to the container (eg
-	 * org.eclipse.jetty.server.AsyncContinuation) or one of the utility
-	 * implementations provided such as an internal <code>FauxContinuation</code>
-	 * or a real implementation like {@link org.eclipse.jetty.continuation.Servlet3Continuation}.
-	 * @param request The request
-	 * @return a Continuation instance
-	 */
-	public static Continuation getContinuation(ServletRequest request)
-	{
-		Continuation continuation = (Continuation) request.getAttribute(Continuation.ATTRIBUTE);
-		if (continuation!=null)
-			return continuation;
-
-		throw new IllegalStateException("!(Jetty || Servlet 3.0 || ContinuationFilter)");
-	}
-}
--- a/src/org/eclipse/jetty/server/handler/GzipHandler.java	Sun Oct 09 01:52:29 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/GzipHandler.java	Sun Oct 09 02:08:40 2016 -0600
@@ -35,7 +35,6 @@
 
 import org.eclipse.jetty.continuation.Continuation;
 import org.eclipse.jetty.continuation.ContinuationListener;
-import org.eclipse.jetty.continuation.ContinuationSupport;
 import org.eclipse.jetty.http.HttpMethods;
 import org.eclipse.jetty.http.gzip.CompressedResponseWrapper;
 import org.eclipse.jetty.http.gzip.AbstractCompressedStream;
@@ -62,295 +61,274 @@
  */
 public class GzipHandler extends HandlerWrapper
 {
-    private static final Logger LOG = LoggerFactory.getLogger(GzipHandler.class);
+	private static final Logger LOG = LoggerFactory.getLogger(GzipHandler.class);
 
-    protected Set<String> _mimeTypes;
-    protected Set<String> _excluded;
-    protected int _bufferSize = 8192;
-    protected int _minGzipSize = 256;
-    protected String _vary = "Accept-Encoding, User-Agent";
+	protected Set<String> _mimeTypes;
+	protected Set<String> _excluded;
+	protected int _bufferSize = 8192;
+	protected int _minGzipSize = 256;
+	protected String _vary = "Accept-Encoding, User-Agent";
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Instantiates a new gzip handler.
-     */
-    public GzipHandler()
-    {
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Instantiates a new gzip handler.
+	 */
+	public GzipHandler()
+	{
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Get the mime types.
-     * 
-     * @return mime types to set
-     */
-    public Set<String> getMimeTypes()
-    {
-        return _mimeTypes;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Get the mime types.
+	 * 
+	 * @return mime types to set
+	 */
+	public Set<String> getMimeTypes()
+	{
+		return _mimeTypes;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Set the mime types.
-     * 
-     * @param mimeTypes
-     *            the mime types to set
-     */
-    public void setMimeTypes(Set<String> mimeTypes)
-    {
-        _mimeTypes = mimeTypes;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Set the mime types.
+	 * 
+	 * @param mimeTypes
+	 *            the mime types to set
+	 */
+	public void setMimeTypes(Set<String> mimeTypes)
+	{
+		_mimeTypes = mimeTypes;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Set the mime types.
-     * 
-     * @param mimeTypes
-     *            the mime types to set
-     */
-    public void setMimeTypes(String mimeTypes)
-    {
-        if (mimeTypes != null)
-        {
-            _mimeTypes = new HashSet<String>();
-            StringTokenizer tok = new StringTokenizer(mimeTypes,",",false);
-            while (tok.hasMoreTokens())
-            {
-                _mimeTypes.add(tok.nextToken());
-            }
-        }
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Set the mime types.
+	 * 
+	 * @param mimeTypes
+	 *            the mime types to set
+	 */
+	public void setMimeTypes(String mimeTypes)
+	{
+		if (mimeTypes != null)
+		{
+			_mimeTypes = new HashSet<String>();
+			StringTokenizer tok = new StringTokenizer(mimeTypes,",",false);
+			while (tok.hasMoreTokens())
+			{
+				_mimeTypes.add(tok.nextToken());
+			}
+		}
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Get the excluded user agents.
-     * 
-     * @return excluded user agents
-     */
-    public Set<String> getExcluded()
-    {
-        return _excluded;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Get the excluded user agents.
+	 * 
+	 * @return excluded user agents
+	 */
+	public Set<String> getExcluded()
+	{
+		return _excluded;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Set the excluded user agents.
-     * 
-     * @param excluded
-     *            excluded user agents to set
-     */
-    public void setExcluded(Set<String> excluded)
-    {
-        _excluded = excluded;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Set the excluded user agents.
+	 * 
+	 * @param excluded
+	 *            excluded user agents to set
+	 */
+	public void setExcluded(Set<String> excluded)
+	{
+		_excluded = excluded;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Set the excluded user agents.
-     * 
-     * @param excluded
-     *            excluded user agents to set
-     */
-    public void setExcluded(String excluded)
-    {
-        if (excluded != null)
-        {
-            _excluded = new HashSet<String>();
-            StringTokenizer tok = new StringTokenizer(excluded,",",false);
-            while (tok.hasMoreTokens())
-                _excluded.add(tok.nextToken());
-        }
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Set the excluded user agents.
+	 * 
+	 * @param excluded
+	 *            excluded user agents to set
+	 */
+	public void setExcluded(String excluded)
+	{
+		if (excluded != null)
+		{
+			_excluded = new HashSet<String>();
+			StringTokenizer tok = new StringTokenizer(excluded,",",false);
+			while (tok.hasMoreTokens())
+				_excluded.add(tok.nextToken());
+		}
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @return The value of the Vary header set if a response can be compressed.
-     */
-    public String getVary()
-    {
-        return _vary;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return The value of the Vary header set if a response can be compressed.
+	 */
+	public String getVary()
+	{
+		return _vary;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Set the value of the Vary header sent with responses that could be compressed.  
-     * <p>
-     * By default it is set to 'Accept-Encoding, User-Agent' since IE6 is excluded by 
-     * default from the excludedAgents. If user-agents are not to be excluded, then 
-     * this can be set to 'Accept-Encoding'.  Note also that shared caches may cache 
-     * many copies of a resource that is varied by User-Agent - one per variation of the 
-     * User-Agent, unless the cache does some normalization of the UA string.
-     * @param vary The value of the Vary header set if a response can be compressed.
-     */
-    public void setVary(String vary)
-    {
-        _vary = vary;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Set the value of the Vary header sent with responses that could be compressed.  
+	 * <p>
+	 * By default it is set to 'Accept-Encoding, User-Agent' since IE6 is excluded by 
+	 * default from the excludedAgents. If user-agents are not to be excluded, then 
+	 * this can be set to 'Accept-Encoding'.  Note also that shared caches may cache 
+	 * many copies of a resource that is varied by User-Agent - one per variation of the 
+	 * User-Agent, unless the cache does some normalization of the UA string.
+	 * @param vary The value of the Vary header set if a response can be compressed.
+	 */
+	public void setVary(String vary)
+	{
+		_vary = vary;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Get the buffer size.
-     * 
-     * @return the buffer size
-     */
-    public int getBufferSize()
-    {
-        return _bufferSize;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Get the buffer size.
+	 * 
+	 * @return the buffer size
+	 */
+	public int getBufferSize()
+	{
+		return _bufferSize;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Set the buffer size.
-     * 
-     * @param bufferSize
-     *            buffer size to set
-     */
-    public void setBufferSize(int bufferSize)
-    {
-        _bufferSize = bufferSize;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Set the buffer size.
+	 * 
+	 * @param bufferSize
+	 *            buffer size to set
+	 */
+	public void setBufferSize(int bufferSize)
+	{
+		_bufferSize = bufferSize;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Get the minimum reponse size.
-     * 
-     * @return minimum reponse size
-     */
-    public int getMinGzipSize()
-    {
-        return _minGzipSize;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Get the minimum reponse size.
+	 * 
+	 * @return minimum reponse size
+	 */
+	public int getMinGzipSize()
+	{
+		return _minGzipSize;
+	}
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Set the minimum reponse size.
-     * 
-     * @param minGzipSize
-     *            minimum reponse size
-     */
-    public void setMinGzipSize(int minGzipSize)
-    {
-        _minGzipSize = minGzipSize;
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * Set the minimum reponse size.
+	 * 
+	 * @param minGzipSize
+	 *            minimum reponse size
+	 */
+	public void setMinGzipSize(int minGzipSize)
+	{
+		_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
-    {
-        if (_handler!=null && isStarted())
-        {
-            String ae = request.getHeader("accept-encoding");
-            if (ae != null && ae.indexOf("gzip")>=0 && !response.containsHeader("Content-Encoding")
-                    && !HttpMethods.HEAD.equalsIgnoreCase(request.getMethod()))
-            {
-                if (_excluded!=null)
-                {
-                    String ua = request.getHeader("User-Agent");
-                    if (_excluded.contains(ua))
-                    {
-                        _handler.handle(target,baseRequest, request, response);
-                        return;
-                    }
-                }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @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
+	{
+		if (_handler!=null && isStarted())
+		{
+			String ae = request.getHeader("accept-encoding");
+			if (ae != null && ae.indexOf("gzip")>=0 && !response.containsHeader("Content-Encoding")
+					&& !HttpMethods.HEAD.equalsIgnoreCase(request.getMethod()))
+			{
+				if (_excluded!=null)
+				{
+					String ua = request.getHeader("User-Agent");
+					if (_excluded.contains(ua))
+					{
+						_handler.handle(target,baseRequest, request, response);
+						return;
+					}
+				}
 
-                final CompressedResponseWrapper wrappedResponse = newGzipResponseWrapper(request,response);
-                
-                boolean exceptional=true;
-                try
-                {
-                    _handler.handle(target, baseRequest, request, wrappedResponse);
-                    exceptional=false;
-                }
-                finally
-                {
-                    Continuation continuation = ContinuationSupport.getContinuation(request);
-                    if (continuation.isSuspended() && continuation.isResponseWrapped())   
-                    {
-                        continuation.addContinuationListener(new ContinuationListener()
-                        {
-                            public void onComplete(Continuation continuation)
-                            {
-                                try
-                                {
-                                    wrappedResponse.finish();
-                                }
-                                catch(IOException e)
-                                {
-                                    LOG.warn("",e);
-                                }
-                            }
-
-                            public void onTimeout(Continuation continuation)
-                            {}
-                        });
-                    }
-                    else if (exceptional && !response.isCommitted())
-                    {
-                        wrappedResponse.resetBuffer();
-                        wrappedResponse.noCompression();
-                    }
-                    else
-                        wrappedResponse.finish();
-                }
-            }
-            else
-            {
-                _handler.handle(target,baseRequest, request, response);
-            }
-        }
-    }
+				final CompressedResponseWrapper wrappedResponse = newGzipResponseWrapper(request,response);
+				
+				boolean exceptional=true;
+				try
+				{
+					_handler.handle(target, baseRequest, request, wrappedResponse);
+					exceptional=false;
+				}
+				finally
+				{
+					if (exceptional && !response.isCommitted())
+					{
+						wrappedResponse.resetBuffer();
+						wrappedResponse.noCompression();
+					}
+					else
+						wrappedResponse.finish();
+				}
+			}
+			else
+			{
+				_handler.handle(target,baseRequest, request, response);
+			}
+		}
+	}
 
-    /**
-     * Allows derived implementations to replace ResponseWrapper implementation.
-     *
-     * @param request the request
-     * @param response the response
-     * @return the gzip response wrapper
-     */
-    protected CompressedResponseWrapper newGzipResponseWrapper(HttpServletRequest request, HttpServletResponse response)
-    {
-        return new CompressedResponseWrapper(request,response)
-        {
-            {
-                super.setMimeTypes(GzipHandler.this._mimeTypes);
-                super.setBufferSize(GzipHandler.this._bufferSize);
-                super.setMinCompressSize(GzipHandler.this._minGzipSize);
-            }
-            
-            @Override
-            protected AbstractCompressedStream newCompressedStream(HttpServletRequest request,HttpServletResponse response) throws IOException
-            {
-                return new AbstractCompressedStream("gzip",request,this,_vary)
-                {
-                    @Override
-                    protected DeflaterOutputStream createStream() throws IOException
-                    {
-                        return new GZIPOutputStream(_response.getOutputStream(),_bufferSize);
-                    }
-                };
-            }
-            
-            @Override
-            protected PrintWriter newWriter(OutputStream out,String encoding) throws UnsupportedEncodingException
-            {
-                return GzipHandler.this.newWriter(out,encoding);
-            }
-        };
-    }
-    
-    /**
-     * Allows derived implementations to replace PrintWriter implementation.
-     *
-     * @param out the out
-     * @param encoding the encoding
-     * @return the prints the writer
-     * @throws UnsupportedEncodingException
-     */
-    protected PrintWriter newWriter(OutputStream out,String encoding) throws UnsupportedEncodingException
-    {
-        return encoding==null?new PrintWriter(out):new PrintWriter(new OutputStreamWriter(out,encoding));
-    }
+	/**
+	 * Allows derived implementations to replace ResponseWrapper implementation.
+	 *
+	 * @param request the request
+	 * @param response the response
+	 * @return the gzip response wrapper
+	 */
+	protected CompressedResponseWrapper newGzipResponseWrapper(HttpServletRequest request, HttpServletResponse response)
+	{
+		return new CompressedResponseWrapper(request,response)
+		{
+			{
+				super.setMimeTypes(GzipHandler.this._mimeTypes);
+				super.setBufferSize(GzipHandler.this._bufferSize);
+				super.setMinCompressSize(GzipHandler.this._minGzipSize);
+			}
+			
+			@Override
+			protected AbstractCompressedStream newCompressedStream(HttpServletRequest request,HttpServletResponse response) throws IOException
+			{
+				return new AbstractCompressedStream("gzip",request,this,_vary)
+				{
+					@Override
+					protected DeflaterOutputStream createStream() throws IOException
+					{
+						return new GZIPOutputStream(_response.getOutputStream(),_bufferSize);
+					}
+				};
+			}
+			
+			@Override
+			protected PrintWriter newWriter(OutputStream out,String encoding) throws UnsupportedEncodingException
+			{
+				return GzipHandler.this.newWriter(out,encoding);
+			}
+		};
+	}
+	
+	/**
+	 * Allows derived implementations to replace PrintWriter implementation.
+	 *
+	 * @param out the out
+	 * @param encoding the encoding
+	 * @return the prints the writer
+	 * @throws UnsupportedEncodingException
+	 */
+	protected PrintWriter newWriter(OutputStream out,String encoding) throws UnsupportedEncodingException
+	{
+		return encoding==null?new PrintWriter(out):new PrintWriter(new OutputStreamWriter(out,encoding));
+	}
 }