Search in sources :

Example 16 with Handler

use of org.eclipse.jetty.server.Handler in project jetty.project by eclipse.

the class ServletContextHandler method setServletHandler.

/* ------------------------------------------------------------ */
/**
     * @param servletHandler The servletHandler to set.
     */
public void setServletHandler(ServletHandler servletHandler) {
    if (isStarted())
        throw new IllegalStateException("STARTED");
    Handler next = null;
    if (_servletHandler != null) {
        next = _servletHandler.getHandler();
        _servletHandler.setHandler(null);
        replaceHandler(_servletHandler, servletHandler);
    }
    _servletHandler = servletHandler;
    if (next != null && _servletHandler.getHandler() == null)
        _servletHandler.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 17 with Handler

use of org.eclipse.jetty.server.Handler in project jetty.project by eclipse.

the class ServletContextHandler method setSecurityHandler.

/* ------------------------------------------------------------ */
/**
     * @param securityHandler The {@link SecurityHandler} to set on this context.
     */
public void setSecurityHandler(SecurityHandler securityHandler) {
    if (isStarted())
        throw new IllegalStateException("STARTED");
    Handler next = null;
    if (_securityHandler != null) {
        next = _securityHandler.getHandler();
        _securityHandler.setHandler(null);
        replaceHandler(_securityHandler, securityHandler);
    }
    _securityHandler = securityHandler;
    if (next != null && _securityHandler.getHandler() == null)
        _securityHandler.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 18 with Handler

use of org.eclipse.jetty.server.Handler 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 19 with Handler

use of org.eclipse.jetty.server.Handler in project jetty.project by eclipse.

the class StatisticsServlet method init.

public void init() throws ServletException {
    ServletContext context = getServletContext();
    ContextHandler.Context scontext = (ContextHandler.Context) context;
    Server _server = scontext.getContextHandler().getServer();
    Handler handler = _server.getChildHandlerByClass(StatisticsHandler.class);
    if (handler != null) {
        _statsHandler = (StatisticsHandler) handler;
    } else {
        LOG.warn("Statistics Handler not installed!");
        return;
    }
    _memoryBean = ManagementFactory.getMemoryMXBean();
    _connectors = _server.getConnectors();
    if (getInitParameter("restrictToLocalhost") != null) {
        _restrictToLocalhost = "true".equals(getInitParameter("restrictToLocalhost"));
    }
}
Also used : ServletContext(javax.servlet.ServletContext) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) ServletContext(javax.servlet.ServletContext) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler)

Example 20 with Handler

use of org.eclipse.jetty.server.Handler in project buck by facebook.

the class TraceHandlerDelegateTest method testHandleGet.

@Test
public void testHandleGet() throws IOException, ServletException {
    Request baseRequest = createMock(Request.class);
    expect(baseRequest.getPathInfo()).andReturn("/abcdef");
    baseRequest.setHandled(true);
    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpServletResponse response = createMock(HttpServletResponse.class);
    response.setStatus(200);
    response.setContentType("text/html; charset=utf-8");
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    expect(response.getWriter()).andReturn(printWriter);
    response.flushBuffer();
    BuildTraces buildTraces = createMock(BuildTraces.class);
    expect(buildTraces.getTraceAttributesFor("abcdef")).andReturn(new TraceAttributes(Optional.of("buck build buck"), 2000L));
    Handler traceHandler = new TemplateHandler(new TraceHandlerDelegate(buildTraces));
    replayAll();
    traceHandler.handle("/trace/abcdef", baseRequest, request, response);
    verifyAll();
    String expectedScriptTag = "<script src=\"/tracedata/abcdef?callback=onTracesLoaded\">";
    String html = stringWriter.toString();
    assertThat(html, containsString(expectedScriptTag));
    assertThat(html, containsString("buck build buck"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StringWriter(java.io.StringWriter) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) TraceAttributes(com.facebook.buck.util.trace.BuildTraces.TraceAttributes) Handler(org.eclipse.jetty.server.Handler) Matchers.containsString(org.hamcrest.Matchers.containsString) BuildTraces(com.facebook.buck.util.trace.BuildTraces) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

Handler (org.eclipse.jetty.server.Handler)63 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)18 Server (org.eclipse.jetty.server.Server)14 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)13 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)12 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)10 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)10 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)10 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)7 ServerConnector (org.eclipse.jetty.server.ServerConnector)7 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)7 HandlerList (org.eclipse.jetty.server.handler.HandlerList)7 ArrayList (java.util.ArrayList)6 Connector (org.eclipse.jetty.server.Connector)6 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)6 Test (org.junit.Test)6 HandlerWrapper (org.eclipse.jetty.server.handler.HandlerWrapper)5 GzipHandler (org.eclipse.jetty.server.handler.gzip.GzipHandler)5 URI (java.net.URI)4