Issue #4765 - Review GzipHandler inside ServletContextHandler.

Removed GzipHandler from ServletContextHandler.
Updated ServletContextHandlerTest.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2020-04-13 14:55:16 +02:00
parent 93774ae564
commit 1a234dcf4c
2 changed files with 2 additions and 77 deletions

View File

@ -95,7 +95,6 @@ public class ServletContextHandler extends ContextHandler
public static final int SESSIONS = 1;
public static final int SECURITY = 2;
public static final int GZIP = 4;
public static final int NO_SESSIONS = 0;
public static final int NO_SECURITY = 0;
@ -128,7 +127,6 @@ public class ServletContextHandler extends ContextHandler
protected SessionHandler _sessionHandler;
protected SecurityHandler _securityHandler;
protected ServletHandler _servletHandler;
protected GzipHandler _gzipHandler;
protected int _options;
protected JspConfigDescriptor _jspConfig;
@ -281,21 +279,6 @@ public class ServletContextHandler extends ContextHandler
handler = _securityHandler;
}
// link gzip handler
if (getGzipHandler() != null)
{
while (!(handler.getHandler() instanceof GzipHandler) &&
!(handler.getHandler() instanceof ServletHandler) &&
handler.getHandler() instanceof HandlerWrapper)
{
handler = (HandlerWrapper)handler.getHandler();
}
if (handler.getHandler() != _gzipHandler)
doSetHandler(handler, _gzipHandler);
handler = _gzipHandler;
}
// link servlet handler
if (getServletHandler() != null)
{
@ -369,8 +352,6 @@ public class ServletContextHandler extends ContextHandler
/**
* Finish constructing handlers and link them together.
*
* @see org.eclipse.jetty.server.handler.ContextHandler#startContext()
*/
@Override
protected void startContext() throws Exception
@ -440,17 +421,6 @@ public class ServletContextHandler extends ContextHandler
return _sessionHandler;
}
/**
* @return Returns the gzipHandler.
*/
@ManagedAttribute(value = "context gzip handler", readonly = true)
public GzipHandler getGzipHandler()
{
if (_gzipHandler == null && (_options & GZIP) != 0 && !isStarted())
_gzipHandler = new GzipHandler();
return _gzipHandler;
}
/**
* Convenience method to add a servlet.
*
@ -652,16 +622,6 @@ public class ServletContextHandler extends ContextHandler
relinkHandlers();
}
/**
* @param gzipHandler The {@link GzipHandler} to set on this context.
*/
public void setGzipHandler(GzipHandler gzipHandler)
{
replaceHandler(_gzipHandler, gzipHandler);
_gzipHandler = gzipHandler;
relinkHandlers();
}
/**
* @param servletHandler The servletHandler to set.
*/
@ -683,8 +643,6 @@ public class ServletContextHandler extends ContextHandler
setSessionHandler((SessionHandler)handler);
else if (handler instanceof SecurityHandler)
setSecurityHandler((SecurityHandler)handler);
else if (handler instanceof GzipHandler)
setGzipHandler((GzipHandler)handler);
else if (handler instanceof ServletHandler)
setServletHandler((ServletHandler)handler);
else

View File

@ -79,7 +79,6 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.Decorator;
@ -1630,30 +1629,6 @@ public class ServletContextHandlerTest
assertEquals(extra, context.getSessionHandler().getHandler());
}
@Test
public void testGzipHandlerOption() throws Exception
{
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS | ServletContextHandler.GZIP);
GzipHandler gzip = context.getGzipHandler();
_server.start();
assertEquals(context.getSessionHandler(), context.getHandler());
assertEquals(gzip, context.getSessionHandler().getHandler());
assertEquals(context.getServletHandler(), gzip.getHandler());
}
@Test
public void testGzipHandlerSet() throws Exception
{
ServletContextHandler context = new ServletContextHandler();
context.setSessionHandler(new SessionHandler());
context.setGzipHandler(new GzipHandler());
GzipHandler gzip = context.getGzipHandler();
_server.start();
assertEquals(context.getSessionHandler(), context.getHandler());
assertEquals(gzip, context.getSessionHandler().getHandler());
assertEquals(context.getServletHandler(), gzip.getHandler());
}
@Test
public void testReplaceServletHandlerWithServlet() throws Exception
{
@ -1689,14 +1664,12 @@ public class ServletContextHandlerTest
@Test
public void testSetSecurityHandler() throws Exception
{
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY | ServletContextHandler.GZIP);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS | ServletContextHandler.SECURITY);
assertNotNull(context.getSessionHandler());
SessionHandler sessionHandler = context.getSessionHandler();
assertNotNull(context.getSecurityHandler());
SecurityHandler securityHandler = context.getSecurityHandler();
assertNotNull(context.getGzipHandler());
GzipHandler gzipHandler = context.getGzipHandler();
//check the handler linking order
HandlerWrapper h = (HandlerWrapper)context.getHandler();
assertSame(h, sessionHandler);
@ -1704,9 +1677,6 @@ public class ServletContextHandlerTest
h = (HandlerWrapper)h.getHandler();
assertSame(h, securityHandler);
h = (HandlerWrapper)h.getHandler();
assertSame(h, gzipHandler);
//replace the security handler
SecurityHandler myHandler = new SecurityHandler()
{
@ -1747,9 +1717,6 @@ public class ServletContextHandlerTest
h = (HandlerWrapper)h.getHandler();
assertSame(h, myHandler);
h = (HandlerWrapper)h.getHandler();
assertSame(h, gzipHandler);
}
@Test