org.apache.catalina.Globals Java Examples

The following examples show how to use org.apache.catalina.Globals. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Check if sendfile can be used.
 */
protected boolean checkSendfile(HttpServletRequest request,
                              HttpServletResponse response,
                              CacheEntry entry,
                              long length, Range range) {
    if ((sendfileSize > 0)
        && (entry.resource != null)
        && ((length > sendfileSize) || (entry.resource.getContent() == null))
        && (entry.attributes.getCanonicalPath() != null)
        && (Boolean.TRUE.equals(request.getAttribute(Globals.SENDFILE_SUPPORTED_ATTR)))
        && (request.getClass().getName().equals("org.apache.catalina.connector.RequestFacade"))
        && (response.getClass().getName().equals("org.apache.catalina.connector.ResponseFacade"))) {
        request.setAttribute(Globals.SENDFILE_FILENAME_ATTR, entry.attributes.getCanonicalPath());
        if (range == null) {
            request.setAttribute(Globals.SENDFILE_FILE_START_ATTR, Long.valueOf(0L));
            request.setAttribute(Globals.SENDFILE_FILE_END_ATTR, Long.valueOf(length));
        } else {
            request.setAttribute(Globals.SENDFILE_FILE_START_ATTR, Long.valueOf(range.start));
            request.setAttribute(Globals.SENDFILE_FILE_END_ATTR, Long.valueOf(range.end + 1));
        }
        return true;
    }
    return false;
}
 
Example #2
Source File: ApplicationDispatcher.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Include the response from another resource in the current response.
 * Any runtime exception, IOException, or ServletException thrown by the
 * called servlet will be propagated to the caller.
 *
 * @param request The servlet request that is including this one
 * @param response The servlet response to be appended to
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet exception occurs
 */
@Override
public void include(ServletRequest request, ServletResponse response)
    throws ServletException, IOException
{
    if (Globals.IS_SECURITY_ENABLED) {
        try {
            PrivilegedInclude dp = new PrivilegedInclude(request,response);
            AccessController.doPrivileged(dp);
        } catch (PrivilegedActionException pe) {
            Exception e = pe.getException();

            if (e instanceof ServletException)
                throw (ServletException) e;
            throw (IOException) e;
        }
    } else {
        doInclude(request, response);
    }
}
 
