Search in sources :

Example 1 with GzipHandler

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();
}
Also used : Handler(org.eclipse.jetty.server.Handler) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler)

Example 2 with GzipHandler

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();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) Handler(org.eclipse.jetty.server.Handler) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) File(java.io.File)

Example 3 with GzipHandler

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());
}
Also used : GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) Test(org.junit.Test)

Example 4 with GzipHandler

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();
}
Also used : Server(org.eclipse.jetty.server.Server) GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) LocalConnector(org.eclipse.jetty.server.LocalConnector) Before(org.junit.Before)

Example 5 with GzipHandler

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;
}
Also used : GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler)

Aggregations

GzipHandler (org.eclipse.jetty.server.handler.gzip.GzipHandler)32 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)11 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)9 Server (org.eclipse.jetty.server.Server)8 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)6 ServerConnector (org.eclipse.jetty.server.ServerConnector)6 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)6 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)5 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)5 File (java.io.File)4 Filter (javax.servlet.Filter)3 Handler (org.eclipse.jetty.server.Handler)3 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)3 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)3 Constraint (org.eclipse.jetty.util.security.Constraint)3 Test (org.junit.jupiter.api.Test)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 DispatcherType (javax.servlet.DispatcherType)2