/* getContextAttribute(HttpServlet...) which implements ServletConfig and causes ambigous calls unless explicitly specified...
324268
public static final <T> T getContextAttribute(HttpServlet servlet, String name, Class<T> cls, Set<GetOpts> opts, T defaultValue)
	{
		return getContextAttribute((ServletConfig)servlet, name, cls, opts, defaultValue);
	}
1201703
public static ServletRequest getContextRequest()
    {
        ServiceContext context = (ServiceContext) _localContext.get();

        if (context != null)
            return context._request;
        else
            return null;
    }
123898
public static HttpServletResponse getHttpServletResponseFromExternalWebflowContext() {
        val servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();
        if (servletExternalContext != null) {
            return (HttpServletResponse) servletExternalContext.getNativeResponse();
        }
        return null;
    }
1049480
public void setContext( AdapterContext context )
    {
        Object servletContext = context.getExternalContext();
        assert servletContext instanceof ServletContext : servletContext;
        _servletContext = ( ServletContext ) servletContext;
        _eventReporter = createEventReporter();
    }
676532
private Attribute checkContext(URI type, URI id, URI issuer,
                                        URI category, int designatorType) {
        if (!STRING_ATTRIBUTE_TYPE_URI.equals(type)) return null;
        String [] values = null;
        switch(designatorType){
            case AttributeDesignator.SUBJECT_TARGET:
                values = context.getSubjectValues(id.toString());
                break;
            case AttributeDesignator.RESOURCE_TARGET:
                values = context.getResourceValues(id);
                break;
            case AttributeDesignator.ACTION_TARGET:
                values = context.getActionValues(id);
                break;
            case AttributeDesignator.ENVIRONMENT_TARGET:
                values = context.getEnvironmentValues(id);
                break;
        }
        if (values == null || values.length == 0) return null;
        String iString = (issuer == null) ? null : issuer.toString();
        String tString = type.toString();
        if (values.length == 1) {
            AttributeValue val = stringToValue(values[0], tString);
            return (val == null) ? null :
                new SingletonAttribute(id, iString, getCurrentDateTime(), val);
        } else {
            ArrayList<AttributeValue> valCollection = new ArrayList<AttributeValue>(values.length);
            for (int i=0;i<values.length;i++) {
                AttributeValue val = stringToValue(values[i], tString);
                if (val != null) valCollection.add(val);
            }
            return new BasicAttribute(id, type, iString, getCurrentDateTime(), valCollection);
        }
    }
104390
public synchronized void setContextAttribute(String name, Object value)
    {
        Object old= super.getContextAttribute(name);
        super.setContextAttribute(name, value);

        if (_contextAttributeListeners != null)
        {
            ServletContextAttributeEvent event=
                new ServletContextAttributeEvent(getServletContext(), name, old != null ? old : value);
            for (int i= 0; i < LazyList.size(_contextAttributeListeners); i++)
            {
                ServletContextAttributeListener l=
                    (ServletContextAttributeListener)LazyList.get(_contextAttributeListeners, i);
                if (old == null)
                    l.attributeAdded(event);
                else
                    if (value == null)
                        l.attributeRemoved(event);
                    else
                        l.attributeReplaced(event);
            }
        }
    }
844119
private String getContextPath() {
    ClassLoader loader = getClass().getClassLoader();
    if(loader == null)
     return null;
    URL url = loader.getResource("/");
    if (url != null) {
      String[] elements = url.toString().split("/");
      for (int i = elements.length - 1; i > 0; --i) {
        // URLs look like this: file:/.../ImageServer/WEB-INF/classes/
        // And we want that part that's just before WEB-INF
        if ("WEB-INF".equals(elements[i])) {
          return elements[i - 1];
        }
      }
    }
    return null;
  }
866978
@Override
    public String getContextPath() {
        final HttpServletRequest request = getCurrentRequest();
        String appUri = (String) request.getAttribute(GrailsApplicationAttributes.APP_URI_ATTRIBUTE);
        if (appUri == null) {
            appUri = urlHelper.getContextPath(request);
        }
        return appUri;
    }
811916
protected Object getContextAttribute(String name)
    {
        if (ServletHandler.__J_S_CONTEXT_TEMPDIR.equals(name))
        {
            // Initialize temporary directory
            Object t = getHttpContext().getAttribute(ServletHandler.__J_S_CONTEXT_TEMPDIR);

            if (t instanceof File)
                return (File)t;
            
            return getHttpContext().getTempDirectory();
        }

        if (_attributes.containsKey(name))
            return _attributes.get(name);
        return getHttpContext().getAttribute(name);
    }
982780
public static HttpContext getContext(HttpHost httpHost)
    {
        AuthCache authCache = new BasicAuthCache();
        authCache.put(httpHost, new BasicScheme());

        HttpContext context = new BasicHttpContext();
        context.setAttribute(ClientContext.AUTH_CACHE, authCache);
        return context;
    }
1295145
@Override
    public String getContextPath() {
        if (SecurityUtil.isPackageProtectionEnabled()) {
            return (String) doPrivileged("getContextPath", null);
        } else {
            return context.getContextPath();
        }
    }
252739
public static void dumpServletContext( ServletContext context, PrintStream output )
    {
        if ( output == null )
        {
            output = System.err;
        }

        output.println( "*** ServletContext " + context );

        for ( Enumeration e = context.getAttributeNames(); e.hasMoreElements(); )
        {
            String name = ( String ) e.nextElement();
            output.println( "            attribute " + name + " = " + context.getAttribute( name ) );
        }
    }
253725
public static HttpServletResponse getHttpServletResponseFromExternalWebflowContext(final RequestContext context) {
        Assert.isInstanceOf(ServletExternalContext.class, context.getExternalContext(),
            "Cannot obtain HttpServletResponse from event of type: " + context.getExternalContext().getClass().getName());
        return (HttpServletResponse) context.getExternalContext().getNativeResponse();
    }
1187540
public ServletContext findContext(String path) {
        WebGroup g = (WebGroup) requestMapper.map(path);
        if (g != null)
            return g.getContext();
        else
            return null;
    }
1229583
protected void createSessionContext(DeployedModule moduleConfig) throws Throwable {
        try {
            // added sessionIdListeners for Servlet 3.1
            ArrayList sessionRelatedListeners[] = new ArrayList[] { sessionListeners, sessionAttrListeners, sessionIdListeners }; // cmd
            // PQ81253
            this.sessionCtx = ((WebGroup) parent).getSessionContext(moduleConfig, this, sessionRelatedListeners); // cmd
            // PQ81253
        } catch (Throwable th) {
            // pk435011
            logger.logp(Level.SEVERE, CLASS_NAME, "createSessionContext", "error.obtaining.session.context", th);
            throw new WebAppNotLoadedException(th.getMessage());
        }

    }
593869
public static URLTemplatesFactory getURLTemplatesFactory( ServletContext servletContext )
    {
        assert servletContext != null : "The ServletContext cannot be null.";

        if ( servletContext == null )
        {
            throw new IllegalArgumentException( "The ServletContext cannot be null." );
        }

        return ( URLTemplatesFactory ) servletContext.getAttribute( URL_TEMPLATE_FACTORY_ATTR );
    }
1016565
public ServletContextHandler getHandler() {
    ServletContextHandler contextHandler = new ServletContextHandler();
    contextHandler.setContextPath(SERVLET_PATH);
    contextHandler.addServlet(new ServletHolder(new MetricsServlet(mCollectorRegistry)), "/");
    return contextHandler;
  }