Example #3
Source File: WebappClassLoaderBase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public boolean check(Permission permission) {
    if (!Globals.IS_SECURITY_ENABLED) {
        return true;
    }
    Policy currentPolicy = Policy.getPolicy();
    if (currentPolicy != null) {
        URL contextRootUrl = resources.getResource("/").getCodeBase();
        CodeSource cs = new CodeSource(contextRootUrl, (Certificate[]) null);
        PermissionCollection pc = currentPolicy.getPermissions(cs);
        if (pc.implies(permission)) {
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: ApplicationDispatcher.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Include the response from another resource in the current response.
 * Any runtime exception, IOException, or ServletException thrown by the
 * called servlet will be propagated to the caller.
 *
 * @param request The servlet request that is including this one
 * @param response The servlet response to be appended to
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet exception occurs
 */
@Override
public void include(ServletRequest request, ServletResponse response)
    throws ServletException, IOException
{
    if (Globals.IS_SECURITY_ENABLED) {
        try {
            PrivilegedInclude dp = new PrivilegedInclude(request,response);
            AccessController.doPrivileged(dp);
        } catch (PrivilegedActionException pe) {
            Exception e = pe.getException();

            if (e instanceof ServletException)
                throw (ServletException) e;
            throw (IOException) e;
        }
    } else {
        doInclude(request, response);
    }
}
 
Example #5
Source File: DefaultServlet.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Check if sendfile can be used.
 */
protected boolean checkSendfile(HttpServletRequest request,
                              HttpServletResponse response,
                              CacheEntry entry,
                              long length, Range range) {
    if ((sendfileSize > 0)
        && (entry.resource != null)
        && ((length > sendfileSize) || (entry.resource.getContent() == null))
        && (entry.attributes.getCanonicalPath() != null)
        && (Boolean.TRUE.equals(request.getAttribute(Globals.SENDFILE_SUPPORTED_ATTR)))
        && (request.getClass().getName().equals("org.apache.catalina.connector.RequestFacade"))
        && (response.getClass().getName().equals("org.apache.catalina.connector.ResponseFacade"))) {
        request.setAttribute(Globals.SENDFILE_FILENAME_ATTR, entry.attributes.getCanonicalPath());
        if (range == null) {
            request.setAttribute(Globals.SENDFILE_FILE_START_ATTR, Long.valueOf(0L));
            request.setAttribute(Globals.SENDFILE_FILE_END_ATTR, Long.valueOf(length));
        } else {
            request.setAttribute(Globals.SENDFILE_FILE_START_ATTR, Long.valueOf(range.start));
            request.setAttribute(Globals.SENDFILE_FILE_END_ATTR, Long.valueOf(range.end + 1));
        }
        return true;
    }
    return false;
}
 
Example #6
Source File: ApplicationContext.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Return the names of the context's initialization parameters, or an
 * empty enumeration if the context has no initialization parameters.
 */
@Override
public Enumeration<String> getInitParameterNames() {
    Set<String> names = new HashSet<String>();
    names.addAll(parameters.keySet());
    // Special handling for XML settings as these attributes will always be
    // available if they have been set on the context
    if (context.getTldValidation()) {
        names.add(Globals.JASPER_XML_VALIDATION_TLD_INIT_PARAM);
    }
    if (context.getXmlValidation()) {
        names.add(Globals.JASPER_XML_VALIDATION_INIT_PARAM);
    }
    if (!context.getXmlBlockExternal()) {
        names.add(Globals.JASPER_XML_BLOCK_EXTERNAL_INIT_PARAM);
    }
    return Collections.enumeration(names);
}
 
Example #7
Source File: OutputBuffer.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private static C2BConverter createConverter(final Charset charset) throws IOException {
    if (Globals.IS_SECURITY_ENABLED) {
        try {
            return AccessController.doPrivileged(new PrivilegedExceptionAction<C2BConverter>() {
                @Override
                public C2BConverter run() throws IOException {
                    return new C2BConverter(charset);
                }
            });
        } catch (PrivilegedActionException ex) {
            Exception e = ex.getException();
            if (e instanceof IOException) {
                throw (IOException) e;
            } else {
                throw new IOException(ex);
            }
        }
    } else {
        return new C2BConverter(charset);
    }
}
 
Example #8
Source File: DefaultServlet.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private File validateGlobalXsltFile() {
    
    File result = null;
    String base = System.getProperty(Globals.CATALINA_BASE_PROP);
    
    if (base != null) {
        File baseConf = new File(base, "conf");
        result = validateGlobalXsltFile(baseConf);
    }
    
    if (result == null) {
        String home = System.getProperty(Globals.CATALINA_HOME_PROP);
        if (home != null && !home.equals(base)) {
            File homeConf = new File(home, "conf");
            result = validateGlobalXsltFile(homeConf);
        }
    }

    return result;
}
 
Example #9
Source File: ReplicatedContext.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {

    try {
        CatalinaCluster catclust = (CatalinaCluster)this.getCluster();
        if (this.context == null) this.context = new ReplApplContext(this);
        if ( catclust != null ) {
            ReplicatedMap<String,Object> map =
                    new ReplicatedMap<String,Object>(this,
                            catclust.getChannel(),DEFAULT_REPL_TIMEOUT,
                            getName(),getClassLoaders());
            map.setChannelSendOptions(mapSendOptions);
            ((ReplApplContext)this.context).setAttributeMap(map);
            if (getAltDDName() != null) context.setAttribute(Globals.ALT_DD_ATTR, getAltDDName());
        }
        super.startInternal();
    }  catch ( Exception x ) {
        log.error("Unable to start ReplicatedContext",x);
        throw new LifecycleException("Failed to start ReplicatedContext",x);
    }
}
 
Example #10
Source File: AbstractAccessLogValve.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void addElement(CharArrayWriter buf, Date date, Request request,
        Response response, long time) {
    // Don't need to flush since trigger for log message is after the
    // response has been committed
    long length = response.getBytesWritten(false);
    if (length <= 0) {
        // Protect against nulls and unexpected types as these values
        // may be set by untrusted applications
        Object start = request.getAttribute(
                Globals.SENDFILE_FILE_START_ATTR);
        if (start instanceof Long) {
            Object end = request.getAttribute(
                    Globals.SENDFILE_FILE_END_ATTR);
            if (end instanceof Long) {
                length = ((Long) end).longValue() -
                        ((Long) start).longValue();
            }
        }
    }
    if (length <= 0 && conversion) {
        buf.append('-');
    } else {
        buf.append(Long.toString(length));
    }
}
 
Example #11
Source File: ApplicationContext.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Return the value of the specified initialization parameter, or
 * <code>null</code> if this parameter does not exist.
 *
 * @param name Name of the initialization parameter to retrieve
 */
@Override
public String getInitParameter(final String name) {
    // Special handling for XML settings as the context setting must
    // always override anything that might have been set by an application.
    if (Globals.JASPER_XML_VALIDATION_TLD_INIT_PARAM.equals(name) &&
            context.getTldValidation()) {
        return "true";
    }
    if (Globals.JASPER_XML_VALIDATION_INIT_PARAM.equals(name) &&
            context.getXmlValidation()) {
        return "true";
    }
    if (Globals.JASPER_XML_BLOCK_EXTERNAL_INIT_PARAM.equals(name)) {
        if (!context.getXmlBlockExternal()) {
            // System admin has explicitly changed the default
            return "false";
        }
    }
    return parameters.get(name);
}
 
Example #12
Source File: ApplicationHttpRequest.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Override the <code>setAttribute()</code> method of the
 * wrapped request.
 *
 * @param name Name of the attribute to set
 * @param value Value of the attribute to set
 */
@Override
public void setAttribute(String name, Object value) {

    if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
        dispatcherType = (DispatcherType)value;
        return;
    } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
        requestDispatcherPath = value;
        return;
    }

    if (!setSpecial(name, value)) {
        getRequest().setAttribute(name, value);
    }

}
 
Example #13
Source File: MongoAccessLogValve.java    From tomcat-mongo-access-log with Apache License 2.0 6 votes vote down vote up
@Override
public void addElement(StringBuilder buf, DBObject result, Date date, Request request,
        Response response, long time) {
    // Don't need to flush since trigger for log message is after the
    // response has been committed
    long length = response.getBytesWritten(false);
    if (length <= 0) {
        // Protect against nulls and unexpected types as these values
        // may be set by untrusted applications
        Object start = request.getAttribute(
                Globals.SENDFILE_FILE_START_ATTR);
        if (start instanceof Long) {
            Object end = request.getAttribute(
                    Globals.SENDFILE_FILE_END_ATTR);
            if (end instanceof Long) {
                length = ((Long) end).longValue() -
                        ((Long) start).longValue();
            }
        }
    }
    if (length <= 0 && conversion) {
        result.put("bytesSent", '-');
    } else {
        result.put("bytesSent", length);
    }
}
 
Example #14
Source File: DefaultServlet.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Check if sendfile can be used.
 * @param request The Servlet request
 * @param response The Servlet response
 * @param resource The resource
 * @param length The length which will be written (will be used only if
 *  range is null)
 * @param range The range that will be written
 * @return <code>true</code> if sendfile should be used (writing is then
 *  delegated to the endpoint)
 */
protected boolean checkSendfile(HttpServletRequest request,
                              HttpServletResponse response,
                              WebResource resource,
                              long length, Range range) {
    String canonicalPath;
    if (sendfileSize > 0
        && length > sendfileSize
        && (Boolean.TRUE.equals(request.getAttribute(Globals.SENDFILE_SUPPORTED_ATTR)))
        && (request.getClass().getName().equals("org.apache.catalina.connector.RequestFacade"))
        && (response.getClass().getName().equals("org.apache.catalina.connector.ResponseFacade"))
        && resource.isFile()
        && ((canonicalPath = resource.getCanonicalPath()) != null)
        ) {
        request.setAttribute(Globals.SENDFILE_FILENAME_ATTR, canonicalPath);
        if (range == null) {
            request.setAttribute(Globals.SENDFILE_FILE_START_ATTR, Long.valueOf(0L));
            request.setAttribute(Globals.SENDFILE_FILE_END_ATTR, Long.valueOf(length));
        } else {
            request.setAttribute(Globals.SENDFILE_FILE_START_ATTR, Long.valueOf(range.start));
            request.setAttribute(Globals.SENDFILE_FILE_END_ATTR, Long.valueOf(range.end + 1));
        }
        return true;
    }
    return false;
}
 
Example #15
Source File: DefaultServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private File validateGlobalXsltFile() {
    
    File result = null;
    String base = System.getProperty(Globals.CATALINA_BASE_PROP);
    
    if (base != null) {
        File baseConf = new File(base, "conf");
        result = validateGlobalXsltFile(baseConf);
    }
    
    if (result == null) {
        String home = System.getProperty(Globals.CATALINA_HOME_PROP);
        if (home != null && !home.equals(base)) {
            File homeConf = new File(home, "conf");
            result = validateGlobalXsltFile(homeConf);
        }
    }

    return result;
}
 
Example #16
Source File: AccessLogValve.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void addElement(StringBuilder buf, Date date, Request request,
        Response response, long time) {
    // Don't need to flush since trigger for log message is after the
    // response has been committed
    long length = response.getBytesWritten(false);
    if (length <= 0) {
        // Protect against nulls and unexpected types as these values
        // may be set by untrusted applications
        Object start = request.getAttribute(
                Globals.SENDFILE_FILE_START_ATTR);
        if (start instanceof Long) {
            Object end = request.getAttribute(
                    Globals.SENDFILE_FILE_END_ATTR);
            if (end instanceof Long) {
                length = ((Long) end).longValue() -
                        ((Long) start).longValue();
            }
        }
    }
    if (length <= 0 && conversion) {
        buf.append('-');
    } else {
        buf.append(length);
    }
}
 
Example #17
Source File: Introspection.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Obtain the declared fields for a class taking account of any security
 * manager that may be configured.
 */
public static Field[] getDeclaredFields(final Class<?> clazz) {
    Field[] fields = null;
    if (Globals.IS_SECURITY_ENABLED) {
        fields = AccessController.doPrivileged(
                new PrivilegedAction<Field[]>(){
            @Override
            public Field[] run(){
                return clazz.getDeclaredFields();
            }
        });
    } else {
        fields = clazz.getDeclaredFields();
    }
    return fields;
}
 
Example #18
Source File: ApplicationDispatcher.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Forward this request and response to another resource for processing.
 * Any runtime exception, IOException, or ServletException thrown by the
 * called servlet will be propagated to the caller.
 *
 * @param request The servlet request to be forwarded
 * @param response The servlet response to be forwarded
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet exception occurs
 */
@Override
public void forward(ServletRequest request, ServletResponse response)
    throws ServletException, IOException
{
    if (Globals.IS_SECURITY_ENABLED) {
        try {
            PrivilegedForward dp = new PrivilegedForward(request,response);
            AccessController.doPrivileged(dp);
        } catch (PrivilegedActionException pe) {
            Exception e = pe.getException();
            if (e instanceof ServletException)
                throw (ServletException) e;
            throw (IOException) e;
        }
    } else {
        doForward(request,response);
    }
}
 
Example #19
Source File: AsyncContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void run() {
    ClassLoader oldCL = context.bind(Globals.IS_SECURITY_ENABLED, null);
    try {
        wrapped.run();
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        context.getLogger().error(sm.getString("asyncContextImpl.asyncRunnableError"), t);
        coyoteRequest.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
        org.apache.coyote.Response coyoteResponse = coyoteRequest.getResponse();
        coyoteResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        coyoteResponse.setError();
    } finally {
        context.unbind(Globals.IS_SECURITY_ENABLED, oldCL);
    }

    // Since this runnable is not executing as a result of a socket
    // event, we need to ensure that any registered dispatches are
    // executed.
    coyoteRequest.action(ActionCode.DISPATCH_EXECUTE, null);
}
 
Example #20
Source File: AsyncContextImpl.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void fireOnComplete() {
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("asyncContextImpl.fireOnComplete"));
    }
    List<AsyncListenerWrapper> listenersCopy = new ArrayList<>();
    listenersCopy.addAll(listeners);

    ClassLoader oldCL = context.bind(Globals.IS_SECURITY_ENABLED, null);
    try {
        for (AsyncListenerWrapper listener : listenersCopy) {
            try {
                listener.fireOnComplete(event);
            } catch (Throwable t) {
                ExceptionUtils.handleThrowable(t);
                log.warn(sm.getString("asyncContextImpl.onCompleteError",
                        listener.getClass().getName()), t);
            }
        }
    } finally {
        context.fireRequestDestroyEvent(request.getRequest());
        clearServletRequestResponse();
        this.context.decrementInProgressAsyncCount();
        context.unbind(Globals.IS_SECURITY_ENABLED, oldCL);
    }
}
 
