StandardContext
.
*
- * @author Craig R. McClanahan
- * @author Remy Maucherat
- * @version $Revision: 1.15.2.1 $ $Date: 2008/04/17 18:37:06 $
+ * @author Craig R. McClanahan 2008
+ * @author Remy Maucherat 2008
*/
public class ApplicationContext implements ServletContext {
- // ----------------------------------------------------------- Constructors
-
private static final Logger log = LogFacade.getLogger();
private static final ResourceBundle rb = log.getResourceBundle();
-
- /**
- * Construct a new instance of this class, associated with the specified
- * Context instance.
- *
- * @param context The associated Context instance
- */
- public ApplicationContext(StandardContext context) {
- this.context = context;
-
- setAttribute("com.sun.faces.useMyFaces",
- Boolean.valueOf(context.isUseMyFaces()));
- }
-
- public StandardContext getStandardContext() {
- return context;
- }
-
-
- // ----------------------------------------------------- Instance Variables
-
- /**
- * The context attributes for this context.
- */
+ /** The context attributes for this context. */
private final Mapnull
.
- *
- * @param name Name of the context attribute to return
+ * @return the resources object that is mapped to a specified path.
+ * The path must begin with a "/" and is interpreted as relative
+ * to the current context root.
*/
+ public DirContext getResources() {
+ return context.getResources();
+ }
+
+
@Override
public Object getAttribute(String name) {
return attributes.get(name);
}
- /**
- * Return an enumeration of the names of the context attributes
- * associated with this context.
- */
+
@Override
public EnumerationThe context path is the portion of the request URI that is used - * to select the context of the request. The context path always comes - * first in a request URI. The path starts with a "/" character but does - * not end with a "/" character. For servlets in the default (root) - * context, this method returns "". - * - *
It is possible that a servlet container may match a context by
- * more than one context path. In such cases the
- * {@link jakarta.servlet.http.HttpServletRequest#getContextPath()}
- * will return the actual context path used by the request and it may
- * differ from the path returned by this method.
- * The context path returned by this method should be considered as the
- * prime or preferred context path of the application.
- *
- * @see jakarta.servlet.http.HttpServletRequest#getContextPath()
- */
+
@Override
public String getContextPath() {
return context.getPath();
}
- /**
- * Return a Return the Valve instance that has been distinguished as the basic
* Valve for this Pipeline (if any).
*/
+ @Override
public GlassFishValve getBasic() {
return (pipeline.getBasic());
}
@@ -1330,6 +1412,7 @@ public GlassFishValve getBasic() {
* Container, including the basic Valve (if any). If there are no
* such Valves, a zero-length array is returned.
*/
+ @Override
public GlassFishValve[] getValves() {
return (pipeline.getValves());
}
@@ -1339,6 +1422,7 @@ public GlassFishValve[] getValves() {
* @return true if this pipeline has any non basic valves, false
* otherwise
*/
+ @Override
public boolean hasNonBasicValves() {
return pipeline.hasNonBasicValves();
}
@@ -1350,6 +1434,7 @@ public boolean hasNonBasicValves() {
*
* @param valve Valve to be removed
*/
+ @Override
public synchronized void removeValve(GlassFishValve valve) {
pipeline.removeValve(valve);
@@ -1372,6 +1457,7 @@ public synchronized void removeValve(GlassFishValve valve) {
*
* @param valve Valve to be distinguished as the basic Valve
*/
+ @Override
public void setBasic(GlassFishValve valve) {
pipeline.setBasic(valve);
@@ -1384,6 +1470,7 @@ public void setBasic(GlassFishValve valve) {
* invoked inside the classloading context of this container. Unexpected
* throwables will be caught and logged.
*/
+ @Override
public void backgroundProcess() {
}
@@ -1399,6 +1486,7 @@ public void backgroundProcess() {
* @param type Event type
* @param data Event data
*/
+ @Override
public void fireContainerEvent(String type, Object data) {
ContainerListener[] list = null;
@@ -1411,8 +1499,8 @@ public void fireContainerEvent(String type, Object data) {
}
ContainerEvent event = new ContainerEvent(this, type, data);
- for (int i = 0; i < list.length; i++) {
- list[i].containerEvent(event);
+ for (ContainerListener listener : list) {
+ listener.containerEvent(event);
}
}
@@ -1423,17 +1511,17 @@ public void fireContainerEvent(String type, Object data) {
protected void startChildren() {
Container children[] = findChildren();
- for (int i = 0; i < children.length; i++) {
- if (children[i] instanceof Lifecycle) {
+ for (Container child : children) {
+ if (child instanceof Lifecycle) {
try {
- ((Lifecycle) children[i]).start();
+ ((Lifecycle) child).start();
} catch (Throwable t) {
- String msg = MessageFormat.format(rb.getString(LogFacade.CONTAINER_NOT_STARTED_EXCEPTION), children[i]);
+ String msg = MessageFormat.format(rb.getString(LogFacade.CONTAINER_NOT_STARTED_EXCEPTION), child);
log.log(Level.SEVERE, msg, t);
- if (children[i] instanceof Context) {
- ((Context) children[i]).setAvailable(false);
- } else if (children[i] instanceof Wrapper) {
- ((Wrapper) children[i]).setAvailable(Long.MAX_VALUE);
+ if (child instanceof Context) {
+ ((Context) child).setAvailable(false);
+ } else if (child instanceof Wrapper) {
+ ((Wrapper) child).setAvailable(Long.MAX_VALUE);
}
}
}
@@ -1466,9 +1554,9 @@ protected void log(String message) {
protected void log(String message, Throwable throwable) {
message = neutralizeForLog(message);
org.apache.catalina.Logger logger = getLogger();
- if (logger != null)
+ if (logger != null) {
logger.log(logName() + ": " + message, throwable);
- else {
+ } else {
log.log(Level.SEVERE, message, throwable);
}
@@ -1482,8 +1570,9 @@ protected String logName() {
String className = this.getClass().getName();
int period = className.lastIndexOf(".");
- if (period >= 0)
+ if (period >= 0) {
className = className.substring(period + 1);
+ }
return (className + "[" + getName() + "]");
}
@@ -1502,7 +1591,9 @@ public ObjectName getJmxName() {
public String getObjectName() {
if (oname != null) {
return oname.toString();
- } else return null;
+ } else {
+ return null;
+ }
}
public String getDomain() {
@@ -1543,8 +1634,9 @@ public ObjectName[] getChildren() {
public ObjectName createObjectName(String domain, ObjectName parent)
throws Exception
{
- if (log.isLoggable(Level.FINE))
+ if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, neutralizeForLog("Create ObjectName " + domain + " " + parent));
+ }
return null;
}
@@ -1570,7 +1662,9 @@ public String getContainerSuffix() {
String path=((StandardContext)context).getEncodedPath();
suffix.append(",path=").append((path.equals("")) ? "/" : path);
}
- if( host!=null ) suffix.append(",host=").append( host.getName() );
+ if( host!=null ) {
+ suffix.append(",host=").append( host.getName() );
+ }
if (servlet != null) {
String containerName = container.getName();
suffix.append(",servlet=");
@@ -1586,10 +1680,12 @@ public String getContainerSuffix() {
*/
protected void threadStart() {
- if (thread != null)
+ if (thread != null) {
return;
- if (backgroundProcessorDelay <= 0)
+ }
+ if (backgroundProcessorDelay <= 0) {
return;
+ }
threadDone = false;
String threadName = "ContainerBackgroundProcessor[" + toString() + "]";
@@ -1606,8 +1702,9 @@ protected void threadStart() {
*/
protected void threadStop() {
- if (thread == null)
+ if (thread == null) {
return;
+ }
threadDone = true;
thread.interrupt();
@@ -1631,6 +1728,7 @@ protected void threadStop() {
*/
protected class ContainerBackgroundProcessor implements Runnable {
+ @Override
public void run() {
while (!threadDone) {
try {
@@ -1663,9 +1761,9 @@ protected void processChildren(Container container, ClassLoader cl) {
Thread.currentThread().setContextClassLoader(cl);
}
Container[] children = container.findChildren();
- for (int i = 0; i < children.length; i++) {
- if (children[i].getBackgroundProcessorDelay() <= 0) {
- processChildren(children[i], cl);
+ for (Container child : children) {
+ if (child.getBackgroundProcessorDelay() <= 0) {
+ processChildren(child, cl);
}
}
}
diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardContext.java b/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardContext.java
index a9089fcbe73..b59f163b056 100644
--- a/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardContext.java
+++ b/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardContext.java
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 2023 Contributors to Eclipse Foundation.
- * Copyright (c) 1997-2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -210,11 +210,6 @@ public class StandardContext extends ContainerBase implements Context, ServletCo
*/
protected static final URLEncoder urlEncoder;
- /**
- * The descriptive information string for this implementation.
- */
- private static final String info = "org.apache.catalina.core.StandardContext/1.0";
-
private static final RuntimePermission GET_CLASSLOADER_PERMISSION = new RuntimePermission("getClassLoader");
/**
@@ -230,21 +225,6 @@ public class StandardContext extends ContainerBase implements Context, ServletCo
urlEncoder.addSafeCharacter('/');
}
- // ----------------------------------------------------------- Constructors
-
- /**
- * Create a new StandardContext component with the default basic Valve.
- */
- public StandardContext() {
- pipeline.setBasic(new StandardContextValve());
- namingResources.setContainer(this);
- if (Globals.IS_SECURITY_ENABLED) {
- mySecurityManager = AccessController.doPrivileged(new PrivilegedCreateSecurityManager());
- }
- }
-
- // ----------------------------------------------------- Instance Variables
-
/**
* The alternate deployment descriptor name.
*/
@@ -536,7 +516,7 @@ public StandardContext() {
/**
* The notification sequence number.
*/
- private long sequenceNumber = 0;
+ private long sequenceNumber;
/**
* The status code error pages for this web application, keyed by HTTP status code (as an Integer).
@@ -599,7 +579,7 @@ public StandardContext() {
/**
* Iteration count for background processing.
*/
- private int count = 0;
+ private int count;
/**
* Caching allowed flag.
@@ -619,7 +599,7 @@ public StandardContext() {
/**
* Cache max size in KB.
*/
- protected int cacheMaxSize = 10240; // 10 MB
+ protected int cacheMaxSize = 10_240; // 10 MB
/**
* Cache TTL in ms.
@@ -631,20 +611,19 @@ public StandardContext() {
*/
private DirContext webappResources;
- /*
+ /**
* Time (in milliseconds) it took to start this context
*/
private long startupTime;
- /*
+ /**
* Time (in milliseconds since January 1, 1970, 00:00:00) when this context was started
*/
private long startTimeMillis;
private long tldScanTime;
- // Should the filter and security mapping be done
- // in a case sensitive manner
+ /** Should the filter and security mapping be done in a case sensitive manner */
protected boolean caseSensitiveMapping = true;
/**
@@ -741,28 +720,30 @@ public StandardContext() {
*/
private List
- * If any of the specified URL patterns are already mapped to a different Servlet, no updates will be performed.
+ * If any of the specified URL patterns are already mapped to a different Servlet, no updates
+ * will be performed.
*
* @param servletMap the Servlet mappings containing the Servlet name and URL patterns
- *
- * @return the (possibly empty) Set of URL patterns that are already mapped to a different Servlet
- *
- * @exception IllegalArgumentException if the specified servlet name is not known to this Context
+ * @return (possibly empty) Set of URL patterns that are already mapped to a different Servlet
+ * @throws IllegalArgumentException if the specified servlet name is not known to this Context
*/
public Set
- * If any of the specified URL patterns are already mapped to a different Servlet, no updates will be performed.
+ * If any of the specified URL patterns are already mapped to a different Servlet, no updates
+ * will be performed.
*
* @param name the Servlet name
* @param urlPatterns the URL patterns
- *
- * @return the (possibly empty) Set of URL patterns that are already mapped to a different Servlet
- *
- * @exception IllegalArgumentException if the specified servlet name is not known to this Context
+ * @return (possibly empty) Set of URL patterns that are already mapped to a different Servlet
+ * @throws IllegalArgumentException if the specified servlet name is not known to this Context
*/
public Set
- * In order to add any URL patterns that will be mapped to the given servlet, addServletMappings must be used. If this
- * context has already been started, the URL patterns must be passed to addServlet instead.
- *
- * @param servletName the servlet name
- * @param instance the servlet instance
- * @param initParams Map containing the initialization parameters for the servlet
- *
- * @throws ServletException if the servlet fails to be initialized
- */
+
@Override
public ServletRegistration.Dynamic addServlet(String servletName, Servlet instance, Map
- * A default error page is an error page that was declared without any exception-type and error-code.
- *
- * @return the default error page of this context, or null if this context does not have any default error page
- */
@Override
public ErrorPage getDefaultErrorPage() {
return defaultErrorPage;
}
- /**
- * Return the filter definition for the specified filter name, if any; otherwise return
- * IMPLEMENTATION NOTE: This method is designed to deal with reloads required by changes to classes in the
- * underlying repositories of our class loader. It does not handle changes to the web application deployment descriptor.
- * If that has occurred, you should stop this Context and create (and start) a new Context instance instead.
+ * IMPLEMENTATION NOTE: This method is designed to deal with reloads required by changes
+ * to classes in the underlying repositories of our class loader. It does not handle changes to
+ * the web application deployment descriptor.
+ * If that has occurred, you should stop this Context and create (and start) a new Context
+ * instance instead.
*
- * @exception IllegalStateException if the ServletContext
object that corresponds to a
- * specified URI on the server. This method allows servlets to gain
- * access to the context for various parts of the server, and as needed
- * obtain RequestDispatcher
objects or resources from the
- * context. The given path must be absolute (beginning with a "/"),
- * and is interpreted based on our virtual host's document root.
- *
- * @param uri Absolute URI of a resource on the server
- */
+
@Override
public ServletContext getContext(String uri) {
return context.getContext(uri);
}
- /**
- * Return the value of the specified initialization parameter, or
- * null
if this parameter does not exist.
- *
- * @param name Name of the initialization parameter to retrieve
- */
+
@Override
public String getInitParameter(final String name) {
return parameters.get(name);
}
- /**
- * Return the names of the context's initialization parameters, or an
- * empty enumeration if the context has no initialization parameters.
- */
+
@Override
public Enumerationnull
if
- * the MIME type cannot be determined.
- *
- * @param file Filename for which to identify a MIME type
- */
+
@Override
public String getMimeType(String file) {
return context.getMimeType(file);
}
- /**
- * Return a RequestDispatcher
object that acts as a
- * wrapper for the named servlet.
- *
- * @param name Name of the servlet for which a dispatcher is requested
- */
+
@Override
public RequestDispatcher getNamedDispatcher(String name) {
return context.getNamedDispatcher(name);
}
- /**
- * @param path The virtual path to be translated
- *
- * @return the real path corresponding to the given virtual path, or
- * null
if the container was unable to perform the
- * translation
- */
+
@Override
public String getRealPath(String path) {
return context.getRealPath(path);
}
- /**
- * Return a RequestDispatcher
instance that acts as a
- * wrapper for the resource at the given path. The path must begin
- * with a "/" or be empty, and is interpreted as relative to the current
- * context root.
- *
- * @param path The path to the desired resource.
- */
+
@Override
public RequestDispatcher getRequestDispatcher(String path) {
return context.getRequestDispatcher(path);
}
- /**
- * Return the URL to the resource that is mapped to a specified path.
- * The path must begin with a "/" and is interpreted as relative to the
- * current context root.
- *
- * @param path The path to the desired resource
- *
- * @exception MalformedURLException if the path is not given
- * in the correct form
- */
+
@Override
- public URL getResource(String path)
- throws MalformedURLException {
+ public URL getResource(String path) throws MalformedURLException {
return context.getResource(path);
}
- /**
- * Return the requested resource as an InputStream
. The
- * path must be specified according to the rules described under
- * getResource
. If no such resource can be identified,
- * return null
.
- *
- * @param path The path to the desired resource.
- */
+
@Override
public InputStream getResourceAsStream(String path) {
return context.getResourceAsStream(path);
}
- /**
- * Return a Set containing the resource paths of resources member of the
- * specified collection. Each path will be a String starting with
- * a "/" character. The returned set is immutable.
- *
- * @param path Collection path
- */
+
@Override
public Set<jsp-config>
related configuration
- * that was aggregated from the web.xml
and
- * web-fragment.xml
descriptor files of the web application
- * represented by this ServletContext.
- */
+
@Override
public JspConfigDescriptor getJspConfigDescriptor() {
return context.getJspConfigDescriptor();
}
+
@Override
public ClassLoader getClassLoader() {
return context.getClassLoader();
}
+
@Override
public void declareRoles(String... roleNames) {
if (isRestricted) {
- throw new UnsupportedOperationException(
- rb.getString(LogFacade.UNSUPPORTED_OPERATION_EXCEPTION));
+ throw new UnsupportedOperationException(rb.getString(LogFacade.UNSUPPORTED_OPERATION_EXCEPTION));
}
context.declareRoles(roleNames);
}
+
@Override
public String getVirtualServerName() {
return context.getVirtualServerName();
}
+
@Override
public int getSessionTimeout() {
return context.getSessionTimeout();
}
+
@Override
public void setSessionTimeout(int sessionTimeout) {
if (isRestricted) {
- throw new UnsupportedOperationException(
- rb.getString(LogFacade.UNSUPPORTED_OPERATION_EXCEPTION));
+ throw new UnsupportedOperationException(rb.getString(LogFacade.UNSUPPORTED_OPERATION_EXCEPTION));
}
context.setSessionTimeout(sessionTimeout);
}
+
@Override
public String getRequestCharacterEncoding() {
return context.getRequestCharacterEncoding();
}
+
@Override
public void setRequestCharacterEncoding(String encoding) {
if (isRestricted) {
- throw new UnsupportedOperationException(
- rb.getString(LogFacade.UNSUPPORTED_OPERATION_EXCEPTION));
+ throw new UnsupportedOperationException(rb.getString(LogFacade.UNSUPPORTED_OPERATION_EXCEPTION));
}
context.setRequestCharacterEncoding(encoding);
}
+
@Override
public String getResponseCharacterEncoding() {
return context.getResponseCharacterEncoding();
}
+
@Override
public void setResponseCharacterEncoding(String encoding) {
if (isRestricted) {
- throw new UnsupportedOperationException(
- rb.getString(LogFacade.UNSUPPORTED_OPERATION_EXCEPTION));
+ throw new UnsupportedOperationException(rb.getString(LogFacade.UNSUPPORTED_OPERATION_EXCEPTION));
}
context.setResponseCharacterEncoding(encoding);
}
- // -------------------------------------------------------- Package Methods
-
/**
* Clear all application-created attributes.
*/
@@ -923,12 +644,6 @@ void clearAttributes() {
}
}
- /**
- * Return the facade associated with this ApplicationContext.
- */
- protected ServletContext getFacade() {
- return this.facade;
- }
/**
* Set an attribute as read only.
@@ -941,6 +656,7 @@ void setAttributeReadOnly(String name) {
}
}
+
void setRestricted(boolean isRestricted) {
this.isRestricted = isRestricted;
}
diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/core/ApplicationContextFacade.java b/appserver/web/web-core/src/main/java/org/apache/catalina/core/ApplicationContextFacade.java
index 6649136fae7..9274c550309 100644
--- a/appserver/web/web-core/src/main/java/org/apache/catalina/core/ApplicationContextFacade.java
+++ b/appserver/web/web-core/src/main/java/org/apache/catalina/core/ApplicationContextFacade.java
@@ -53,9 +53,7 @@
*/
public final class ApplicationContextFacade implements ServletContext {
- /**
- * Wrapped application context.
- */
+ /** Wrapped application context. */
private final ApplicationContext context;
/**
@@ -107,20 +105,12 @@ public int getMinorVersion() {
}
- /**
- * Gets the major version of the Servlet specification that the
- * application represented by this ServletContext is based on.
- */
@Override
public int getEffectiveMajorVersion() {
return context.getEffectiveMajorVersion();
}
- /**
- * Gets the minor version of the Servlet specification that the
- * application represented by this ServletContext is based on.
- */
@Override
public int getEffectiveMinorVersion() {
return context.getEffectiveMinorVersion();
@@ -256,12 +246,7 @@ public Enumeration<jsp-config>
related configuration
- * that was aggregated from the web.xml
and
- * web-fragment.xml
descriptor files of the web application
- * represented by this ServletContext.
- */
@Override
public JspConfigDescriptor getJspConfigDescriptor() {
if (IS_SECURITY_ENABLED) {
diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/core/ContainerBase.java b/appserver/web/web-core/src/main/java/org/apache/catalina/core/ContainerBase.java
index ccd0b8deae7..d94dd6766e6 100644
--- a/appserver/web/web-core/src/main/java/org/apache/catalina/core/ContainerBase.java
+++ b/appserver/web/web-core/src/main/java/org/apache/catalina/core/ContainerBase.java
@@ -1,5 +1,6 @@
/*
- * Copyright (c) 1997-2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023 Contributors to the Eclipse Foundation
+ * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,34 +18,41 @@
package org.apache.catalina.core;
+import jakarta.servlet.ServletException;
+
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.util.*;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.ResourceBundle;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.text.MessageFormat;
+
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.naming.directory.DirContext;
-import jakarta.servlet.ServletException;
-import static com.sun.logging.LogCleanerUtil.neutralizeForLog;
import org.apache.catalina.Container;
import org.apache.catalina.ContainerEvent;
import org.apache.catalina.ContainerListener;
import org.apache.catalina.Context;
import org.apache.catalina.Globals;
-import org.apache.catalina.LogFacade;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Loader;
+import org.apache.catalina.LogFacade;
import org.apache.catalina.Manager;
import org.apache.catalina.Pipeline;
import org.apache.catalina.Realm;
@@ -56,6 +64,8 @@
import org.apache.naming.resources.ProxyDirContext;
import org.glassfish.web.valve.GlassFishValve;
+import static com.sun.logging.LogCleanerUtil.neutralizeForLog;
+
/**
* Abstract implementation of the Container interface, providing common
@@ -134,12 +144,13 @@ public abstract class ContainerBase
protected class PrivilegedAddChild
implements PrivilegedAction<description>/<version>
.
*/
+ @Override
public String getInfo() {
return this.getClass().getName();
}
@@ -356,18 +370,21 @@ public String getInfo() {
* no associated Loader, return the Loader associated with our parent
* Container (if any); otherwise, return null
.
*/
+ @Override
public Loader getLoader() {
try {
readLock.lock();
- if (loader != null)
+ if (loader != null) {
return (loader);
+ }
} finally {
readLock.unlock();
}
- if (parent != null)
+ if (parent != null) {
return (parent.getLoader());
+ }
return (null);
}
@@ -378,6 +395,7 @@ public Loader getLoader() {
*
* @param loader The newly associated loader
*/
+ @Override
public void setLoader(Loader loader) {
Loader oldLoader;
@@ -387,8 +405,9 @@ public void setLoader(Loader loader) {
// Change components if necessary
oldLoader = this.loader;
- if (oldLoader == loader)
+ if (oldLoader == loader) {
return;
+ }
this.loader = loader;
// Stop the old component if necessary
@@ -402,8 +421,9 @@ public void setLoader(Loader loader) {
}
// Start the new component if necessary
- if (loader != null)
+ if (loader != null) {
loader.setContainer(this);
+ }
if (started && (loader != null) &&
(loader instanceof Lifecycle)) {
try {
@@ -427,18 +447,21 @@ public void setLoader(Loader loader) {
* no associated Logger, return the Logger associated with our parent
* Container (if any); otherwise return null
.
*/
+ @Override
public org.apache.catalina.Logger getLogger() {
try {
readLock.lock();
- if (logger != null)
+ if (logger != null) {
return (logger);
+ }
} finally {
readLock.unlock();
}
- if (parent != null)
+ if (parent != null) {
return (parent.getLogger());
+ }
return (null);
}
@@ -449,6 +472,7 @@ public org.apache.catalina.Logger getLogger() {
*
* @param logger The newly associated Logger
*/
+ @Override
public void setLogger(org.apache.catalina.Logger logger) {
org.apache.catalina.Logger oldLogger;
@@ -457,8 +481,9 @@ public void setLogger(org.apache.catalina.Logger logger) {
writeLock.lock();
// Change components if necessary
oldLogger = this.logger;
- if (oldLogger == logger)
+ if (oldLogger == logger) {
return;
+ }
this.logger = logger;
// Stop the old component if necessary
@@ -473,8 +498,9 @@ public void setLogger(org.apache.catalina.Logger logger) {
// Start the new component if necessary
- if (logger != null)
+ if (logger != null) {
logger.setContainer(this);
+ }
if (started && (logger != null) &&
(logger instanceof Lifecycle)) {
try {
@@ -498,18 +524,21 @@ public void setLogger(org.apache.catalina.Logger logger) {
* no associated Manager, return the Manager associated with our parent
* Container (if any); otherwise return null
.
*/
+ @Override
public Manager getManager() {
try {
readLock.lock();
- if (manager != null)
+ if (manager != null) {
return (manager);
+ }
} finally {
readLock.unlock();
}
- if (parent != null)
+ if (parent != null) {
return (parent.getManager());
+ }
return (null);
}
@@ -520,6 +549,7 @@ public Manager getManager() {
*
* @param manager The newly associated Manager
*/
+ @Override
public void setManager(Manager manager) {
Manager oldManager;
@@ -528,8 +558,9 @@ public void setManager(Manager manager) {
writeLock.lock();
// Change components if necessary
oldManager = this.manager;
- if (oldManager == manager)
+ if (oldManager == manager) {
return;
+ }
this.manager = manager;
// Stop the old component if necessary
@@ -543,8 +574,9 @@ public void setManager(Manager manager) {
}
// Start the new component if necessary
- if (manager != null)
+ if (manager != null) {
manager.setContainer(this);
+ }
if (started && (manager != null) &&
(manager instanceof Lifecycle)) {
try {
@@ -565,6 +597,7 @@ public void setManager(Manager manager) {
/**
* Return an object which may be utilized for mapping to this component.
*/
+ @Override
public Object getMappingObject() {
return this;
}
@@ -575,6 +608,7 @@ public Object getMappingObject() {
* Container. Within the set of child containers belonging to a particular
* parent, Container names must be unique.
*/
+ @Override
public String getName() {
return (name);
@@ -592,6 +626,7 @@ public String getName() {
* added to the children of a parent Container (after which the name
* may not be changed)
*/
+ @Override
public void setName(String name) {
String oldName = this.name;
@@ -604,6 +639,7 @@ public void setName(String name) {
* Return the Container for which this Container is a child, if there is
* one. If there is no defined parent, return null
.
*/
+ @Override
public Container getParent() {
return (parent);
@@ -621,6 +657,7 @@ public Container getParent() {
* @exception IllegalArgumentException if this Container refuses to become
* attached to the specified Container
*/
+ @Override
public void setParent(Container container) {
Container oldParent = this.parent;
@@ -634,9 +671,11 @@ public void setParent(Container container) {
* This call is meaningful only after a Loader has
* been configured.
*/
+ @Override
public ClassLoader getParentClassLoader() {
- if (parentClassLoader != null)
+ if (parentClassLoader != null) {
return (parentClassLoader);
+ }
if (parent != null) {
return (parent.getParentClassLoader());
}
@@ -653,6 +692,7 @@ public ClassLoader getParentClassLoader() {
*
* @param parent The new parent class loader
*/
+ @Override
public void setParentClassLoader(ClassLoader parent) {
ClassLoader oldParentClassLoader = this.parentClassLoader;
this.parentClassLoader = parent;
@@ -665,8 +705,9 @@ public void setParentClassLoader(ClassLoader parent) {
* Return the Pipeline object that manages the Valves associated with
* this Container.
*/
+ @Override
public Pipeline getPipeline() {
- return (this.pipeline);
+ return this.pipeline;
}
@@ -674,6 +715,7 @@ public Pipeline getPipeline() {
* @return true if this container was configured with a custom pipeline,
* false otherwise
*/
+ @Override
public boolean hasCustomPipeline() {
return hasCustomPipeline;
}
@@ -686,6 +728,7 @@ public boolean hasCustomPipeline() {
*
* @return true if the check is required; false otherwise.
*/
+ @Override
public boolean isCheckIfRequestIsSecure() {
return checkIfRequestIsSecure;
}
@@ -701,6 +744,7 @@ public boolean isCheckIfRequestIsSecure() {
* @param checkIfRequestIsSecure true if check is required, false
* otherwise
*/
+ @Override
public void setCheckIfRequestIsSecure(boolean checkIfRequestIsSecure) {
this.checkIfRequestIsSecure = checkIfRequestIsSecure;
}
@@ -711,17 +755,20 @@ public void setCheckIfRequestIsSecure(boolean checkIfRequestIsSecure) {
* no associated Realm, return the Realm associated with our parent
* Container (if any); otherwise return null
.
*/
+ @Override
public Realm getRealm() {
try {
readLock.lock();
- if (realm != null)
+ if (realm != null) {
return (realm);
+ }
} finally {
readLock.unlock();
}
- if (parent != null)
+ if (parent != null) {
return (parent.getRealm());
+ }
return (null);
}
@@ -732,6 +779,7 @@ public Realm getRealm() {
*
* @param realm The newly associated Realm
*/
+ @Override
public void setRealm(Realm realm) {
Realm oldRealm;
@@ -740,8 +788,9 @@ public void setRealm(Realm realm) {
writeLock.lock();
// Change components if necessary
oldRealm = this.realm;
- if (oldRealm == realm)
+ if (oldRealm == realm) {
return;
+ }
this.realm = realm;
// Stop the old component if necessary
@@ -755,8 +804,9 @@ public void setRealm(Realm realm) {
}
// Start the new component if necessary
- if (realm != null)
+ if (realm != null) {
realm.setContainer(this);
+ }
if (started && (realm != null) &&
(realm instanceof Lifecycle)) {
try {
@@ -780,18 +830,21 @@ public void setRealm(Realm realm) {
* resources associated with our parent Container (if any); otherwise
* return null
.
*/
+ @Override
public DirContext getResources() {
try {
readLock.lock();
- if (resources != null)
+ if (resources != null) {
return (resources);
+ }
} finally {
readLock.unlock();
}
- if (parent != null)
+ if (parent != null) {
return (parent.getResources());
+ }
return (null);
}
@@ -803,6 +856,7 @@ public DirContext getResources() {
*
* @param resources The newly associated DirContext
*/
+ @Override
public void setResources(DirContext resources) throws Exception {
// Called from StandardContext.setResources()
// <- StandardContext.start()
@@ -814,11 +868,13 @@ public void setResources(DirContext resources) throws Exception {
try {
writeLock.lock();
oldResources = this.resources;
- if (oldResources == resources)
+ if (oldResources == resources) {
return;
- Hashtablejsp-config
element related info aggregated from web.xml and web-fragment.xml */
private JspConfigDescriptor jspConfigDesc;
- // ServletContextListeners may be registered (via ServletContext#addListener) only within the scope of
- // ServletContainerInitializer#onStartup
+ /**
+ * ServletContextListeners may be registered (via ServletContext#addListener) only within
+ * the scope of ServletContainerInitializer#onStartup
+ */
private boolean isProgrammaticServletContextListenerRegistrationAllowed;
- /*
+ /**
* Security manager responsible for enforcing permission check on ServletContext#getClassLoader
*/
private MySecurityManager mySecurityManager;
- // Iterable over all ServletContainerInitializers that were discovered
+ /** Iterable over all ServletContainerInitializers that were discovered */
private ServiceLoader<description>/<version>
.
- */
@Override
public String getInfo() {
- return info;
- }
-
- public void setJvmRoute(String jvmRoute) {
- this.jvmRoute = jvmRoute;
+ return "org.apache.catalina.core.StandardContext/1.0";
}
public String getJvmRoute() {
return jvmRoute;
}
+ public void setJvmRoute(String jvmRoute) {
+ this.jvmRoute = jvmRoute;
+ }
+
public String getEngineName() {
if (engineName != null) {
return engineName;
}
-
return domain;
}
@@ -1365,19 +1262,11 @@ public void setEEServer(String eeServer) {
this.eeServer = eeServer;
}
- /**
- * Return the login configuration descriptor for this web application.
- */
@Override
public LoginConfig getLoginConfig() {
return loginConfig;
}
- /**
- * Set the login configuration descriptor for this web application.
- *
- * @param config The new login configuration
- */
@Override
public void setLoginConfig(LoginConfig config) {
// Validate the incoming property value
@@ -1411,9 +1300,6 @@ public void setLoginConfig(LoginConfig config) {
support.firePropertyChange("loginConfig", oldLoginConfig, this.loginConfig);
}
- /**
- * Get the mapper associated with the context.
- */
@Override
public Mapper getMapper() {
return mapper;
@@ -1430,19 +1316,11 @@ public void restrictedSetPipeline(Pipeline pipeline) {
}
}
- /**
- * Return the naming resources associated with this web application.
- */
@Override
public NamingResources getNamingResources() {
return namingResources;
}
- /**
- * Set the naming resources for this web application.
- *
- * @param namingResources The new naming resources
- */
@Override
public void setNamingResources(NamingResources namingResources) {
// Process the property setting change
@@ -1451,9 +1329,6 @@ public void setNamingResources(NamingResources namingResources) {
support.firePropertyChange("namingResources", oldNamingResources, this.namingResources);
}
- /**
- * Return the context path for this Context.
- */
@Override
public String getPath() {
return getName();
@@ -1472,19 +1347,11 @@ public void setPath(String path) {
setName(urlDecode(path, "UTF-8"));
}
- /**
- * Return the public identifier of the deployment descriptor DTD that is currently being parsed.
- */
@Override
public String getPublicId() {
return publicId;
}
- /**
- * Set the public identifier of the deployment descriptor DTD that is currently being parsed.
- *
- * @param publicId The public identifier
- */
@Override
public void setPublicId(String publicId) {
log.log(FINEST, () -> "Setting deployment descriptor public ID to '" + publicId + "'");
@@ -1494,33 +1361,31 @@ public void setPublicId(String publicId) {
support.firePropertyChange("publicId", oldPublicId, publicId);
}
- /**
- * Return the reloadable flag for this web application.
- */
@Override
public boolean getReloadable() {
return reloadable;
}
- /**
- * Return the DefaultContext override flag for this web application.
- */
@Override
public boolean getOverride() {
return override;
}
+
/**
- * Gets the original document root for this Context, which can be an absolute pathname, a relative pathname, or a URL.
+ * Gets the original document root for this Context, which can be an absolute pathname,
+ * a relative pathname, or a URL. Set only if deployment has changed the docRoot!
*
- * Is only set as deployment has change docRoot!
+ * @return the original document root for this Context or null
*/
public String getOriginalDocBase() {
return originalDocBase;
}
+
/**
- * Set the original document root for this Context, which can be an absolute pathname, a relative pathname, or a URL.
+ * Set the original document root for this Context, which can be an absolute pathname,
+ * a relative pathname, or a URL.
*
* @param docBase The original document root
*/
@@ -1528,19 +1393,11 @@ public void setOriginalDocBase(String docBase) {
this.originalDocBase = docBase;
}
- /**
- * Return the privileged flag for this web application.
- */
@Override
public boolean getPrivileged() {
return privileged;
}
- /**
- * Set the privileged flag for this web application.
- *
- * @param privileged The new privileged flag
- */
@Override
public void setPrivileged(boolean privileged) {
boolean oldPrivileged = this.privileged;
@@ -1548,11 +1405,6 @@ public void setPrivileged(boolean privileged) {
support.firePropertyChange("privileged", oldPrivileged, this.privileged);
}
- /**
- * Set the reloadable flag for this web application.
- *
- * @param reloadable The new reloadable flag
- */
@Override
public void setReloadable(boolean reloadable) {
boolean oldReloadable = this.reloadable;
@@ -1560,11 +1412,6 @@ public void setReloadable(boolean reloadable) {
support.firePropertyChange("reloadable", oldReloadable, this.reloadable);
}
- /**
- * Set the DefaultContext override flag for this web application.
- *
- * @param override The new override flag
- */
@Override
public void setOverride(boolean override) {
boolean oldOverride = this.override;
@@ -1580,35 +1427,18 @@ public boolean isJsfApplication() {
return isJsfApplication;
}
- /**
- * Indicates whether this web module contains any ad-hoc paths.
- *
- * An ad-hoc path is a servlet path that is mapped to a servlet not declared in the web module's deployment descriptor.
- *
- * A web module all of whose mappings are for ad-hoc paths is called an ad-hoc web module.
- *
- * @return true if this web module contains any ad-hoc paths, false otherwise
- */
@Override
public boolean hasAdHocPaths() {
return false;
}
- /**
- * Returns the name of the ad-hoc servlet responsible for servicing the given path.
- *
- * @param path The path to service
- *
- * @return The name of the ad-hoc servlet responsible for servicing the given path, or null if the given path is not an
- * ad-hoc path
- */
@Override
public String getAdHocServletName(String path) {
return null;
}
/**
- * Return the "replace welcome files" property.
+ * @return the "replace welcome files" property.
*/
public boolean isReplaceWelcomeFiles() {
return replaceWelcomeFiles;
@@ -1625,25 +1455,11 @@ public void setReplaceWelcomeFiles(boolean replaceWelcomeFiles) {
support.firePropertyChange("replaceWelcomeFiles", oldReplaceWelcomeFiles, this.replaceWelcomeFiles);
}
- /**
- * Returns the value of the securePagesWithPragma property.
- */
@Override
public boolean isSecurePagesWithPragma() {
return securePagesWithPragma;
}
- /**
- * Sets the securePagesWithPragma property of this Context.
- *
- * Setting this property to true will result in Pragma and Cache-Control headers with a value of "No-cache" if proxy
- * caching has been disabled.
- *
- * Setting this property to false will not add any Pragma header, but will set the Cache-Control header to "private".
- *
- * @param securePagesWithPragma true if Pragma and Cache-Control headers are to be set to "No-cache" if proxy caching
- * has been disabled, false otherwise
- */
@Override
public void setSecurePagesWithPragma(boolean securePagesWithPragma) {
boolean oldSecurePagesWithPragma = this.securePagesWithPragma;
@@ -1659,9 +1475,6 @@ public boolean isUseMyFaces() {
return useMyFaces;
}
- /**
- * Return the servlet context for which this Context is a facade.
- */
@Override
public ServletContext getServletContext() {
if (context == null) {
@@ -1675,47 +1488,38 @@ public ServletContext getServletContext() {
return context.getFacade();
}
- /**
- * Return the default session timeout (in minutes) for this web application.
- */
@Override
public int getSessionTimeout() {
return sessionTimeout;
}
+
/**
- * Is the session timeout (in minutes) for this web application over-ridden from the default HERCULES:add
+ * @return true if the session timeout (in minutes) for this web application over-ridden from
+ * the default HERCULES:add
*/
public boolean isSessionTimeoutOveridden() {
return sessionTimeoutOveridden;
}
- /**
- * Set the default session timeout (in minutes) for this web application.
- *
- * @param timeout The new default session timeout
- */
@Override
public void setSessionTimeout(int timeout) {
if (isContextInitializedCalled) {
- throw new IllegalStateException(format(
- rb.getString(SERVLET_CONTEXT_ALREADY_INIT_EXCEPTION),
- new Object[] { "setSessionTimeout", getName() }));
+ throw new IllegalStateException(format(rb.getString(SERVLET_CONTEXT_ALREADY_INIT_EXCEPTION),
+ new Object[] {"setSessionTimeout", getName()}));
}
int oldSessionTimeout = this.sessionTimeout;
- /*
- * SRV.13.4 ("Deployment Descriptor"): If the timeout is 0 or less, the container ensures the default behaviour of
- * sessions is never to time out.
- */
+ // SRV.13.4 ("Deployment Descriptor"): If the timeout is 0 or less, the container ensures
+ // the default behaviour of sessions is never to time out.
this.sessionTimeout = timeout == 0 ? -1 : timeout;
support.firePropertyChange("sessionTimeout", oldSessionTimeout, this.sessionTimeout);
sessionTimeoutOveridden = true;
}
/**
- * Return the value of the unloadDelay flag.
+ * @return the value of the unloadDelay flag.
*/
public long getUnloadDelay() {
return unloadDelay;
@@ -1734,7 +1538,7 @@ public void setUnloadDelay(long unloadDelay) {
}
/**
- * Unpack WAR flag accessor.
+ * @return true if Unpack WAR flag accessor enabled.
*/
public boolean getUnpackWAR() {
return unpackWAR;
@@ -1747,11 +1551,6 @@ public void setUnpackWAR(boolean unpackWAR) {
this.unpackWAR = unpackWAR;
}
- /**
- * Set the resources DirContext object with which this Container is associated.
- *
- * @param resources The newly associated DirContext
- */
@Override
public synchronized void setResources(DirContext resources) {
if (started) {
@@ -1811,61 +1610,31 @@ private synchronized void setAlternateResources(AlternateDocBase alternateDocBas
alternateDocBase.setResources(null);
}
- /**
- * Return the "reuse session IDs when creating sessions" flag
- */
@Override
public boolean getReuseSessionID() {
return reuseSessionID;
}
- /**
- * Set the "reuse session IDs when creating sessions" flag
- *
- * @param reuse The new value for the flag
- */
@Override
public void setReuseSessionID(boolean reuse) {
reuseSessionID = reuse;
}
- /**
- * Return whether this context allows sendRedirect() to redirect to a relative URL.
- *
- * The default value for this property is 'false'.
- */
@Override
public boolean getAllowRelativeRedirect() {
return allowRelativeRedirect;
}
- /**
- * Set whether this context allows sendRedirect() to redirect to a relative URL.
- *
- * @param allowRelativeURLs The new value for this property. The default value for this property is 'false'.
- */
@Override
public void setAllowRelativeRedirect(boolean allowRelativeURLs) {
allowRelativeRedirect = allowRelativeURLs;
}
- /**
- * Get Auditors associated with this context, if any.
- *
- * @return array of Auditor objects, or null
- *
- */
@Override
public Auditor[] getAuditors() {
return auditors;
}
- /**
- * Set the Auditors associated with this context.
- *
- * @param auditor array of Auditor objects
- *
- */
@Override
public void setAuditors(Auditor[] auditor) {
this.auditors = auditor;
@@ -1887,11 +1656,6 @@ public boolean isEmbedded() {
return isEmbedded;
}
- /**
- * Should we generate directory listings?
- */
- protected boolean directoryListing = false;
-
/**
* Enables or disables directory listings on this Context.
*/
@@ -1907,16 +1671,15 @@ public void setDirectoryListing(boolean directoryListing) {
}
/**
- * Checks whether directory listings are enabled or disabled on this Context.
+ * @return true if directory listings are enabled on this Context.
*/
public boolean isDirectoryListing() {
return directoryListing;
}
- // ------------------------------------------------------ Public Properties
/**
- * Return the Locale to character set mapper class for this Context.
+ * @return the Locale to character set mapper class for this Context.
*/
public String getCharsetMapperClass() {
return charsetMapperClass;
@@ -1956,7 +1719,7 @@ public String getWorkPath() {
}
/**
- * Return the work directory for this Context.
+ * @return the work directory for this Context.
*/
public String getWorkDir() {
return workDir;
@@ -1976,24 +1739,11 @@ public void setWorkDir(String workDir) {
}
}
- // -------------------------------------------------------- Context Methods
-
- /**
- * Adds the Listener with the given class name that is declared in the deployment descriptor to the set of Listeners
- * configured for this application.
- *
- * @param listener the fully qualified class name of the Listener
- */
@Override
public void addApplicationListener(String listener) {
addListener(listener, false);
}
- /**
- * Add a new application parameter for this application.
- *
- * @param parameter The new application parameter
- */
@Override
public void addApplicationParameter(ApplicationParameter parameter) {
String newName = parameter.getName();
@@ -2015,30 +1765,24 @@ public void addApplicationParameter(ApplicationParameter parameter) {
}
}
- /**
- * Adds the given child Container to this context.
- *
- * @param child the child Container to add
- *
- * @exception IllegalArgumentException if the given child Container is not an instance of Wrapper
- */
@Override
public void addChild(Container child) {
addChild(child, false, true);
}
+
/**
* Adds the given child (Servlet) to this context.
*
* @param child the child (Servlet) to add
- * @param isProgrammatic true if the given child (Servlet) is being added via one of the programmatic interfaces, and
- * false if it is declared in the deployment descriptor
- * @param createRegistration true if a ServletRegistration needs to be created for the given child, and false if a
- * (preliminary) ServletRegistration had already been created (which would be the case if the Servlet had been declared
- * in the deployment descriptor without any servlet-class, and the servlet-class was later provided via
- * ServletContext#addServlet)
- *
- * @exception IllegalArgumentException if the given child Container is not an instance of Wrapper
+ * @param isProgrammatic true if the given child (Servlet) is being added via one of the
+ * programmatic interfaces, and false if it is declared in the deployment descriptor
+ * @param createRegistration true if a ServletRegistration needs to be created for the given
+ * child, and false if a (preliminary) ServletRegistration had already been created
+ * (which would be the case if the Servlet had been declared in the deployment
+ * descriptor without any servlet-class, and the servlet-class was later provided via
+ * ServletContext#addServlet)
+ * @throws IllegalArgumentException if the given child Container is not an instance of Wrapper
*/
protected void addChild(Container child, boolean isProgrammatic, boolean createRegistration) {
if (!(child instanceof Wrapper)) {
@@ -2059,11 +1803,10 @@ protected void addChild(Container child, boolean isProgrammatic, boolean createR
servletRegistrationMap.put(wrapperName, servletRegistration);
if (isAllNull(wrapper.getServletClassName(), wrapper.getJspFile())) {
- /*
- * Preliminary registration for Servlet that was declared without any servlet-class. Once the registration is completed
- * via ServletContext#addServlet, addChild will be called again, and 'wrapper' will have been configured with a proper
- * class name at that time
- */
+ // Preliminary registration for Servlet that was declared without any servlet-class.
+ // Once the registration is completed via ServletContext#addServlet, addChild will
+ // be called again, and 'wrapper' will have been configured with a proper class name
+ // at that time
return;
}
}
@@ -2097,21 +1840,17 @@ protected void addChild(Container child, boolean isProgrammatic, boolean createR
super.addChild(child);
if (getAvailable()) {
- /*
- * If this StandardContext has already been started, we need to register the newly added child with JMX. Any children
- * that were added before this StandardContext was started have already been registered with JMX (as part of
- * StandardContext.start()).
- */
+ // If this StandardContext has already been started, we need to register the newly added
+ // child with JMX. Any children that were added before this StandardContext was started
+ // have already been registered with JMX (as part of StandardContext.start()).
if (wrapper instanceof StandardWrapper) {
((StandardWrapper) wrapper).registerJMX(this);
}
}
if (isJspServlet && oldJspServlet != null) {
- /*
- * The webapp-specific JspServlet inherits all the mappings specified in the global web.xml, and may add additional
- * ones.
- */
+ // The webapp-specific JspServlet inherits all the mappings specified in the global
+ // web.xml, and may add additional ones.
String[] jspMappings = oldJspServlet.findMappings();
if (jspMappings != null) {
for (String jspMapping : jspMappings) {
@@ -2151,11 +1890,6 @@ public void addConstraint(SecurityConstraint constraint) {
constraints.add(constraint);
}
- /**
- * Add an EJB resource reference for this web application.
- *
- * @param ejb New EJB resource reference
- */
@Override
public void addEjb(ContextEjb ejb) {
namingResources.addEjb(ejb);
@@ -2164,20 +1898,13 @@ public void addEjb(ContextEjb ejb) {
}
}
- /**
- * Add an environment entry for this web application.
- *
- * @param environment New environment entry
- */
@Override
public void addEnvironment(ContextEnvironment environment) {
ContextEnvironment existingEnvironment = findEnvironment(environment.getName());
if (existingEnvironment != null && !existingEnvironment.getOverride()) {
return;
}
-
namingResources.addEnvironment(environment);
-
if (notifyContainerListeners) {
fireContainerEvent("addEnvironment", environment.getName());
}
@@ -2195,11 +1922,6 @@ public void addResourceParams(ResourceParams resourceParameters) {
}
}
- /**
- * Add an error page for the specified error or Java exception.
- *
- * @param errorPage The error page definition to be added
- */
@Override
public void addErrorPage(ErrorPage errorPage) {
// Validate the input parameters
@@ -2241,20 +1963,17 @@ public void addErrorPage(ErrorPage errorPage) {
}
}
- /**
- * Add a filter definition to this Context.
- *
- * @param filterDef The filter definition to be added
- */
@Override
public void addFilterDef(FilterDef filterDef) {
addFilterDef(filterDef, false, true);
}
public void addFilterDef(FilterDef filterDef, boolean isProgrammatic, boolean createRegistration) {
+ log.log(Level.CONFIG, "addFilterDef(filterDef={0}, isProgrammatic={1}, createRegistration={2})",
+ new Object[] {filterDef, isProgrammatic, createRegistration});
if (createRegistration) {
- FilterRegistrationImpl filterRegistration = null;
- if (isProgrammatic || null == filterDef.getFilterClassName()) {
+ final FilterRegistrationImpl filterRegistration;
+ if (isProgrammatic || filterDef.getFilterClassName() == null) {
filterRegistration = new DynamicFilterRegistrationImpl(filterDef, this);
} else {
filterRegistration = new FilterRegistrationImpl(filterDef, this);
@@ -2262,11 +1981,10 @@ public void addFilterDef(FilterDef filterDef, boolean isProgrammatic, boolean cr
filterRegistrationMap.put(filterDef.getFilterName(), filterRegistration);
if (filterDef.getFilterClassName() == null) {
- /*
- * Preliminary registration for Filter that was declared without any filter-class. Once the registration is completed
- * via ServletContext#addFilter, addFilterDef will be called again, and 'filterDef' will have been configured with a
- * proper class name at that time
- */
+ // Preliminary registration for Filter that was declared without any filter-class.
+ // Once the registration is completed via ServletContext#addFilter, addFilterDef
+ // will be called again, and 'filterDef' will have been configured with a proper
+ // class name at that time
return;
}
}
@@ -2280,13 +1998,13 @@ public void addFilterDef(FilterDef filterDef, boolean isProgrammatic, boolean cr
}
}
+
/**
* Add multiple filter mappings to this Context.
*
* @param filterMaps The filter mappings to be added
- *
- * @exception IllegalArgumentException if the specified filter name does not match an existing filter definition, or the
- * filter mapping is malformed
+ * @throws IllegalArgumentException if the specified filter name does not match an existing
+ * filter definition, or the filter mapping is malformed
*/
public void addFilterMaps(FilterMaps filterMaps) {
String[] servletNames = filterMaps.getServletNames();
@@ -2309,13 +2027,10 @@ public void addFilterMaps(FilterMaps filterMaps) {
}
}
+
/**
- * Add a filter mapping to this Context.
- *
- * @param filterMap The filter mapping to be added
- *
- * @exception IllegalArgumentException if the specified filter name does not match an existing filter definition, or the
- * filter mapping is malformed
+ * @throws IllegalArgumentException if the specified filter name does not match an existing
+ * filter definition, or the filter mapping is malformed
*/
@Override
public void addFilterMap(FilterMap filterMap) {
@@ -2331,7 +2046,7 @@ public void addFilterMap(FilterMap filterMap) {
* mappings of this servlet context, and false if it is supposed to be matched before any declared filter mappings of
* this servlet context
*
- * @exception IllegalArgumentException if the specified filter name does not match an existing filter definition, or the
+ * @throws IllegalArgumentException if the specified filter name does not match an existing filter definition, or the
* filter mapping is malformed
*
*/
@@ -2370,7 +2085,7 @@ public void addFilterMap(FilterMap filterMap, boolean isMatchAfter) {
}
/**
- * Gets the current servlet name mappings of the Filter with the given name.
+ * @return the current servlet name mappings of the Filter with the given name.
*/
public Collection<jsp-config>
related configuration that was aggregated over the web.xml
and
- * web-fragment.xml
resources of the web application represented by this ServletContext.
- */
@Override
public JspConfigDescriptor getJspConfigDescriptor() {
return jspConfigDesc;
}
- /**
- * Gets the class loader of the web application represented by this ServletContext.
- */
@Override
public ClassLoader getClassLoader() {
Loader containerLoader = getLoader();
@@ -2857,7 +2502,7 @@ public ClassLoader getClassLoader() {
public void declareRoles(String... roleNames) {
if (isContextInitializedCalled) {
String msg = format(rb.getString(SERVLET_CONTEXT_ALREADY_INIT_EXCEPTION),
- new Object[] { "declareRoles", getName() });
+ new Object[] {"declareRoles", getName()});
throw new IllegalStateException(msg);
}
@@ -2894,11 +2539,6 @@ public String getVirtualServerName() {
return virtualServerName;
}
- /**
- * Add the classname of an InstanceListener to be added to each Wrapper appended to this Context.
- *
- * @param listener Java class name of an InstanceListener class
- */
@Override
public void addInstanceListener(String listener) {
instanceListeners.add(listener);
@@ -2914,13 +2554,6 @@ public void addInstanceListener(InstanceListener listener) {
}
}
- /**
- * Add the given URL pattern as a jsp-property-group. This maps resources that match the given pattern so they will be
- * passed to the JSP container. Though there are other elements in the property group, we only care about the URL
- * pattern here. The JSP container will parse the rest.
- *
- * @param pattern URL pattern to be mapped
- */
@Override
public void addJspMapping(String pattern) {
String servletName = findServletMapping("*.jsp");
@@ -2937,22 +2570,11 @@ public void addJspMapping(String pattern) {
}
}
- /**
- * Add a Locale Encoding Mapping (see Sec 5.4 of Servlet spec 2.4)
- *
- * @param locale locale to map an encoding for
- * @param encoding encoding to be used for a give locale
- */
@Override
public void addLocaleEncodingMappingParameter(String locale, String encoding) {
getCharsetMapper().addCharsetMappingFromDeploymentDescriptor(locale, encoding);
}
- /**
- * Add a local EJB resource reference for this web application.
- *
- * @param ejb New EJB resource reference
- */
@Override
public void addLocalEjb(ContextLocalEjb ejb) {
namingResources.addLocalEjb(ejb);
@@ -2987,12 +2609,6 @@ public void addMessageDestinationRef(MessageDestinationRef mdr) {
}
}
- /**
- * Add a new MIME mapping, replacing any existing mapping for the specified extension.
- *
- * @param extension Filename extension being mapped
- * @param mimeType Corresponding MIME type
- */
@Override
public void addMimeMapping(String extension, String mimeType) {
mimeMappings.put(extension.toLowerCase(Locale.ENGLISH), mimeType);
@@ -3001,15 +2617,7 @@ public void addMimeMapping(String extension, String mimeType) {
}
}
- /**
- * Add a new context initialization parameter.
- *
- * @param name Name of the new parameter
- * @param value Value of the new parameter
- *
- * @exception IllegalArgumentException if the name or value is missing, or if this context initialization parameter has
- * already been registered
- */
+
@Override
public void addParameter(String name, String value) {
// Validate the proposed context initialization parameter
@@ -3032,11 +2640,6 @@ public void addParameter(String name, String value) {
}
}
- /**
- * Add a resource reference for this web application.
- *
- * @param resource New resource reference
- */
@Override
public void addResource(ContextResource resource) {
namingResources.addResource(resource);
@@ -3045,12 +2648,6 @@ public void addResource(ContextResource resource) {
}
}
- /**
- * Add a resource environment reference for this web application.
- *
- * @param name The resource environment reference name
- * @param type The resource environment reference type
- */
@Override
public void addResourceEnvRef(String name, String type) {
namingResources.addResourceEnvRef(name, type);
@@ -3059,11 +2656,6 @@ public void addResourceEnvRef(String name, String type) {
}
}
- /**
- * Add a resource link for this web application.
- *
- * @param resourceLink New resource link
- */
@Override
public void addResourceLink(ContextResourceLink resourceLink) {
namingResources.addResourceLink(resourceLink);
@@ -3072,12 +2664,6 @@ public void addResourceLink(ContextResourceLink resourceLink) {
}
}
- /**
- * Add a security role reference for this web application.
- *
- * @param role Security role used in the application
- * @param link Actual security role to check for
- */
@Override
public void addRoleMapping(String role, String link) {
synchronized (roleMappings) {
@@ -3088,48 +2674,40 @@ public void addRoleMapping(String role, String link) {
}
}
- /**
- * Add a new security role for this web application.
- *
- * @param role New security role
- */
@Override
public void addSecurityRole(String role) {
securityRoles.add(role);
-
if (notifyContainerListeners) {
fireContainerEvent("addSecurityRole", role);
}
}
+
/**
* Adds the given servlet mappings to this Context.
- *
* null
.
- *
- * @param name Name of the desired EJB resource reference
- */
@Override
public ContextEjb findEjb(String name) {
return namingResources.findEjb(name);
}
- /**
- * Return the defined EJB resource references for this application. If there are none, a zero-length array is returned.
- */
@Override
public ContextEjb[] findEjbs() {
return namingResources.findEjbs();
}
- /**
- * Return the environment entry with the specified name, if any; otherwise, return null
.
- *
- * @param name Name of the desired environment entry
- */
@Override
public ContextEnvironment findEnvironment(String name) {
return namingResources.findEnvironment(name);
}
- /**
- * Return the set of defined environment entries for this web application. If none have been defined, a zero-length
- * array is returned.
- */
@Override
public ContextEnvironment[] findEnvironments() {
return namingResources.findEnvironments();
}
- /**
- * Return the error page entry for the specified HTTP error code, if any; otherwise return null
.
- *
- * @param errorCode Error code to look up
- */
@Override
public ErrorPage findErrorPage(int errorCode) {
if ((errorCode >= 400) && (errorCode < 600)) {
return statusPages.get(errorCode);
}
-
return null;
}
- /**
- * Return the error page entry for the specified Java exception type, if any; otherwise return null
.
- *
- * @param exceptionType Exception type to look up
- */
@Override
public ErrorPage findErrorPage(String exceptionType) {
synchronized (exceptionPages) {
@@ -3724,24 +3185,11 @@ public ErrorPage findErrorPage(String exceptionType) {
}
}
- /**
- * Gets the default error page of this context.
- *
- * null
.
- *
- * @param filterName Filter name to look up
- */
@Override
public FilterDef findFilterDef(String filterName) {
synchronized (filterDefs) {
@@ -3749,9 +3197,6 @@ public FilterDef findFilterDef(String filterName) {
}
}
- /**
- * Return the set of defined filters for this Context.
- */
@Override
public FilterDef[] findFilterDefs() {
synchronized (filterDefs) {
@@ -3760,36 +3205,21 @@ public FilterDef[] findFilterDefs() {
}
}
- /**
- * Return the list of filter mappings for this Context.
- */
@Override
public Listnull
.
- *
- * @param name Name of the desired EJB resource reference
- */
@Override
public ContextLocalEjb findLocalEjb(String name) {
return namingResources.findLocalEjb(name);
}
- /**
- * Return the defined local EJB resource references for this application. If there are none, a zero-length array is
- * returned.
- */
@Override
public ContextLocalEjb[] findLocalEjbs() {
return namingResources.findLocalEjbs();
@@ -3802,10 +3232,10 @@ public Context findMappingObject() {
return (Context) getMappingObject();
}
+
/**
- * Return the message destination with the specified name, if any; otherwise, return null
.
- *
* @param name Name of the desired message destination
+ * @return the message destination with the specified name, if any; otherwise, return null
.
*/
public MessageDestination findMessageDestination(String name) {
synchronized (messageDestinations) {
@@ -3813,9 +3243,10 @@ public MessageDestination findMessageDestination(String name) {
}
}
+
/**
- * Return the set of defined message destinations for this web application. If none have been defined, a zero-length
- * array is returned.
+ * @return the set of defined message destinations for this web application. If none have been
+ * defined, a zero-length array is returned.
*/
public MessageDestination[] findMessageDestinations() {
synchronized (messageDestinations) {
@@ -3823,46 +3254,34 @@ public MessageDestination[] findMessageDestinations() {
}
}
+
/**
- * Return the message destination ref with the specified name, if any; otherwise, return null
.
- *
* @param name Name of the desired message destination ref
+ * @return the message destination ref with the specified name, if any; otherwise, return null
.
*/
public MessageDestinationRef findMessageDestinationRef(String name) {
return namingResources.findMessageDestinationRef(name);
}
+
/**
- * Return the set of defined message destination refs for this web application. If none have been defined, a zero-length
- * array is returned.
+ * @return the set of defined message destination refs for this web application. If none have
+ * been defined, a zero-length array is returned.
*/
public MessageDestinationRef[] findMessageDestinationRefs() {
return namingResources.findMessageDestinationRefs();
}
- /**
- * Return the MIME type to which the specified extension is mapped, if any; otherwise return null
.
- *
- * @param extension Extension to map to a MIME type
- */
@Override
public String findMimeMapping(String extension) {
return mimeMappings.get(extension.toLowerCase(Locale.ENGLISH));
}
- /**
- * Return the extensions for which MIME mappings are defined. If there are none, a zero-length array is returned.
- */
@Override
public String[] findMimeMappings() {
return mimeMappings.keySet().toArray(new String[mimeMappings.size()]);
}
- /**
- * Return the value for the specified context initialization parameter name, if any; otherwise return null
.
- *
- * @param name Name of the parameter to return
- */
@Override
public String findParameter(String name) {
synchronized (parameters) {
@@ -3870,10 +3289,6 @@ public String findParameter(String name) {
}
}
- /**
- * Return the names of all defined context initialization parameters for this Context. If no parameters are defined, a
- * zero-length array is returned.
- */
@Override
public String[] findParameters() {
synchronized (parameters) {
@@ -3881,97 +3296,53 @@ public String[] findParameters() {
}
}
- /**
- * Return the resource reference with the specified name, if any; otherwise return null
.
- *
- * @param name Name of the desired resource reference
- */
@Override
public ContextResource findResource(String name) {
return namingResources.findResource(name);
}
- /**
- * Return the resource environment reference type for the specified name, if any; otherwise return null
.
- *
- * @param name Name of the desired resource environment reference
- */
@Override
public String findResourceEnvRef(String name) {
return namingResources.findResourceEnvRef(name);
}
- /**
- * Return the set of resource environment reference names for this web application. If none have been specified, a
- * zero-length array is returned.
- */
@Override
public String[] findResourceEnvRefs() {
return namingResources.findResourceEnvRefs();
}
- /**
- * Return the resource link with the specified name, if any; otherwise return null
.
- *
- * @param name Name of the desired resource link
- */
@Override
public ContextResourceLink findResourceLink(String name) {
return namingResources.findResourceLink(name);
}
- /**
- * Return the defined resource links for this application. If none have been defined, a zero-length array is returned.
- */
@Override
public ContextResourceLink[] findResourceLinks() {
return namingResources.findResourceLinks();
}
- /**
- * Return the defined resource references for this application. If none have been defined, a zero-length array is
- * returned.
- */
@Override
public ContextResource[] findResources() {
return namingResources.findResources();
}
- /**
- * For the given security role (as used by an application), return the corresponding role name (as defined by the
- * underlying Realm) if there is one. Otherwise, return the specified role unchanged.
- *
- * @param role Security role to map
- */
@Override
public String findRoleMapping(String role) {
- String realRole = null;
+ final String realRole;
synchronized (roleMappings) {
realRole = roleMappings.get(role);
}
-
if (realRole != null) {
return realRole;
}
-
return role;
}
- /**
- * Checks if the given security role is defined for this application.
- *
- * @param role Security role to check for
- *
- * @return true if the specified security role is defined for this application, false otherwise
- */
@Override
public boolean hasSecurityRole(String role) {
return securityRoles.contains(role);
}
- /**
- * Removes any security roles defined for this application.
- */
@Override
public void removeSecurityRoles() {
// Inform interested listeners
@@ -3984,11 +3355,6 @@ public void removeSecurityRoles() {
securityRoles.clear();
}
- /**
- * Return the servlet name mapped by the specified pattern (if any); otherwise return null
.
- *
- * @param pattern Pattern for which a mapping is requested
- */
@Override
public String findServletMapping(String pattern) {
synchronized (servletMappings) {
@@ -3996,10 +3362,6 @@ public String findServletMapping(String pattern) {
}
}
- /**
- * Return the patterns of all defined servlet mappings for this Context. If no mappings are defined, a zero-length array
- * is returned.
- */
@Override
public String[] findServletMappings() {
synchronized (servletMappings) {
@@ -4008,25 +3370,15 @@ public String[] findServletMappings() {
}
}
- /**
- * Return the context-relative URI of the error page for the specified HTTP status code, if any; otherwise return
- * null
.
- *
- * @param status HTTP status code to look up
- */
@Override
public ErrorPage findStatusPage(int status) {
return statusPages.get(status);
}
- /**
- * Return the set of HTTP status codes for which error pages have been specified. If none are specified, a zero-length
- * array is returned.
- */
@Override
public int[] findStatusPages() {
synchronized (statusPages) {
- int results[] = new int[statusPages.size()];
+ int[] results = new int[statusPages.size()];
int i = 0;
for (Integer element : statusPages.keySet()) {
results[i++] = element;
@@ -4035,12 +3387,6 @@ public int[] findStatusPages() {
}
}
- /**
- * Return true
if the specified welcome file is defined for this Context; otherwise return
- * false
.
- *
- * @param name Welcome file to verify
- */
@Override
public boolean findWelcomeFile(String name) {
synchronized (welcomeFiles) {
@@ -4050,47 +3396,29 @@ public boolean findWelcomeFile(String name) {
}
}
}
-
return false;
}
- /**
- * Gets the watched resources defined for this web application.
- */
@Override
public Listreloadable
property is set to false
.
+ * @throws IllegalStateException if the started
property is set to false
.
*/
@Override
public synchronized void reload() {
@@ -4141,11 +3472,6 @@ public synchronized void reload() {
setPaused(false);
}
- /**
- * Remove the application parameter with the specified name from the set for this application.
- *
- * @param name Name of the application parameter to remove
- */
@Override
public void removeApplicationParameter(String name) {
ApplicationParameter match = null;
@@ -4167,11 +3493,7 @@ public void removeApplicationParameter(String name) {
}
/**
- * Removes the given child container.
- *
- * @param child the child container to be removed
- *
- * @exception IllegalArgumentException if the given child container is not an implementation of Wrapper
+ * @throws IllegalArgumentException if the given child container is not an implementation of Wrapper
*/
@Override
public void removeChild(Container child) {
@@ -4182,9 +3504,6 @@ public void removeChild(Container child) {
super.removeChild(child);
}
- /**
- * Removes any security constraints from this web application.
- */
@Override
public void removeConstraints() {
// Inform interested listeners
@@ -4197,25 +3516,14 @@ public void removeConstraints() {
constraints.clear();
}
- /**
- * Remove any EJB resource reference with the specified name.
- *
- * @param name Name of the EJB resource reference to remove
- */
@Override
public void removeEjb(String name) {
namingResources.removeEjb(name);
-
if (notifyContainerListeners) {
fireContainerEvent("removeEjb", name);
}
}
- /**
- * Remove any environment entry with the specified name.
- *
- * @param name Name of the environment entry to remove
- */
@Override
public void removeEnvironment(String name) {
if (namingResources == null) {
@@ -4234,9 +3542,6 @@ public void removeEnvironment(String name) {
}
}
- /**
- * Removes any error page declarations.
- */
@Override
public void removeErrorPages() {
synchronized (exceptionPages) {
@@ -4258,11 +3563,6 @@ public void removeErrorPages() {
}
}
- /**
- * Remove the specified filter definition from this Context, if it exists; otherwise, no action is taken.
- *
- * @param filterDef Filter definition to be removed
- */
@Override
public void removeFilterDef(FilterDef filterDef) {
synchronized (filterDefs) {
@@ -4274,9 +3574,6 @@ public void removeFilterDef(FilterDef filterDef) {
}
}
- /**
- * Removes any filter mappings from this Context.
- */
@Override
public void removeFilterMaps() {
// Inform interested listeners
@@ -4289,11 +3586,6 @@ public void removeFilterMaps() {
filterMaps.clear();
}
- /**
- * Remove a class name from the list of InstanceListener classes that will be added to newly created Wrappers.
- *
- * @param listener Class name of an InstanceListener class to be removed
- */
@Override
public void removeInstanceListener(String listener) {
instanceListeners.remove(listener);
@@ -4304,15 +3596,9 @@ public void removeInstanceListener(String listener) {
}
}
- /**
- * Remove any local EJB resource reference with the specified name.
- *
- * @param name Name of the EJB resource reference to remove
- */
@Override
public void removeLocalEjb(String name) {
namingResources.removeLocalEjb(name);
-
if (notifyContainerListeners) {
fireContainerEvent("removeLocalEjb", name);
}
@@ -4346,11 +3632,6 @@ public void removeMessageDestinationRef(String name) {
}
}
- /**
- * Remove the MIME mapping for the specified extension, if it exists; otherwise, no action is taken.
- *
- * @param extension Extension to remove the mapping for
- */
@Override
public void removeMimeMapping(String extension) {
mimeMappings.remove(extension.toLowerCase(Locale.ENGLISH));
@@ -4360,27 +3641,16 @@ public void removeMimeMapping(String extension) {
}
}
- /**
- * Remove the context initialization parameter with the specified name, if it exists; otherwise, no action is taken.
- *
- * @param name Name of the parameter to remove
- */
@Override
public void removeParameter(String name) {
synchronized (parameters) {
parameters.remove(name);
}
-
if (notifyContainerListeners) {
fireContainerEvent("removeParameter", name);
}
}
- /**
- * Remove any resource reference with the specified name.
- *
- * @param resourceName Name of the resource reference to remove
- */
@Override
public void removeResource(String resourceName) {
String decoded = URLDecoder.decode(resourceName);
@@ -4400,11 +3670,6 @@ public void removeResource(String resourceName) {
}
}
- /**
- * Remove any resource environment reference with the specified name.
- *
- * @param name Name of the resource environment reference to remove
- */
@Override
public void removeResourceEnvRef(String name) {
namingResources.removeResourceEnvRef(name);
@@ -4414,11 +3679,6 @@ public void removeResourceEnvRef(String name) {
}
}
- /**
- * Remove any resource link with the specified name.
- *
- * @param link Name of the resource link to remove
- */
@Override
public void removeResourceLink(String link) {
String decoded = URLDecoder.decode(link);
@@ -4438,11 +3698,6 @@ public void removeResourceLink(String link) {
}
}
- /**
- * Remove any security role reference for the specified name
- *
- * @param role Security role (as used in the application) to remove
- */
@Override
public void removeRoleMapping(String role) {
synchronized (roleMappings) {
@@ -4454,14 +3709,9 @@ public void removeRoleMapping(String role) {
}
}
- /**
- * Remove any servlet mapping for the specified pattern, if it exists; otherwise, no action is taken.
- *
- * @param pattern URL pattern of the mapping to remove
- */
@Override
public void removeServletMapping(String pattern) {
- String name = null;
+ final String name;
synchronized (servletMappings) {
name = servletMappings.remove(pattern);
}
@@ -4478,17 +3728,11 @@ public void removeServletMapping(String pattern) {
}
}
- /**
- * Checks whether this web application has any watched resources defined.
- */
@Override
public boolean hasWatchedResources() {
return !watchedResources.isEmpty();
}
- /**
- * Clears any watched resources defined for this web application.
- */
@Override
public void removeWatchedResources() {
synchronized (watchedResources) {
@@ -4591,11 +3835,10 @@ public void fireRequestDestroyedEvent(ServletRequest request) {
}
}
- // --------------------------------------------------------- Public Methods
/**
- * Configure and initialize the set of filters for this Context. Return true
if all filter initialization
- * completed successfully, or false
otherwise.
+ * Configure and initialize the set of filters for this Context. Return true
if all
+ * filter initialization completed successfully, or false
otherwise.
*/
public boolean filterStart() {
log.log(FINE, "Starting filters");
@@ -4621,9 +3864,10 @@ public boolean filterStart() {
return ok;
}
+
/**
- * Finalize and release the set of filters for this Context. Return true
if all filter finalization
- * completed successfully, or false
otherwise.
+ * Finalize and release the set of filters for this Context. Return true
if all
+ * filter finalization completed successfully, or false
otherwise.
*/
public boolean filterStop() {
log.log(FINE, "Stopping filters");
@@ -4642,9 +3886,10 @@ public boolean filterStop() {
return true;
}
+
/**
- * Find and return the initialized FilterConfig
for the specified filter name, if any; otherwise return
- * null
.
+ * Find and return the initialized FilterConfig
for the specified filter name, if
+ * any; otherwise return null
.
*
* @param name Name of the desired filter
*/
@@ -4672,20 +3917,21 @@ protected void contextListenerStart() {
}
}
- /*
- * Make sure there are no preliminary servlet or filter registrations left after all listeners have been notified
- */
+ // Make sure there are no preliminary servlet or filter registrations left after all
+ // listeners have been notified
Collectiontrue
if initialization was successfull, or
- * false
otherwise.
+ * Allocate resources, including proxy.
+ *
+ * @return true
if initialization was successfull, or
+ * false
otherwise.
*/
public boolean resourcesStart() {
boolean ok = true;
@@ -4865,19 +4114,18 @@ public void alternateResourcesStart() throws LifecycleException {
}
alternateDocBase.setResources(ContextsAdapterUtility.wrap(proxyDirContext));
} catch (Throwable t) {
- if (log.isLoggable(FINE)) {
- throw new LifecycleException(format(rb.getString(STARTING_RESOURCES_EXCEPTION), getName()), t);
- } else {
- throw new LifecycleException(format(
- rb.getString(STARTING_RESOURCE_EXCEPTION_MESSAGE),
- new Object[] { getName(), t.getMessage() }));
- }
+ throw new LifecycleException(
+ format(rb.getString(STARTING_RESOURCE_EXCEPTION_MESSAGE), new Object[] {getName(), t.getMessage()}),
+ t);
}
}
}
+
/**
* Deallocate resources and destroy proxy.
+ *
+ * @return true if succeeded, false if logged an exception
*/
public boolean resourcesStop() {
boolean ok = true;
@@ -4902,8 +4150,11 @@ public boolean resourcesStop() {
}
+
/**
* Stops this context's alternate doc base resources.
+ *
+ * @return true if succeeded, false if logged an exception
*/
public boolean alternateResourcesStop() {
boolean ok = true;
@@ -4939,12 +4190,15 @@ public boolean alternateResourcesStop() {
return ok;
}
+
/**
- * Load and initialize all servlets marked "load on startup" in the web application deployment descriptor.
+ * Load and initialize all servlets marked "load on startup" in the web application deployment
+ * descriptor.
*
- * @param children Array of wrappers for all currently defined servlets (including those not declared load on startup)
+ * @param children Array of wrappers for all currently defined servlets (including those not
+ * declared load on startup)
*/
- public void loadOnStartup(Container children[]) throws LifecycleException {
+ public void loadOnStartup(Container[] children) throws LifecycleException {
// Collect "load on startup" servlets that need to be initialized
Map<url-pattern>
for conformance with specification requirements.
+ * Validate the syntax of a proposed <url-pattern>
for conformance with
+ * specification requirements.
*
* @param urlPattern URL pattern to be validated
*/
@@ -5913,7 +5160,7 @@ protected boolean validateURLPattern(String urlPattern) {
return false;
}
- if ((urlPattern.startsWith("/")) && (!urlPattern.contains("*."))) {
+ if (urlPattern.startsWith("/") && !urlPattern.contains("*.")) {
checkUnusualURLPattern(urlPattern);
return true;
}
@@ -5937,7 +5184,7 @@ private void checkUnusualURLPattern(String urlPattern) {
// -------------------- JMX methods --------------------
/**
- * Return the MBean Names of the set of defined environment entries for this web application
+ * @return the MBean Names of the set of defined environment entries for this web application
*/
public String[] getEnvironments() {
ContextEnvironment[] envs = getNamingResources().findEnvironments();
@@ -5958,7 +5205,7 @@ public String[] getEnvironments() {
}
/**
- * Return the MBean Names of all the defined resource references for this application.
+ * @return the MBean Names of all the defined resource references for this application.
*/
public String[] getResourceNames() {
ContextResource[] resources = getNamingResources().findResources();
@@ -5975,11 +5222,10 @@ public String[] getResourceNames() {
}
return results.toArray(new String[results.size()]);
-
}
/**
- * Return the MBean Names of all the defined resource links for this application
+ * @return the MBean Names of all the defined resource links for this application
*/
public String[] getResourceLinks() {
ContextResourceLink[] links = getNamingResources().findResourceLinks();
@@ -5995,7 +5241,6 @@ public String[] getResourceLinks() {
return results.toArray(new String[results.size()]);
}
- // ------------------------------------------------------------- Operations
/**
* Add an environment entry for this web application.
@@ -6096,14 +5341,14 @@ public ObjectName createObjectName(String hostDomain, ObjectName parentName) thr
private void preRegisterJMX() {
try {
StandardHost host = (StandardHost) getParent();
- if ((oname == null) || (oname.getKeyProperty("j2eeType") == null)) {
+ if (oname == null || oname.getKeyProperty("j2eeType") == null) {
oname = createObjectName(host.getDomain(), host.getJmxName());
controller = oname;
}
} catch (Exception ex) {
if (log.isLoggable(INFO)) {
String msg = format(rb.getString(LogFacade.ERROR_UPDATING_CTX_INFO),
- new Object[] { this, oname, ex.toString() });
+ new Object[] {this, oname, ex.toString()});
log.log(INFO, msg, ex);
}
}
@@ -6124,9 +5369,8 @@ private void registerJMX() {
((StandardWrapper) child).registerJMX(this);
}
} catch (Exception ex) {
-
String msg = format(rb.getString(LogFacade.ERROR_REGISTERING_WRAPPER_INFO),
- new Object[] { this, oname, ex.toString() });
+ new Object[] {this, oname, ex.toString()});
log.log(INFO, msg, ex);
}
}
@@ -6211,124 +5455,104 @@ public void create() throws Exception {
init();
}
+
/**
* Create an ObjectName
for ContextEnvironment
object.
*
* @param environment The ContextEnvironment to be named
- *
- * @exception MalformedObjectNameException if a name cannot be created
+ * @throws MalformedObjectNameException if a name cannot be created
*/
public ObjectName createObjectName(ContextEnvironment environment) throws MalformedObjectNameException {
-
- ObjectName name = null;
Object container = environment.getNamingResources().getContainer();
if (container instanceof Server) {
- name = new ObjectName(domain + ":type=Environment" + ",resourcetype=Global,name=" + environment.getName());
+ return new ObjectName(domain + ":type=Environment" + ",resourcetype=Global,name=" + environment.getName());
} else if (container instanceof Context) {
String path = ((Context) container).getPath();
- if (path.length() < 1) {
+ if (path.isEmpty()) {
path = "/";
}
Host host = (Host) ((Context) container).getParent();
- name = new ObjectName(domain + ":type=Environment" + ",resourcetype=Context,path=" + path + ",host=" + host.getName() + ",name="
- + environment.getName());
+ return new ObjectName(domain + ":type=Environment" + ",resourcetype=Context,path=" + path + ",host="
+ + host.getName() + ",name=" + environment.getName());
}
- return (name);
-
+ return null;
}
+
/**
* Create an ObjectName
for ContextResource
object.
*
* @param resource The ContextResource to be named
- *
- * @exception MalformedObjectNameException if a name cannot be created
+ * @throws MalformedObjectNameException if a name cannot be created
*/
public ObjectName createObjectName(ContextResource resource) throws MalformedObjectNameException {
-
- ObjectName name = null;
String encodedResourceName = urlEncoder.encode(resource.getName());
Object container = resource.getNamingResources().getContainer();
if (container instanceof Server) {
- name = new ObjectName(
- domain + ":type=Resource" + ",resourcetype=Global,class=" + resource.getType() + ",name=" + encodedResourceName);
+ return new ObjectName(domain + ":type=Resource" + ",resourcetype=Global,class=" + resource.getType()
+ + ",name=" + encodedResourceName);
} else if (container instanceof Context) {
String path = ((Context) container).getPath();
if (path.length() < 1) {
path = "/";
}
Host host = (Host) ((Context) container).getParent();
- name = new ObjectName(domain + ":type=Resource" + ",resourcetype=Context,path=" + path + ",host=" + host.getName() + ",class="
- + resource.getType() + ",name=" + encodedResourceName);
+ return new ObjectName(domain + ":type=Resource" + ",resourcetype=Context,path=" + path + ",host="
+ + host.getName() + ",class=" + resource.getType() + ",name=" + encodedResourceName);
}
- return (name);
-
+ return null;
}
+
/**
* Create an ObjectName
for ContextResourceLink
object.
*
* @param resourceLink The ContextResourceLink to be named
- *
- * @exception MalformedObjectNameException if a name cannot be created
+ * @throws MalformedObjectNameException if a name cannot be created
*/
public ObjectName createObjectName(ContextResourceLink resourceLink) throws MalformedObjectNameException {
- ObjectName name = null;
String encodedResourceLinkName = urlEncoder.encode(resourceLink.getName());
Object container = resourceLink.getNamingResources().getContainer();
if (container instanceof Server) {
- name = new ObjectName(domain + ":type=ResourceLink" + ",resourcetype=Global" + ",name=" + encodedResourceLinkName);
+ return new ObjectName(
+ domain + ":type=ResourceLink" + ",resourcetype=Global" + ",name=" + encodedResourceLinkName);
} else if (container instanceof Context) {
String path = ((Context) container).getPath();
if (path.length() < 1) {
path = "/";
}
Host host = (Host) ((Context) container).getParent();
- name = new ObjectName(domain + ":type=ResourceLink" + ",resourcetype=Context,path=" + path + ",host=" + host.getName()
- + ",name=" + encodedResourceLinkName);
+ return new ObjectName(domain + ":type=ResourceLink" + ",resourcetype=Context,path=" + path + ",host="
+ + host.getName() + ",name=" + encodedResourceLinkName);
}
- return (name);
-
+ return null;
}
- // ------------------------------------------------- ServletContext Methods
- /**
- * Return the value of the specified context attribute, if any; otherwise return null
.
- */
@Override
public Object getAttribute(String name) {
return context.getAttribute(name);
}
- /**
- * Return an enumeration of the names of the context attributes associated with this context.
- */
@Override
public EnumerationServletContext
object that corresponds to a specified URI on the server.
- */
@Override
public ServletContext getContext(String uri) {
// Validate the format of the specified argument
- if ((uri == null) || (!uri.startsWith("/"))) {
- return (null);
+ if (uri == null || !uri.startsWith("/")) {
+ return null;
}
Context child = null;
@@ -6347,11 +5571,11 @@ public ServletContext getContext(String uri) {
mapuri = mapuri.substring(0, slash);
}
} catch (Throwable t) {
- return (null);
+ return null;
}
if (child == null) {
- return (null);
+ return null;
}
if (getCrossContext()) {
@@ -6362,136 +5586,92 @@ public ServletContext getContext(String uri) {
return getServletContext();
} else {
// Nothing to return
- return (null);
+ return null;
}
}
- /**
- * Return the value of the specified initialization parameter, or null
if this parameter does not exist.
- */
@Override
public String getInitParameter(final String name) {
return context.getInitParameter(name);
}
- /**
- * Return the names of the context's initialization parameters, or an empty enumeration if the context has no
- * initialization parameters.
- */
@Override
public Enumerationnull
if the MIME type cannot be determined.
- */
@Override
public String getMimeType(String file) {
-
if (file == null) {
- return (null);
+ return null;
}
int period = file.lastIndexOf(".");
if (period < 0) {
- return (null);
+ return null;
}
String extension = file.substring(period + 1);
if (extension.length() < 1) {
- return (null);
+ return null;
}
-
- return (findMimeMapping(extension));
-
+ return findMimeMapping(extension);
}
- /**
- * Return a RequestDispatcher
object that acts as a wrapper for the named servlet.
- */
@Override
public RequestDispatcher getNamedDispatcher(String name) {
// Validate the name argument
if (name == null) {
- return (null);
+ return null;
}
// Create and return a corresponding request dispatcher
Wrapper wrapper = (Wrapper) findChild(name);
if (wrapper == null) {
- return (null);
+ return null;
}
return new ApplicationDispatcher(wrapper, null, null, null, null, null, name);
-
}
- /**
- * Return the display name of this web application.
- */
@Override
public String getServletContextName() {
return getDisplayName();
}
- /**
- * Remove the context attribute with the specified name, if any.
- */
@Override
public void removeAttribute(String name) {
context.removeAttribute(name);
}
- /**
- * Bind the specified value with the specified context attribute name, replacing any existing value for that name.
- */
@Override
public void setAttribute(String name, Object value) {
context.setAttribute(name, value);
}
- /**
- * Return the name and version of the servlet container.
- */
@Override
public String getServerInfo() {
return context.getServerInfo();
}
- /**
- * Return the real path corresponding to the given virtual path, or null
if the container was unable to
- * perform the translation
- */
@Override
public String getRealPath(String path) {
if (!(showArchivedRealPathEnabled || directoryDeployed)) {
@@ -6532,27 +5712,18 @@ public String getRealPath(String path) {
}
}
- if (!file.exists()) {
- return null;
- } else {
+ if (file.exists()) {
return file.getAbsolutePath();
}
+ return null;
}
- /**
- * Writes the specified message to a servlet log file.
- */
@Override
public void log(String message) {
message = neutralizeForLog(message);
org.apache.catalina.Logger logger = getLogger();
if (logger != null) {
- /*
- * PWC 6403328 logger.log(context.logName() + message, Logger.INFORMATION);
- */
- // START PWC 6403328
logger.log(logName() + " ServletContext.log():" + message, org.apache.catalina.Logger.INFORMATION);
- // END PWC 6403328
}
}
@@ -6567,9 +5738,6 @@ public void log(Exception exception, String message) {
}
}
- /**
- * Writes the specified message and exception to a servlet log file.
- */
@Override
public void log(String message, Throwable throwable) {
message = neutralizeForLog(message);
@@ -6579,32 +5747,27 @@ public void log(String message, Throwable throwable) {
}
}
- /**
- * Return the requested resource as an InputStream
. The path must be specified according to the rules
- * described under getResource
. If no such resource can be identified, return null
.
- */
@Override
public InputStream getResourceAsStream(String path) {
if (path == null || !path.startsWith("/")) {
- return (null);
+ return null;
}
path = RequestUtil.normalize(path);
if (path == null) {
- return (null);
+ return null;
}
- DirContext resources = null;
-
- if (alternateDocBases == null || alternateDocBases.size() == 0) {
+ final DirContext resources;
+ if (alternateDocBases == null || alternateDocBases.isEmpty()) {
resources = getResources();
} else {
AlternateDocBase match = AlternateDocBase.findMatch(path, alternateDocBases);
- if (match != null) {
- resources = ContextsAdapterUtility.unwrap(match.getResources());
- } else {
+ if (match == null) {
// None of the url patterns for alternate doc bases matched
resources = getResources();
+ } else {
+ resources = ContextsAdapterUtility.unwrap(match.getResources());
}
}
@@ -6618,13 +5781,9 @@ public InputStream getResourceAsStream(String path) {
// do nothing
}
}
- return (null);
+ return null;
}
- /**
- * Return the URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted
- * as relative to the current context root.
- */
@Override
public URL getResource(String path) throws MalformedURLException {
log.log(FINEST, "getResource(path={0})", path);
@@ -6683,10 +5842,6 @@ public URL getResource(String path) throws MalformedURLException {
return null;
}
- /**
- * Return a Set containing the resource paths of resources member of the specified collection. Each path will be a
- * String starting with a "/" character. The returned set is immutable.
- */
@Override
public SetRequestDispatcher
instance that acts as a wrapper for the resource at the given path. The path
- * must begin with a "/" and is interpreted as relative to the current context root.
- */
@Override
public RequestDispatcher getRequestDispatcher(String path) {
@@ -6855,114 +6005,73 @@ public RequestDispatcher getRequestDispatcher(String path) {
return new ApplicationDispatcher(wrapper, mappingForDispatch, uriCC.toString(), wrapperPath, pathInfo, queryString, null);
}
- // ------------------------------------------------------------- Attributes
/**
- * Return the naming resources associated with this web application.
+ * @return the naming resources associated with this web application.
*/
public DirContext getStaticResources() {
return getResources();
}
/**
- * Return the naming resources associated with this web application. FIXME: Fooling introspection ...
+ * @return the naming resources associated with this web application.
+ * FIXME: Fooling introspection ...
*/
public DirContext findStaticResources() {
return getResources();
}
/**
- * Return the naming resources associated with this web application.
+ * @return the naming resources associated with this web application.
*/
public String[] getWelcomeFiles() {
return findWelcomeFiles();
}
- /**
- * Set the validation feature of the XML parser used when parsing xml instances.
- *
- * @param webXmlValidation true to enable xml instance validation
- */
@Override
public void setXmlValidation(boolean webXmlValidation) {
this.webXmlValidation = webXmlValidation;
}
- /**
- * Get the server.xml start
class loader, false otherwise
+
+ /**
+ * @return true if the specified class loader cl
can be found in the class
+ * loader delegation chain of the start
class loader, false otherwise
*/
boolean isAncestor(ClassLoader start, ClassLoader cl) {
ClassLoader acl = start;
@@ -7173,15 +6279,14 @@ boolean isAncestor(ClassLoader start, ClassLoader cl) {
return false;
}
- /*
- * Checks whether access to the webapp class loader associated with this Context should be granted to the caller of
- * ServletContext#getClassLoader.
- *
+
+ /**
+ * Checks whether access to the webapp class loader associated with this Context should be
+ * granted to the caller of ServletContext#getClassLoader.
* If no security manager exists, this method returns immediately.
- *
- * Otherwise, it calls the security manager's checkPermission method with the getClassLoader permission if the class
- * loader of the caller of ServletContext#getClassLoader is not the same as, or an ancestor of the webapp class loader
- * associated with this Context.
+ * Otherwise, it calls the security manager's checkPermission method with the getClassLoader
+ * permission if the class loader of the caller of ServletContext#getClassLoader is not the
+ * same as, or an ancestor of the webapp class loader associated with this Context.
*/
void checkGetClassLoaderPermission(ClassLoader webappLoader) {
SecurityManager sm = System.getSecurityManager();
@@ -7190,7 +6295,7 @@ void checkGetClassLoaderPermission(ClassLoader webappLoader) {
}
// Get the current execution stack as an array of classes
- Class[] classContext = getClassContext();
+ Class>[] classContext = getClassContext();
/*
* Determine the caller of ServletContext#getClassLoader:
@@ -7255,7 +6360,7 @@ private static final class DispatchData {
public MessageBytes uriMB;
public MappingData mappingData;
- public DispatchData() {
+ private DispatchData() {
uriMB = MessageBytes.newInstance();
CharChunk uriCC = uriMB.getCharChunk();
uriCC.setLimit(-1);
diff --git a/appserver/web/web-glue/src/main/java/com/sun/enterprise/web/ContextFacade.java b/appserver/web/web-glue/src/main/java/com/sun/enterprise/web/ContextFacade.java
index 3eb565abdcc..d0af9278e8b 100644
--- a/appserver/web/web-glue/src/main/java/com/sun/enterprise/web/ContextFacade.java
+++ b/appserver/web/web-glue/src/main/java/com/sun/enterprise/web/ContextFacade.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation.
+ * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
@@ -17,7 +17,23 @@
package com.sun.enterprise.web;
-import static java.text.MessageFormat.format;
+import jakarta.servlet.Filter;
+import jakarta.servlet.FilterRegistration;
+import jakarta.servlet.RequestDispatcher;
+import jakarta.servlet.Servlet;
+import jakarta.servlet.ServletContext;
+import jakarta.servlet.ServletContextAttributeListener;
+import jakarta.servlet.ServletContextListener;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.ServletRegistration;
+import jakarta.servlet.ServletRequestAttributeListener;
+import jakarta.servlet.ServletRequestListener;
+import jakarta.servlet.SessionCookieConfig;
+import jakarta.servlet.SessionTrackingMode;
+import jakarta.servlet.descriptor.JspConfigDescriptor;
+import jakarta.servlet.http.HttpSessionAttributeListener;
+import jakarta.servlet.http.HttpSessionIdListener;
+import jakarta.servlet.http.HttpSessionListener;
import java.io.File;
import java.io.InputStream;
@@ -40,23 +56,7 @@
import org.glassfish.embeddable.web.config.SecurityConfig;
import org.glassfish.web.LogFacade;
-import jakarta.servlet.Filter;
-import jakarta.servlet.FilterRegistration;
-import jakarta.servlet.RequestDispatcher;
-import jakarta.servlet.Servlet;
-import jakarta.servlet.ServletContext;
-import jakarta.servlet.ServletContextAttributeListener;
-import jakarta.servlet.ServletContextListener;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRegistration;
-import jakarta.servlet.ServletRequestAttributeListener;
-import jakarta.servlet.ServletRequestListener;
-import jakarta.servlet.SessionCookieConfig;
-import jakarta.servlet.SessionTrackingMode;
-import jakarta.servlet.descriptor.JspConfigDescriptor;
-import jakarta.servlet.http.HttpSessionAttributeListener;
-import jakarta.servlet.http.HttpSessionIdListener;
-import jakarta.servlet.http.HttpSessionListener;
+import static java.text.MessageFormat.format;
/**
* Facade object which masks the internal Context
object from the web application.
@@ -75,15 +75,15 @@ public class ContextFacade extends WebModule {
* Wrapped web module.
*/
private WebModule context;
- private File docRoot;
- private String contextRoot;
- private ClassLoader classLoader;
+ private final File docRoot;
+ private final String contextRoot;
+ private final ClassLoader classLoader;
- private Map