public static SecurityHandler getCurrentSecurityHandler() { Context context = ContextHandler.getCurrentContext(); if (context==null) return null; return context.getContextHandler().getChildHandlerByClass(SecurityHandler.class); }
private static WebAppContext createWebAppContext(Builder b, AccessControlList adminsAcl, final String appDir) { WebAppContext ctx = new WebAppContext(); ctx.setDefaultsDescriptor(null); ServletHolder holder = new ServletHolder(new DefaultServlet()); Map<String, String> params = ImmutableMap. <String, String> builder() .put("acceptRanges", "true") .put("dirAllowed", "false") .put("gzip", "true") .put("useFileMappedBuffer", "true") .build(); holder.setInitParameters(params); ctx.setWelcomeFiles(new String[] {"index.html"}); ctx.addServlet(holder, "/"); ctx.setDisplayName(b.name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + b.name); String tempDirectory = b.conf.get(HTTP_TEMP_DIR_KEY); if (tempDirectory != null && !tempDirectory.isEmpty()) { ctx.setTempDirectory(new File(tempDirectory)); ctx.setAttribute("javax.servlet.context.tempdir", tempDirectory); } ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, b.conf); ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl); addNoCacheFilter(ctx); return ctx; }
if (webSocketHandlers != null) { try { webSocketServletContextHandler = new ServletContextHandler(null, "/", true, false); WebSocketUpgradeFilter webSocketUpgradeFilter = WebSocketUpgradeFilter.configureContext(webSocketServletContextHandler); if (webSocketIdleTimeoutMillis.isPresent()) { .getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName()); for (String path : webSocketHandlers.keySet()) { WebSocketCreator webSocketCreator = WebSocketCreatorFactory.create(webSocketHandlers.get(path));
public EmbeddedWebServer(BimServer bimServer, String resourceBase, boolean localDev) { server = new Server(new QueuedThreadPool(200, 20)); socketConnector.setIdleTimeout(10800000); // 3 hours for bulkcheckin socketConnector.setStopTimeout(10800000); // 3 hours for bulkcheckin server.addConnector(socketConnector); context = new WebAppContext(server, "", "/"); context.setTempDirectory(bimServer.getHomeDir().resolve("jettytmp").toFile()); Jsr356Impl.setServletContext(configureContext, context.getServletContext()); Jsr356Impl.setAdditionalWebSocketConfigurator(new AdditionalWebSocketConfigurator() { @Override context.addServlet(servletHolder, "/*"); context.getServletContext().setAttribute("bimserver", bimServer); if (context.getResourceBase() == null) { if (resourceBase == null) {
public void start() throws Exception{ if(!started){ started=true; server.start(); //context.getServletHandler().dumpStdErr(); groovity = (Groovity) context.getServletContext().getAttribute(GroovityServlet.SERVLET_CONTEXT_GROOVITY_INSTANCE); } } public Groovity getGroovity(){
private HttpServer2(final Builder b) throws IOException { final String appDir = getWebAppsPath(b.name); this.webServer = new Server(); this.adminsAcl = b.adminsAcl; this.handlers = new HandlerCollection(); this.webAppContext = createWebAppContext(b, adminsAcl, appDir); this.xFrameOptionIsEnabled = b.xFrameEnabled; this.xFrameOption = b.xFrameOption; try { this.secretProvider = constructSecretProvider(b, webAppContext.getServletContext()); this.webAppContext.getServletContext().setAttribute (AuthenticationFilter.SIGNER_SECRET_PROVIDER_ATTRIBUTE, secretProvider); } catch(IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } this.findPort = b.findPort; this.portRanges = b.portRanges; initializeWebServer(b.name, b.hostName, b.conf, b.pathSpecs); }
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")); } }
private static WebAppContext createWebAppContext(String name, Configuration conf, AccessControlList adminsAcl, final String appDir) { WebAppContext ctx = new WebAppContext(); ctx.setDisplayName(name); ctx.setContextPath("/"); ctx.setWar(appDir + "/" + name); ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf); // for org.apache.hadoop.metrics.MetricsServlet ctx.getServletContext().setAttribute( org.apache.hadoop.http.HttpServer2.CONF_CONTEXT_ATTRIBUTE, conf); ctx.getServletContext().setAttribute(ADMINS_ACL, adminsAcl); addNoCacheFilter(ctx); return ctx; }
public Jetty(String path, int port, ClassLoader classLoader, Injector injector) { WebAppContext webAppContext = new WebAppContext(path, APP_NAME); webAppContext.setClassLoader(classLoader); webAppContext.getServletContext().setAttribute(INJECTOR_KEY, injector); setUp(webAppContext, port); }
/** * @throws Exception */ protected void initJspServlet () throws Exception { ContextHandler ch = ((ContextHandler.Context)getServletHandler().getServletContext()).getContextHandler(); /* Set the webapp's classpath for Jasper */ ch.setAttribute("org.apache.catalina.jsp_classpath", ch.getClassPath()); /* Set the system classpath for Jasper */ setInitParameter("com.sun.appserv.jsp.classpath", Loader.getClassPath(ch.getClassLoader().getParent())); /* Set up other classpath attribute */ if ("?".equals(getInitParameter("classpath"))) { String classpath = ch.getClassPath(); LOG.debug("classpath=" + classpath); if (classpath != null) setInitParameter("classpath", classpath); } }
private MultiParts newMultiParts(ServletInputStream inputStream, String contentType, MultipartConfigElement config, Object object) throws IOException { MultiPartFormDataCompliance compliance = getHttpChannel().getHttpConfiguration().getMultipartFormDataCompliance(); if(LOG.isDebugEnabled()) LOG.debug("newMultiParts {} {}",compliance, this); switch(compliance) { case RFC7578: return new MultiParts.MultiPartsHttpParser(getInputStream(), getContentType(), config, (_context != null?(File)_context.getAttribute("javax.servlet.context.tempdir"):null), this); case LEGACY: default: return new MultiParts.MultiPartsUtilParser(getInputStream(), getContentType(), config, (_context != null?(File)_context.getAttribute("javax.servlet.context.tempdir"):null), this); } }
@Override public void doStart() throws Exception { LOG.info("HazelcastSessionManager.doStart()"); super.doStart(); String[] hosts = getContextHandler().getVirtualHosts(); if (hosts == null || hosts.length == 0) { // IPv6 equiv of 0.0.0.0 hosts = new String[]{"::"}; } String contextPath = getContext().getContextPath(); if (contextPath == null || "".equals(contextPath)) { contextPath = "*"; } LOG.debug("HazelcastSessionManager:doStart():contextpath: " + contextPath); contextId = createContextId(hosts, contextPath); LOG.debug("HazelcastSessionManager:doStart():contextId: " + contextId); sessions = ((HazelcastSessionIdManager) getSessionIdManager()).getSessions(); }
@Override public void doStart() throws Exception _context=ContextHandler.getCurrentContext(); _loader=Thread.currentThread().getContextClassLoader(); synchronized (server) server.setSessionIdManager(_sessionIdManager); String tmp=_context.getInitParameter(SessionManager.__SessionCookieProperty); if (tmp!=null) _sessionCookie=tmp; tmp=_context.getInitParameter(SessionManager.__SessionIdPathParameterNameProperty); if (tmp!=null) setSessionIdPathParameterName(tmp); tmp=_context.getInitParameter(SessionManager.__MaxAgeProperty); if (tmp!=null) _maxCookieAge=Integer.parseInt(tmp.trim()); _sessionDomain=_context.getInitParameter(SessionManager.__SessionDomainProperty); _sessionPath=_context.getInitParameter(SessionManager.__SessionPathProperty); tmp=_context.getInitParameter(SessionManager.__CheckRemoteSessionEncoding); if (tmp!=null) _checkingRemoteSessionIdEncoding=Boolean.parseBoolean(tmp);
ContextHandler.Context context =ContextHandler.getCurrentContext(); if (context!=null) Enumeration<String> names=context.getInitParameterNames(); while (names!=null && names.hasMoreElements()) if (name.startsWith("org.eclipse.jetty.security.") && getInitParameter(name)==null) setInitParameter(name,context.getInitParameter(name)); setAuthenticator(authenticatorFactory.getAuthenticator(getServer(),ContextHandler.getCurrentContext(),this, _identityService, _loginService)); else if (_realmName!=null) LOG.warn("No Authenticator for "+this); throw new IllegalStateException("No Authenticator");
@Override public InputStream getResourceAsStream(String path) { try { URL url = getResource(path); if (url == null) return null; Resource r = Resource.newResource(url); return r.getInputStream(); } catch (Exception e) { LOG.ignore(e); return null; } }
private void setContextAttributes(ServletContextHandler context, Configuration conf) { context.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, conf); context.getServletContext().setAttribute(ADMINS_ACL, adminsAcl); }
@Override public void lifeCycleStarting(LifeCycle event) { ctx.getServletContext().setInitParameter("restx.baseServerUri", baseUrl()); ctx.getServletContext().setInitParameter("restx.serverId", getServerId()); } });
private HandlerList findHandlerList(FilterConfig filterConfig) { Server server = ((ContextHandler.Context) filterConfig.getServletContext()).getContextHandler().getServer(); if (RequestLogHandler.class.isAssignableFrom(server.getHandler().getClass())) { return (HandlerList) ((RequestLogHandler) server.getHandler()).getHandler(); } return (HandlerList) server.getHandler(); }
@Override public void doStart() throws Exception _context=ContextHandler.getCurrentContext(); _loader=Thread.currentThread().getContextClassLoader(); _sessionIdManager=server.getSessionIdManager(); if (_sessionIdManager==null) String tmp=_context.getInitParameter(SessionManager.__SessionCookieProperty); if (tmp!=null) _sessionCookie=tmp; tmp=_context.getInitParameter(SessionManager.__SessionIdPathParameterNameProperty); if (tmp!=null) setSessionIdPathParameterName(tmp); tmp=_context.getInitParameter(SessionManager.__MaxAgeProperty); if (tmp!=null) _maxCookieAge=Integer.parseInt(tmp.trim()); _sessionDomain=_context.getInitParameter(SessionManager.__SessionDomainProperty); _sessionPath=_context.getInitParameter(SessionManager.__SessionPathProperty); tmp=_context.getInitParameter(SessionManager.__CheckRemoteSessionEncoding); if (tmp!=null) _checkingRemoteSessionIdEncoding=Boolean.parseBoolean(tmp);
_managedAttributes.put(attribute,null); Enumeration<String> e = _scontext.getAttributeNames(); while (e.hasMoreElements()) Object value = _scontext.getAttribute(name); checkManagedAttribute(name,value); callContextInitialized(listener, event);