Obtains the {@link WebApp} associated with the given {@link ServletContext}.
425036
public static WebApp get(ServletContext context) {
        Object o = context.getAttribute(WebApp.class.getName());
        if(o==null) {
            synchronized (WebApp.class) {
                o = context.getAttribute(WebApp.class.getName());
                if(o==null) {
                    o = new WebApp(context);
                    context.setAttribute(WebApp.class.getName(),o);
                }
            }
        }
        return (WebApp)o;
    }
346766
public ServletResponse getServletResponse()
    {
        RequestContext reqContext = peekRequestContext();
        if (reqContext == null)
            return null;

        return  reqContext._response;
    }
558830
public static ServletContextCache getCache(ServletContext servletContext) {
		ServletContextCache cache = (ServletContextCache)servletContext.getAttribute(ATTRIBUTE_KEY);
		if(cache == null) {
			// It is possible this is called during context initialization before the listener
			cache = new ServletContextCache(servletContext);
			servletContext.setAttribute(ATTRIBUTE_KEY, cache);
			//throw new IllegalStateException("ServletContextCache not active in the provided ServletContext.  Add context listener to web.xml?");
		} else {
			assert cache.servletContext == servletContext;
		}
		return cache;
	}
1187090
protected void createWebAppContext() {
    webapp = new WebAppContext();
    webapp.setThrowUnavailableOnStartupException(true);
    webapp.setServerClasses(getServerClasses());
    webapp.setContextPath(getContextPath());
    webapp.setTempDirectory(createTempDir("jetty-app-"));
    setSecureCookies();
  }
428888
public static HttpServletRequest getHttpServletRequestFromRequestAttributes() {
        try {
            return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
        } catch (final Exception e) {
            LOGGER.trace(e.getMessage(), e);
        }
        return null;
    }
626277
public static Context getApplicationContext() {
        com.ardikars.jxnet.context.Context context = com.ardikars.jxnet.context.Application.getApplicationContext();
        return new ApplicationContext(context);
    }
625334
public static WebAppContext createWebAppContext() {
		WebAppContext webAppContext = new WebAppContext();

		webAppContext.setContextPath(setting.getStr("contextPath", "/"));
		webAppContext.setResourceBase(resourceBase);

		// 方式1：Servlet级别拦截
		webAppContext.addServlet(createHuluServletHolder(), "/*");

		// 方式2：Filter级别拦截
		// FilterHolder filterHolder = new FilterHolder(ActionFilter.class);
		// filterHolder.setAsyncSupported(false);
		// webAppContext.addFilter(ActionFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

		return webAppContext;
	}
859252
protected PageContext getPageContext()
    {
        JspContext ctxt = getJspContext();
        if (ctxt instanceof PageContext)
            return (PageContext) ctxt;

        // assert the page context and log an error in production
        assert(false) : "The JspContext was not a PageContext";
        logger.error("The JspContext was not a PageContext");
        return null;
    }
121786
public ServletContext getCurrentServletContext() {
        final ClassLoader cl = getContextClassLoader();
        if (cl == null) {
            return null;
        }
        return servletContexts.get(cl);
    }
528536
public synchronized HttpContext getHttpContext() {
        if (jolokiaHttpContext == null) {
            final String user = getConfiguration(USER);
            final String authMode = getConfiguration(AUTH_MODE);
            if (user == null) {
                if (ServiceAuthenticationHttpContext.shouldBeUsed(authMode)) {
                    jolokiaHttpContext = new ServiceAuthenticationHttpContext(bundleContext, authMode);
                } else {
                    jolokiaHttpContext = new DefaultHttpContext();
                }
            } else {
                jolokiaHttpContext =
                    new BasicAuthenticationHttpContext(getConfiguration(REALM),
                                                       createAuthenticator(authMode));
            }
        }
        return jolokiaHttpContext;
    }
399769
protected String resolveResourceContextPath(HttpServletRequest request, String resource) {
        final String resourceContextPath = this.getResourceServerContextPath();
        
        this.logger.debug("Attempting to locate resource serving webapp with context path: {}", resourceContextPath);
        
        //Try to resolve the 
        final ServletContext resourceContext = this.servletContext.getContext(resourceContextPath);
        if (resourceContext == null || !resourceContextPath.equals(resourceContext.getContextPath())) {
            this.logger.warn("Could not find resource serving webapp under context path {} ensure the resource server is deployed and cross context dispatching is enable for this web application", resourceContextPath);
            return request.getContextPath();
        }
        
        this.logger.debug("Found resource serving webapp at: {}", resourceContextPath);
        
        URL url = null;
        try {
            url = resourceContext.getResource(resource);
        }
        catch (MalformedURLException e) {
            //Ignore
        }
        
        if (url == null) {
            this.logger.debug("Resource serving webapp {} doesn't contain resource {} Falling back to the local resource.", resourceContextPath, resource);
            return request.getContextPath();
        }
        
        this.logger.debug("Resource serving webapp {} contains resource {} Using resource server.", resourceContextPath, resource);
        return resourceContextPath;
    }
1344664
public static ActionServlet getActionServlet( ServletContext context )
    {
        if ( context == null ) return null;
        return ( ActionServlet ) context.getAttribute( Globals.ACTION_SERVLET_KEY );
    }
316310
public static FlowControllerFactory get( ServletContext servletContext )
    {
        FlowControllerFactory factory = ( FlowControllerFactory ) servletContext.getAttribute( CONTEXT_ATTR );
        assert factory != null
                : FlowControllerFactory.class.getName() + " was not found in ServletContext attribute " + CONTEXT_ATTR;
        factory.reinit( servletContext );
        return factory;
    }
1076891
public static UrlMappingsHolder lookupUrlMappings(ServletContext servletContext) {
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        return (UrlMappingsHolder)wac.getBean(UrlMappingsHolder.BEAN_ID);
    }
32797
public static XmlWebApplicationContext getAppContext(Page page) {
        return page == null ? null : (XmlWebApplicationContext) page.getAttribute(APP_CONTEXT_ATTRIB);
    }
764733
Object getServletContextForCurrentClassLoader() {
        Object result;
        FactoryManagerCacheKey key = new FactoryManagerCacheKey(null, getClassLoader(), applicationMap);
        result = key.getContext();
        
        return result;
    }
517271
public static ContextLoaderListener createSpringContextLoader(final WebApplicationContext webApplicationContext) {
        return new ContextLoaderListener() {
            @SuppressWarnings("unchecked")
            @Override
            protected WebApplicationContext createWebApplicationContext(ServletContext sc) {
                return webApplicationContext;
            }
        };
    }