Search in sources :

Example 1 with ServletContext

use of javax.servlet.ServletContext 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 2 with ServletContext

use of javax.servlet.ServletContext 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 3 with ServletContext

use of javax.servlet.ServletContext in project jetty.project by eclipse.

the class QoSFilter method init.

public void init(FilterConfig filterConfig) {
    int max_priority = __DEFAULT_MAX_PRIORITY;
    if (filterConfig.getInitParameter(MAX_PRIORITY_INIT_PARAM) != null)
        max_priority = Integer.parseInt(filterConfig.getInitParameter(MAX_PRIORITY_INIT_PARAM));
    _queues = new Queue[max_priority + 1];
    _listeners = new AsyncListener[_queues.length];
    for (int p = 0; p < _queues.length; ++p) {
        _queues[p] = new ConcurrentLinkedQueue<>();
        _listeners[p] = new QoSAsyncListener(p);
    }
    int maxRequests = __DEFAULT_PASSES;
    if (filterConfig.getInitParameter(MAX_REQUESTS_INIT_PARAM) != null)
        maxRequests = Integer.parseInt(filterConfig.getInitParameter(MAX_REQUESTS_INIT_PARAM));
    _passes = new Semaphore(maxRequests, true);
    _maxRequests = maxRequests;
    long wait = __DEFAULT_WAIT_MS;
    if (filterConfig.getInitParameter(MAX_WAIT_INIT_PARAM) != null)
        wait = Integer.parseInt(filterConfig.getInitParameter(MAX_WAIT_INIT_PARAM));
    _waitMs = wait;
    long suspend = __DEFAULT_TIMEOUT_MS;
    if (filterConfig.getInitParameter(SUSPEND_INIT_PARAM) != null)
        suspend = Integer.parseInt(filterConfig.getInitParameter(SUSPEND_INIT_PARAM));
    _suspendMs = suspend;
    ServletContext context = filterConfig.getServletContext();
    if (context != null && Boolean.parseBoolean(filterConfig.getInitParameter(MANAGED_ATTR_INIT_PARAM)))
        context.setAttribute(filterConfig.getFilterName(), this);
}
Also used : ServletContext(javax.servlet.ServletContext) Semaphore(java.util.concurrent.Semaphore)

Example 4 with ServletContext

use of javax.servlet.ServletContext in project jetty.project by eclipse.

the class WebAppContextTest method testRealPathDoesNotExist.

@Test
public void testRealPathDoesNotExist() throws Exception {
    Server server = new Server(0);
    WebAppContext context = new WebAppContext(".", "/");
    server.setHandler(context);
    server.start();
    ServletContext ctx = context.getServletContext();
    assertNotNull(ctx.getRealPath("/doesnotexist"));
    assertNotNull(ctx.getRealPath("/doesnotexist/"));
}
Also used : Server(org.eclipse.jetty.server.Server) ServletContext(javax.servlet.ServletContext) Test(org.junit.Test)

Example 5 with ServletContext

use of javax.servlet.ServletContext in project jetty.project by eclipse.

the class InfoServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    ServletContext context = config.getServletContext();
    NativeWebSocketConfiguration configuration = (NativeWebSocketConfiguration) context.getAttribute(NativeWebSocketConfiguration.class.getName());
    configuration.getFactory().getPolicy().setMaxTextMessageSize(10 * 1024 * 1024);
    configuration.addMapping("/info/*", this);
}
Also used : ServletContext(javax.servlet.ServletContext)

Aggregations

ServletContext (javax.servlet.ServletContext)1111 Test (org.junit.Test)259 HttpServletRequest (javax.servlet.http.HttpServletRequest)186 HttpServletResponse (javax.servlet.http.HttpServletResponse)143 IOException (java.io.IOException)136 ServletException (javax.servlet.ServletException)101 ServletConfig (javax.servlet.ServletConfig)79 File (java.io.File)78 FilterConfig (javax.servlet.FilterConfig)66 HashMap (java.util.HashMap)64 Enumeration (java.util.Enumeration)52 InputStream (java.io.InputStream)51 ArrayList (java.util.ArrayList)50 URL (java.net.URL)48 HttpSession (javax.servlet.http.HttpSession)43 Map (java.util.Map)39 Locale (java.util.Locale)38 List (java.util.List)33 PrintWriter (java.io.PrintWriter)32 LinkedHashMap (java.util.LinkedHashMap)30