Example #21
Source File: ApplicationHttpRequest.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Set the request that we are wrapping.
 *
 * @param request The new wrapped request
 */
void setRequest(HttpServletRequest request) {

    super.setRequest(request);

    // Initialize the attributes for this request
    dispatcherType = (DispatcherType)request.getAttribute(Globals.DISPATCHER_TYPE_ATTR);
    requestDispatcherPath = request.getAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR);

    // Initialize the path elements for this request
    contextPath = request.getContextPath();
    pathInfo = request.getPathInfo();
    queryString = request.getQueryString();
    requestURI = request.getRequestURI();
    servletPath = request.getServletPath();
    if (request instanceof org.apache.catalina.servlet4preview.http.HttpServletRequest) {
        mapping = ((org.apache.catalina.servlet4preview.http.HttpServletRequest) request).getHttpServletMapping();
    } else {
        mapping = (new ApplicationMapping(null)).getHttpServletMapping();
    }
}
 
Example #22
Source File: ApplicationHttpRequest.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Override the <code>setAttribute()</code> method of the
 * wrapped request.
 *
 * @param name Name of the attribute to set
 * @param value Value of the attribute to set
 */
@Override
public void setAttribute(String name, Object value) {

    if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
        dispatcherType = (DispatcherType)value;
        return;
    } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
        requestDispatcherPath = value;
        return;
    }

    if (!setSpecial(name, value)) {
        getRequest().setAttribute(name, value);
    }

}
 
