Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Bartel2012-09-06 06:25:24 +0000
committerJan Bartel2012-09-06 06:25:24 +0000
commit29b4418876778868cf69cba6722bbe53d0308361 (patch)
tree47d88f3a8c904e5078e9c7c1ebf5197f233bc98e /jetty-server/src/main/java
parent605df3657725ae2b04cdec50af58b02d17d61c73 (diff)
parent358e5b5bfd8f97032c0aa0eed99dbfc0c42ec0a8 (diff)
downloadorg.eclipse.jetty.project-29b4418876778868cf69cba6722bbe53d0308361.tar.gz
org.eclipse.jetty.project-29b4418876778868cf69cba6722bbe53d0308361.tar.xz
org.eclipse.jetty.project-29b4418876778868cf69cba6722bbe53d0308361.zip
Merge branch 'jetty-9' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project into jetty-9
Diffstat (limited to 'jetty-server/src/main/java')
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java4
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/Server.java16
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/gzip/AbstractCompressedStream.java348
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/gzip/CompressedResponseWrapper.java415
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java6
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/GzipHandler.java330
6 files changed, 17 insertions, 1102 deletions
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java
index 9d2fb53001..d02ac4950e 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java
@@ -58,12 +58,12 @@ public class SelectChannelConnector extends AbstractNetworkConnector
private volatile boolean _reuseAddress = true;
private volatile int _lingerTime = -1;
- public SelectChannelConnector(Server server)
+ public SelectChannelConnector(@Name("server") Server server)
{
this(server, null);
}
- public SelectChannelConnector(Server server, SslContextFactory sslContextFactory)
+ public SelectChannelConnector(@Name("server")Server server, @Name("sslContextFactory") SslContextFactory sslContextFactory)
{
this(server, null, null, null, sslContextFactory, 0, 0);
}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
index 5084ff7203..95e9f451d9 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
@@ -47,6 +47,7 @@ import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
+import org.eclipse.jetty.util.annotation.Name;
import org.eclipse.jetty.util.component.Container;
import org.eclipse.jetty.util.component.Destroyable;
import org.eclipse.jetty.util.component.Graceful;
@@ -80,7 +81,7 @@ public class Server extends HandlerWrapper implements Attributes
__version=System.getProperty("jetty.version","9.x.y.z-SNAPSHOT");
}
- private final Container _container=new Container();
+ private final Container _container;
private final AttributesMap _attributes = new AttributesMap();
private final ThreadPool _threadPool;
private final List<Connector> _connectors = new CopyOnWriteArrayList<>();
@@ -102,7 +103,7 @@ public class Server extends HandlerWrapper implements Attributes
/** Convenience constructor
* Creates server and a {@link SelectChannelConnector} at the passed port.
*/
- public Server(int port)
+ public Server(@Name("port")int port)
{
this((ThreadPool)null);
SelectChannelConnector connector=new SelectChannelConnector(this);
@@ -114,7 +115,7 @@ public class Server extends HandlerWrapper implements Attributes
/** Convenience constructor
* Creates server and a {@link SelectChannelConnector} at the passed address.
*/
- public Server(InetSocketAddress addr)
+ public Server(@Name("address")InetSocketAddress addr)
{
this((ThreadPool)null);
SelectChannelConnector connector=new SelectChannelConnector(this);
@@ -125,9 +126,16 @@ public class Server extends HandlerWrapper implements Attributes
/* ------------------------------------------------------------ */
- public Server(ThreadPool pool)
+ public Server(@Name("threadpool") ThreadPool pool)
+ {
+ this(pool,null);
+ }
+
+ /* ------------------------------------------------------------ */
+ public Server(@Name("threadpool") ThreadPool pool,@Name("container") Container container)
{
_threadPool=pool!=null?pool:new QueuedThreadPool();
+ _container=container!=null?container:new Container();
addBean(_threadPool);
setServer(this);
}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/gzip/AbstractCompressedStream.java b/jetty-server/src/main/java/org/eclipse/jetty/server/gzip/AbstractCompressedStream.java
deleted file mode 100644
index 5045415e14..0000000000
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/gzip/AbstractCompressedStream.java
+++ /dev/null
@@ -1,348 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.server.gzip;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.zip.DeflaterOutputStream;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.jetty.util.ByteArrayOutputStream2;
-
-/* ------------------------------------------------------------ */
-/**
- * Skeletal implementation of a CompressedStream. This class adds compression features to a ServletOutputStream and takes care of setting response headers, etc.
- * Major work and configuration is done here. Subclasses using different kinds of compression only have to implement the abstract methods doCompress() and
- * setContentEncoding() using the desired compression and setting the appropriate Content-Encoding header string.
- */
-public abstract class AbstractCompressedStream extends ServletOutputStream
-{
- private final String _encoding;
- protected HttpServletRequest _request;
- protected HttpServletResponse _response;
- protected OutputStream _out;
- protected ByteArrayOutputStream2 _bOut;
- protected DeflaterOutputStream _compressedOutputStream;
- protected boolean _closed;
- protected int _bufferSize;
- protected int _minCompressSize;
- protected long _contentLength;
- protected boolean _doNotCompress;
-
- /**
- * Instantiates a new compressed stream.
- *
- * @param request
- * the request
- * @param response
- * the response
- * @param contentLength
- * the content length
- * @param bufferSize
- * the buffer size
- * @param minCompressSize
- * the min compress size
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- public AbstractCompressedStream(String encoding,HttpServletRequest request, HttpServletResponse response, long contentLength, int bufferSize, int minCompressSize)
- throws IOException
- {
- _encoding=encoding;
- _request = request;
- _response = response;
- _contentLength = contentLength;
- _bufferSize = bufferSize;
- _minCompressSize = minCompressSize;
- if (minCompressSize == 0)
- doCompress();
- }
-
- /**
- * Reset buffer.
- */
- public void resetBuffer()
- {
- if (_response.isCommitted())
- throw new IllegalStateException("Committed");
- _closed = false;
- _out = null;
- _bOut = null;
- if (_compressedOutputStream != null)
- _response.setHeader("Content-Encoding",null);
- _compressedOutputStream = null;
- _doNotCompress = false;
- }
-
- /**
- * Sets the content length.
- *
- * @param length
- * the new content length
- */
- public void setContentLength(long length)
- {
- _contentLength = length;
- if (_doNotCompress && length >= 0)
- {
- if (_contentLength < Integer.MAX_VALUE)
- _response.setContentLength((int)_contentLength);
- else
- _response.setHeader("Content-Length",Long.toString(_contentLength));
- }
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see java.io.OutputStream#flush()
- */
- @Override
- public void flush() throws IOException
- {
- if (_out == null || _bOut != null)
- {
- if (_contentLength > 0 && _contentLength < _minCompressSize)
- doNotCompress();
- else
- doCompress();
- }
-
- _out.flush();
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see java.io.OutputStream#close()
- */
- @Override
- public void close() throws IOException
- {
- if (_closed)
- return;
-
- if (_request.getAttribute("javax.servlet.include.request_uri") != null)
- flush();
- else
- {
- if (_bOut != null)
- {
- if (_contentLength < 0)
- _contentLength = _bOut.getCount();
- if (_contentLength < _minCompressSize)
- doNotCompress();
- else
- doCompress();
- }
- else if (_out == null)
- {
- doNotCompress();
- }
-
- if (_compressedOutputStream != null)
- _compressedOutputStream.close();
- else
- _out.close();
- _closed = true;
- }
- }
-
- /**
- * Finish.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- public void finish() throws IOException
- {
- if (!_closed)
- {
- if (_out == null || _bOut != null)
- {
- if (_contentLength > 0 && _contentLength < _minCompressSize)
- doNotCompress();
- else
- doCompress();
- }
-
- if (_compressedOutputStream != null && !_closed)
- {
- _closed = true;
- _compressedOutputStream.close();
- }
- }
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see java.io.OutputStream#write(int)
- */
- @Override
- public void write(int b) throws IOException
- {
- checkOut(1);
- _out.write(b);
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see java.io.OutputStream#write(byte[])
- */
- @Override
- public void write(byte b[]) throws IOException
- {
- checkOut(b.length);
- _out.write(b);
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see java.io.OutputStream#write(byte[], int, int)
- */
- @Override
- public void write(byte b[], int off, int len) throws IOException
- {
- checkOut(len);
- _out.write(b,off,len);
- }
-
- /**
- * Do compress.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- */
- public void doCompress() throws IOException
- {
- if (_compressedOutputStream==null)
- {
- if (_response.isCommitted())
- throw new IllegalStateException();
-
- setHeader("Content-Encoding", _encoding);
- if (_response.containsHeader("Content-Encoding"))
- {
- _out=_compressedOutputStream=createStream();
-
- if (_bOut!=null)
- {
- _out.write(_bOut.getBuf(),0,_bOut.getCount());
- _bOut=null;
- }
- }
- else
- doNotCompress();
- }
- }
-
- /**
- * Do not compress.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- public void doNotCompress() throws IOException
- {
- if (_compressedOutputStream != null)
- throw new IllegalStateException("Compressed output stream is already assigned.");
- if (_out == null || _bOut != null)
- {
- _doNotCompress = true;
-
- _out = _response.getOutputStream();
- setContentLength(_contentLength);
-
- if (_bOut != null)
- _out.write(_bOut.getBuf(),0,_bOut.getCount());
- _bOut = null;
- }
- }
-
- /**
- * Check out.
- *
- * @param length
- * the length
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- private void checkOut(int length) throws IOException
- {
- if (_closed)
- throw new IOException("CLOSED");
-
- if (_out == null)
- {
- if (_response.isCommitted() || (_contentLength >= 0 && _contentLength < _minCompressSize))
- doNotCompress();
- else if (length > _minCompressSize)
- doCompress();
- else
- _out = _bOut = new ByteArrayOutputStream2(_bufferSize);
- }
- else if (_bOut != null)
- {
- if (_response.isCommitted() || (_contentLength >= 0 && _contentLength < _minCompressSize))
- doNotCompress();
- else if (length >= (_bOut.getBuf().length - _bOut.getCount()))
- doCompress();
- }
- }
-
- /**
- * @see org.eclipse.jetty.http.gzip.CompressedStream#getOutputStream()
- */
- public OutputStream getOutputStream()
- {
- return _out;
- }
-
- /**
- * @see org.eclipse.jetty.http.gzip.CompressedStream#isClosed()
- */
- public boolean isClosed()
- {
- return _closed;
- }
-
- /**
- * Allows derived implementations to replace PrintWriter implementation.
- */
- protected PrintWriter newWriter(OutputStream out, String encoding) throws UnsupportedEncodingException
- {
- return encoding == null?new PrintWriter(out):new PrintWriter(new OutputStreamWriter(out,encoding));
- }
-
- protected void setHeader(String name,String value)
- {
- _response.setHeader(name, value);
- }
-
- /**
- * Create the stream fitting to the underlying compression type.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- protected abstract DeflaterOutputStream createStream() throws IOException;
-
-}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/gzip/CompressedResponseWrapper.java b/jetty-server/src/main/java/org/eclipse/jetty/server/gzip/CompressedResponseWrapper.java
deleted file mode 100644
index 22bd100761..0000000000
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/gzip/CompressedResponseWrapper.java
+++ /dev/null
@@ -1,415 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.server.gzip;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.Set;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpServletResponseWrapper;
-
-import org.eclipse.jetty.util.StringUtil;
-
-/*------------------------------------------------------------ */
-/**
- */
-public abstract class CompressedResponseWrapper extends HttpServletResponseWrapper
-{
-
- public static final int DEFAULT_BUFFER_SIZE = 8192;
- public static final int DEFAULT_MIN_COMPRESS_SIZE = 256;
-
- private Set<String> _mimeTypes;
- private int _bufferSize=DEFAULT_BUFFER_SIZE;
- private int _minCompressSize=DEFAULT_MIN_COMPRESS_SIZE;
- protected HttpServletRequest _request;
-
- private PrintWriter _writer;
- private AbstractCompressedStream _compressedStream;
- private long _contentLength=-1;
- private boolean _noCompression;
-
- public CompressedResponseWrapper(HttpServletRequest request, HttpServletResponse response)
- {
- super(response);
- _request = request;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#setMimeTypes(java.util.Set)
- */
- public void setMimeTypes(Set<String> mimeTypes)
- {
- _mimeTypes = mimeTypes;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#setBufferSize(int)
- */
- @Override
- public void setBufferSize(int bufferSize)
- {
- _bufferSize = bufferSize;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#setMinCompressSize(int)
- */
- public void setMinCompressSize(int minCompressSize)
- {
- _minCompressSize = minCompressSize;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#setContentType(java.lang.String)
- */
- @Override
- public void setContentType(String ct)
- {
- super.setContentType(ct);
-
- if (ct!=null)
- {
- int colon=ct.indexOf(";");
- if (colon>0)
- ct=ct.substring(0,colon);
- }
-
- if ((_compressedStream==null || _compressedStream.getOutputStream()==null) &&
- (_mimeTypes==null && ct!=null && ct.contains("gzip") ||
- _mimeTypes!=null && (ct==null||!_mimeTypes.contains(StringUtil.asciiToLowerCase(ct)))))
- {
- noCompression();
- }
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#setStatus(int, java.lang.String)
- */
- @Override
- public void setStatus(int sc, String sm)
- {
- super.setStatus(sc,sm);
- if (sc<200 || sc==204 || sc==205 || sc>=300)
- noCompression();
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#setStatus(int)
- */
- @Override
- public void setStatus(int sc)
- {
- super.setStatus(sc);
- if (sc<200 || sc==204 || sc==205 || sc>=300)
- noCompression();
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#setContentLength(int)
- */
- @Override
- public void setContentLength(int length)
- {
- setContentLength((long)length);
- }
-
- /* ------------------------------------------------------------ */
- protected void setContentLength(long length)
- {
- _contentLength=length;
- if (_compressedStream!=null)
- _compressedStream.setContentLength(length);
- else if (_noCompression && _contentLength>=0)
- {
- HttpServletResponse response = (HttpServletResponse)getResponse();
- if(_contentLength<Integer.MAX_VALUE)
- {
- response.setContentLength((int)_contentLength);
- }
- else
- {
- response.setHeader("Content-Length", Long.toString(_contentLength));
- }
- }
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#addHeader(java.lang.String, java.lang.String)
- */
- @Override
- public void addHeader(String name, String value)
- {
- if ("content-length".equalsIgnoreCase(name))
- {
- _contentLength=Long.parseLong(value);
- if (_compressedStream!=null)
- _compressedStream.setContentLength(_contentLength);
- }
- else if ("content-type".equalsIgnoreCase(name))
- {
- setContentType(value);
- }
- else if ("content-encoding".equalsIgnoreCase(name))
- {
- super.addHeader(name,value);
- if (!isCommitted())
- {
- noCompression();
- }
- }
- else
- super.addHeader(name,value);
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#flushBuffer()
- */
- @Override
- public void flushBuffer() throws IOException
- {
- if (_writer!=null)
- _writer.flush();
- if (_compressedStream!=null)
- _compressedStream.finish();
- else
- getResponse().flushBuffer();
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#reset()
- */
- @Override
- public void reset()
- {
- super.reset();
- if (_compressedStream!=null)
- _compressedStream.resetBuffer();
- _writer=null;
- _compressedStream=null;
- _noCompression=false;
- _contentLength=-1;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#resetBuffer()
- */
- @Override
- public void resetBuffer()
- {
- super.resetBuffer();
- if (_compressedStream!=null)
- _compressedStream.resetBuffer();
- _writer=null;
- _compressedStream=null;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#sendError(int, java.lang.String)
- */
- @Override
- public void sendError(int sc, String msg) throws IOException
- {
- resetBuffer();
- super.sendError(sc,msg);
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#sendError(int)
- */
- @Override
- public void sendError(int sc) throws IOException
- {
- resetBuffer();
- super.sendError(sc);
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#sendRedirect(java.lang.String)
- */
- @Override
- public void sendRedirect(String location) throws IOException
- {
- resetBuffer();
- super.sendRedirect(location);
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#noCompression()
- */
- public void noCompression()
- {
- _noCompression=true;
- if (_compressedStream!=null)
- {
- try
- {
- _compressedStream.doNotCompress();
- }
- catch (IOException e)
- {
- throw new IllegalStateException(e);
- }
- }
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#finish()
- */
- public void finish() throws IOException
- {
- if (_writer!=null && !_compressedStream.isClosed())
- _writer.flush();
- if (_compressedStream!=null)
- _compressedStream.finish();
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#setHeader(java.lang.String, java.lang.String)
- */
- @Override
- public void setHeader(String name, String value)
- {
- if ("content-length".equalsIgnoreCase(name))
- {
- setContentLength(Long.parseLong(value));
- }
- else if ("content-type".equalsIgnoreCase(name))
- {
- setContentType(value);
- }
- else if ("content-encoding".equalsIgnoreCase(name))
- {
- super.setHeader(name,value);
- if (!isCommitted())
- {
- noCompression();
- }
- }
- else
- super.setHeader(name,value);
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#getOutputStream()
- */
- @Override
- public ServletOutputStream getOutputStream() throws IOException
- {
- if (_compressedStream==null)
- {
- if (getResponse().isCommitted() || _noCompression)
- {
- setContentLength(_contentLength);
- return getResponse().getOutputStream();
- }
-
- _compressedStream=newCompressedStream(_request,(HttpServletResponse)getResponse(),_contentLength,_bufferSize,_minCompressSize);
- }
- else if (_writer!=null)
- throw new IllegalStateException("getWriter() called");
-
- return _compressedStream;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#getWriter()
- */
- @Override
- public PrintWriter getWriter() throws IOException
- {
- if (_writer==null)
- {
- if (_compressedStream!=null)
- throw new IllegalStateException("getOutputStream() called");
-
- if (getResponse().isCommitted() || _noCompression)
- {
- setContentLength(_contentLength);
- return getResponse().getWriter();
- }
-
- _compressedStream=newCompressedStream(_request,(HttpServletResponse)getResponse(),_contentLength,_bufferSize,_minCompressSize);
- _writer=newWriter(_compressedStream,getCharacterEncoding());
- }
- return _writer;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @see org.eclipse.jetty.server.gzip.CompressedResponseWrapper#setIntHeader(java.lang.String, int)
- */
- @Override
- public void setIntHeader(String name, int value)
- {
- if ("content-length".equalsIgnoreCase(name))
- {
- _contentLength=value;
- if (_compressedStream!=null)
- _compressedStream.setContentLength(_contentLength);
- }
- else
- super.setIntHeader(name,value);
- }
-
- /* ------------------------------------------------------------ */
- /**
- * Allows derived implementations to replace PrintWriter implementation.
- *
- * @param out the out
- * @param encoding the encoding
- * @return the prints the writer
- * @throws UnsupportedEncodingException the unsupported encoding exception
- */
- protected PrintWriter newWriter(OutputStream out,String encoding) throws UnsupportedEncodingException
- {
- return encoding==null?new PrintWriter(out):new PrintWriter(new OutputStreamWriter(out,encoding));
- }
-
- /* ------------------------------------------------------------ */
- /**
- *@return the underlying CompressedStream implementation
- */
- protected abstract AbstractCompressedStream newCompressedStream(HttpServletRequest _request, HttpServletResponse response, long _contentLength2, int _bufferSize2, int _minCompressedSize2) throws IOException;
-
-}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
index d6346dcfde..1e2a6be5df 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
@@ -167,7 +167,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
private Map<String, Object> _managedAttributes;
private String[] _protectedTargets;
- public enum Availability { AVAILABLE,SHUTDOWN,UNAVAILABLE};
+ public enum Availability { UNAVAILABLE,STARTING,AVAILABLE,SHUTDOWN,};
private volatile Availability _availability;
/* ------------------------------------------------------------ */
@@ -666,7 +666,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
@Override
protected void doStart() throws Exception
{
- _availability = Availability.UNAVAILABLE;
+ _availability = Availability.STARTING;
if (_contextPath == null)
throw new IllegalStateException("Null contextPath");
@@ -696,6 +696,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
startContext();
_availability = Availability.AVAILABLE;
+ LOG.info("started {}",this);
}
finally
{
@@ -756,7 +757,6 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
public void callContextInitialized (ServletContextListener l, ServletContextEvent e)
{
l.contextInitialized(e);
- LOG.info("started {}",this);
}
/* ------------------------------------------------------------ */
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/GzipHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/GzipHandler.java
deleted file mode 100644
index 77b63474ee..0000000000
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/GzipHandler.java
+++ /dev/null
@@ -1,330 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.server.handler;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.GZIPOutputStream;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.jetty.continuation.Continuation;
-import org.eclipse.jetty.continuation.ContinuationListener;
-import org.eclipse.jetty.continuation.ContinuationSupport;
-import org.eclipse.jetty.http.HttpMethod;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.server.gzip.AbstractCompressedStream;
-import org.eclipse.jetty.server.gzip.CompressedResponseWrapper;
-import org.eclipse.jetty.util.log.Log;
-import org.eclipse.jetty.util.log.Logger;
-
-/* ------------------------------------------------------------ */
-/**
- * GZIP Handler This handler will gzip the content of a response if:
- * <ul>
- * <li>The filter is mapped to a matching path</li>
- * <li>The response status code is >=200 and <300
- * <li>The content length is unknown or more than the <code>minGzipSize</code> initParameter or the minGzipSize is 0(default)</li>
- * <li>The content-type is in the comma separated list of mimeTypes set in the <code>mimeTypes</code> initParameter or if no mimeTypes are defined the
- * content-type is not "application/gzip"</li>
- * <li>No content-encoding is specified by the resource</li>
- * </ul>
- *
- * <p>
- * Compressing the content can greatly improve the network bandwidth usage, but at a cost of memory and CPU cycles. If this handler is used for static content,
- * then use of efficient direct NIO may be prevented, thus use of the gzip mechanism of the <code>org.eclipse.jetty.servlet.DefaultServlet</code> is advised instead.
- * </p>
- */
-public class GzipHandler extends HandlerWrapper
-{
- private static final Logger LOG = Log.getLogger(GzipHandler.class);
-
- protected Set<String> _mimeTypes;
- protected Set<String> _excluded;
- protected int _bufferSize = 8192;
- protected int _minGzipSize = 256;
-
- /* ------------------------------------------------------------ */
- /**
- * Instantiates a new gzip handler.
- */
- public GzipHandler()
- {
- }
-
- /* ------------------------------------------------------------ */
- /**
- * 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(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;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * 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());
- }
- }
-
- /* ------------------------------------------------------------ */
- /**
- * 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;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * 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;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * @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")
- && !HttpMethod.HEAD.is(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);
- }
- }
- }
-
- /**
- * 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,long contentLength,int bufferSize, int minCompressSize) throws IOException
- {
- return new AbstractCompressedStream("gzip",request,response,contentLength,bufferSize,minCompressSize)
- {
- @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));
- }
-}

Back to the top