use of org.eclipse.jetty.server.handler.gzip.GzipHandler in project jetty.project by eclipse.
the class ServletContextHandler method setGzipHandler.
/* ------------------------------------------------------------ */
/**
* @param gzipHandler The {@link GzipHandler} to set on this context.
*/
public void setGzipHandler(GzipHandler gzipHandler) {
if (isStarted())
throw new IllegalStateException("STARTED");
Handler next = null;
if (_gzipHandler != null) {
next = _gzipHandler.getHandler();
_gzipHandler.setHandler(null);
replaceHandler(_gzipHandler, gzipHandler);
}
_gzipHandler = gzipHandler;
if (next != null && _gzipHandler.getHandler() == null)
_gzipHandler.setHandler(next);
relinkHandlers();
}
use of org.eclipse.jetty.server.handler.gzip.GzipHandler in project jetty.project by eclipse.
the class ManyHandlers method main.
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
// create the handlers
Handler param = new ParamHandler();
HandlerWrapper wrapper = new WelcomeWrapHandler();
Handler hello = new HelloHandler();
Handler dft = new DefaultHandler();
RequestLogHandler requestLog = new RequestLogHandler();
// configure request logging
File requestLogFile = File.createTempFile("demo", "log");
NCSARequestLog ncsaLog = new NCSARequestLog(requestLogFile.getAbsolutePath());
requestLog.setRequestLog(ncsaLog);
// create the handler collections
HandlerCollection handlers = new HandlerCollection();
HandlerList list = new HandlerList();
// link them all together
wrapper.setHandler(hello);
list.setHandlers(new Handler[] { param, new GzipHandler(), dft });
handlers.setHandlers(new Handler[] { list, requestLog });
// Handler tree looks like the following
// <pre>
// Server
// + HandlerCollection
// . + HandlerList
// . | + param (ParamHandler)
// . | + wrapper (WelcomeWrapHandler)
// . | | \ hello (HelloHandler)
// . | \ dft (DefaultHandler)
// . \ requestLog (RequestLogHandler)
// </pre>
server.setHandler(handlers);
server.start();
server.join();
}
use of org.eclipse.jetty.server.handler.gzip.GzipHandler in project jetty.project by eclipse.
the class ServletContextHandlerTest method testGzipHandlerOption.
@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());
}
use of org.eclipse.jetty.server.handler.gzip.GzipHandler in project jetty.project by eclipse.
the class GzipHandlerTest method init.
@Before
public void init() throws Exception {
_server = new Server();
_connector = new LocalConnector(_server);
_server.addConnector(_connector);
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setExcludedAgentPatterns();
gzipHandler.setMinGzipSize(16);
gzipHandler.setInflateBufferSize(4096);
ServletContextHandler context = new ServletContextHandler(gzipHandler, "/ctx");
ServletHandler servlets = context.getServletHandler();
_server.setHandler(gzipHandler);
gzipHandler.setHandler(context);
servlets.addServletWithMapping(MicroServlet.class, "/micro");
servlets.addServletWithMapping(MicroChunkedServlet.class, "/microchunked");
servlets.addServletWithMapping(TestServlet.class, "/content");
servlets.addServletWithMapping(ForwardServlet.class, "/forward");
servlets.addServletWithMapping(IncludeServlet.class, "/include");
servlets.addServletWithMapping(EchoServlet.class, "/echo/*");
_server.start();
}
use of org.eclipse.jetty.server.handler.gzip.GzipHandler in project nifi by apache.
the class JettyServer method gzip.
/**
* Enables compression for the specified handler.
*
* @param handler handler to enable compression for
* @return compression enabled handler
*/
private Handler gzip(final Handler handler) {
final GzipHandler gzip = new GzipHandler();
gzip.setIncludedMethods("GET", "POST", "PUT", "DELETE");
gzip.setHandler(handler);
return gzip;
}
Aggregations