Example #23
Source File: ApplicationContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public String getInitParameter(final String name) {
    // Special handling for XML settings as the context setting must
    // always override anything that might have been set by an application.
    if (Globals.JASPER_XML_VALIDATION_TLD_INIT_PARAM.equals(name) &&
            context.getTldValidation()) {
        return "true";
    }
    if (Globals.JASPER_XML_BLOCK_EXTERNAL_INIT_PARAM.equals(name)) {
        if (!context.getXmlBlockExternal()) {
            // System admin has explicitly changed the default
            return "false";
        }
    }
    return parameters.get(name);
}
 
Example #24
Source File: TestSSLValve.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testSslCipherUserKeySizeHeaderPresent() throws Exception {
    Integer keySize = Integer.valueOf(452);
    mockRequest.setHeader(valve.getSslCipherUserKeySizeHeader(), String.valueOf(keySize));

    valve.invoke(mockRequest, null);

    Assert.assertEquals(keySize, mockRequest.getAttribute(Globals.KEY_SIZE_ATTR));
}
 
Example #25
Source File: ApplicationFilterChain.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Process the event, using the security manager if the option is enabled.
 * 
 * @param event the event to process
 * 
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet exception occurs
 */
@Override
public void doFilterEvent(CometEvent event)
    throws IOException, ServletException {

    if( Globals.IS_SECURITY_ENABLED ) {
        final CometEvent ev = event;
        try {
            java.security.AccessController.doPrivileged(
                new java.security.PrivilegedExceptionAction<Void>() {
                    @Override
                    public Void run() 
                        throws ServletException, IOException {
                        internalDoFilterEvent(ev);
                        return null;
                    }
                }
            );
        } catch( PrivilegedActionException pe) {
            Exception e = pe.getException();
            if (e instanceof ServletException)
                throw (ServletException) e;
            else if (e instanceof IOException)
                throw (IOException) e;
            else if (e instanceof RuntimeException)
                throw (RuntimeException) e;
            else
                throw new ServletException(e.getMessage(), e);
        }
    } else {
        internalDoFilterEvent(event);
    }
}
 
