Search in sources :

Example 1 with Handler

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

the class JettyHttpServer method checkIfContextIsFree.

private void checkIfContextIsFree(String path) {
    Handler serverHandler = _server.getHandler();
    if (serverHandler instanceof ContextHandler) {
        ContextHandler ctx = (ContextHandler) serverHandler;
        if (ctx.getContextPath().equals(path))
            throw new RuntimeException("another context already bound to path " + path);
    }
    Handler[] handlers = _server.getHandlers();
    if (handlers == null)
        return;
    for (Handler handler : handlers) {
        if (handler instanceof ContextHandler) {
            ContextHandler ctx = (ContextHandler) handler;
            if (ctx.getContextPath().equals(path))
                throw new RuntimeException("another context already bound to path " + path);
        }
    }
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpHandler(com.sun.net.httpserver.HttpHandler)

Example 2 with Handler

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

the class JettyHttpServer method findContextHandlerCollection.

private ContextHandlerCollection findContextHandlerCollection(Handler[] handlers) {
    if (handlers == null)
        return null;
    for (Handler handler : handlers) {
        if (handler instanceof ContextHandlerCollection) {
            return (ContextHandlerCollection) handler;
        }
        if (handler instanceof HandlerCollection) {
            HandlerCollection hc = (HandlerCollection) handler;
            ContextHandlerCollection chc = findContextHandlerCollection(hc.getHandlers());
            if (chc != null)
                return chc;
        }
    }
    return null;
}
Also used : Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpHandler(com.sun.net.httpserver.HttpHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 3 with Handler

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

the class Invoker method init.

/* ------------------------------------------------------------ */
public void init() {
    ServletContext config = getServletContext();
    _contextHandler = ((ContextHandler.Context) config).getContextHandler();
    Handler handler = _contextHandler.getHandler();
    while (handler != null && !(handler instanceof ServletHandler) && (handler instanceof HandlerWrapper)) handler = ((HandlerWrapper) handler).getHandler();
    _servletHandler = (ServletHandler) handler;
    Enumeration<String> e = getInitParameterNames();
    while (e.hasMoreElements()) {
        String param = e.nextElement();
        String value = getInitParameter(param);
        String lvalue = value.toLowerCase(Locale.ENGLISH);
        if ("nonContextServlets".equals(param)) {
            _nonContextServlets = value.length() > 0 && lvalue.startsWith("t");
        }
        if ("verbose".equals(param)) {
            _verbose = value.length() > 0 && lvalue.startsWith("t");
        } else {
            if (_parameters == null)
                _parameters = new HashMap<String, String>();
            _parameters.put(param, value);
        }
    }
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HashMap(java.util.HashMap) ServletContext(javax.servlet.ServletContext) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HandlerWrapper(org.eclipse.jetty.server.handler.HandlerWrapper)

Example 4 with Handler

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

the class ServletContextHandler method setSessionHandler.

/* ------------------------------------------------------------ */
/**
     * @param sessionHandler The sessionHandler to set.
     */
public void setSessionHandler(SessionHandler sessionHandler) {
    if (isStarted())
        throw new IllegalStateException("STARTED");
    Handler next = null;
    if (_sessionHandler != null) {
        next = _sessionHandler.getHandler();
        _sessionHandler.setHandler(null);
        replaceHandler(_sessionHandler, sessionHandler);
    }
    _sessionHandler = sessionHandler;
    if (next != null && _sessionHandler.getHandler() == null)
        _sessionHandler.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 5 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)

Aggregations

Handler (org.eclipse.jetty.server.Handler)116 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)36 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)35 Server (org.eclipse.jetty.server.Server)32 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)25 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)23 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)22 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)21 ArrayList (java.util.ArrayList)20 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)17 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)17 Test (org.junit.Test)16 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 IOException (java.io.IOException)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 SecurityHandler (org.eclipse.jetty.security.SecurityHandler)12 Request (org.eclipse.jetty.server.Request)12 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)12 StatisticsHandler (org.eclipse.jetty.server.handler.StatisticsHandler)11 ServerConnector (org.eclipse.jetty.server.ServerConnector)10