Example #26
Source File: FailedRequestFilter.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private boolean isGoodRequest(ServletRequest request) {
    // Trigger parsing of parameters
    request.getParameter("none");
    // Detect failure
    if (request.getAttribute(Globals.PARAMETER_PARSE_FAILED_ATTR) != null) {
        return false;
    }
    return true;
}
 
Example #27
Source File: WebappClassLoaderBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public boolean hasLoggingConfig() {
    if (Globals.IS_SECURITY_ENABLED) {
        Boolean result = AccessController.doPrivileged(new PrivilegedHasLoggingConfig());
        return result.booleanValue();
    } else {
        return findResource("logging.properties") != null;
    }
}
 
Example #28
Source File: ContextConfig.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
protected String getBaseDir() {
    Container engineC=context.getParent().getParent();
    if( engineC instanceof StandardEngine ) {
        return ((StandardEngine)engineC).getBaseDir();
    }
    return System.getProperty(Globals.CATALINA_BASE_PROP);
}
 
Example #29
Source File: ApplicationContext.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public Enumeration<String> getInitParameterNames() {
    Set<String> names = new HashSet<>();
    names.addAll(parameters.keySet());
    // Special handling for XML settings as these attributes will always be
    // available if they have been set on the context
    if (context.getTldValidation()) {
        names.add(Globals.JASPER_XML_VALIDATION_TLD_INIT_PARAM);
    }
    if (!context.getXmlBlockExternal()) {
        names.add(Globals.JASPER_XML_BLOCK_EXTERNAL_INIT_PARAM);
    }
    return Collections.enumeration(names);
}
 
Example #30
Source File: WebappLoader.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Stop associated {@link ClassLoader} and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void stopInternal() throws LifecycleException {

    if (log.isDebugEnabled())
        log.debug(sm.getString("webappLoader.stopping"));

    setState(LifecycleState.STOPPING);

    // Remove context attributes as appropriate
    if (container instanceof Context) {
        ServletContext servletContext =
            ((Context) container).getServletContext();
        servletContext.removeAttribute(Globals.CLASS_PATH_ATTR);
    }

    // Throw away our current class loader
    if (classLoader != null) {
        ((Lifecycle) classLoader).stop();
        DirContextURLStreamHandler.unbind(classLoader);
    }

    try {
        StandardContext ctx=(StandardContext)container;
        String contextName = ctx.getName();
        if (!contextName.startsWith("/")) {
            contextName = "/" + contextName;
        }
        ObjectName cloname = new ObjectName
            (MBeanUtils.getDomain(ctx) + ":type=WebappClassLoader,context="
             + contextName + ",host=" + ctx.getParent().getName());
        Registry.getRegistry(null, null).unregisterComponent(cloname);
    } catch (Exception e) {
        log.error("LifecycleException ", e);
    }

    classLoader = null;
}