import java.util.Stack;
import java.util.TreeMap;
import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicLong;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanNotificationInfo;
import org.apache.catalina.Container;
import org.apache.catalina.ContainerListener;
import org.apache.catalina.Context;
-import org.apache.catalina.Engine;
import org.apache.catalina.Globals;
import org.apache.catalina.Host;
import org.apache.catalina.InstanceListener;
/**
* The notification sequence number.
*/
- private long sequenceNumber = 0;
+ private AtomicLong sequenceNumber = new AtomicLong(0);
/**
* The status code error pages for this web application, keyed by
(sm.getString("standardContext.notWrapper"));
}
- Wrapper wrapper = (Wrapper) child;
boolean isJspServlet = "jsp".equals(child.getName());
// Allow webapp to override JspServlet inherited from global web.xml.
if (findChild(name) == null)
throw new IllegalArgumentException
(sm.getString("standardContext.servletMap.name", name));
- pattern = adjustURLPattern(RequestUtil.URLDecode(pattern));
- if (!validateURLPattern(pattern))
+ String decodedPattern = adjustURLPattern(RequestUtil.URLDecode(pattern));
+ if (!validateURLPattern(decodedPattern))
throw new IllegalArgumentException
- (sm.getString("standardContext.servletMap.pattern", pattern));
+ (sm.getString("standardContext.servletMap.pattern", decodedPattern));
// Add this mapping to our registered set
synchronized (servletMappingsLock) {
- String name2 = servletMappings.get(pattern);
+ String name2 = servletMappings.get(decodedPattern);
if (name2 != null) {
// Don't allow more than one servlet on the same pattern
Wrapper wrapper = (Wrapper) findChild(name2);
- wrapper.removeMapping(pattern);
- mapper.removeWrapper(pattern);
+ wrapper.removeMapping(decodedPattern);
+ mapper.removeWrapper(decodedPattern);
}
- servletMappings.put(pattern, name);
+ servletMappings.put(decodedPattern, name);
}
Wrapper wrapper = (Wrapper) findChild(name);
- wrapper.addMapping(pattern);
+ wrapper.addMapping(decodedPattern);
// Update context mapper
- mapper.addWrapper(pattern, wrapper, jspWildCard,
+ mapper.addWrapper(decodedPattern, wrapper, jspWildCard,
resourceOnlyServlets.contains(name));
- fireContainerEvent("addServletMapping", pattern);
+ fireContainerEvent("addServletMapping", decodedPattern);
}
private int insertPoint = 0;
/**
- * Reset the set to the initial state.
- */
- public void clear() {
- synchronized (lock) {
- array = new FilterMap[0];
- insertPoint = 0;
- }
- }
-
- /**
* Return the set of filter mappings.
*/
public FilterMap[] asArray() {
// Send j2ee.state.starting notification
if (this.getObjectName() != null) {
- Notification notification = new Notification("j2ee.state.starting",
- this.getObjectName(),
- sequenceNumber++);
+ Notification notification = new Notification("j2ee.state.starting",
+ this.getObjectName(), sequenceNumber.getAndIncrement());
broadcaster.sendNotification(notification);
}
if (log.isDebugEnabled())
log.debug("Configuring default Resources");
try {
- if ((docBase != null) && (docBase.endsWith(".war")) && (!(new File(getBasePath())).isDirectory()))
+ if ((getDocBase() != null) && (getDocBase().endsWith(".war")) &&
+ (!(new File(getBasePath())).isDirectory()))
setResources(new WARDirContext());
else
setResources(new FileDirContext());
}
if (ok && isUseNaming()) {
- if (namingContextListener == null) {
- namingContextListener = new NamingContextListener();
- namingContextListener.setName(getNamingContextName());
- addLifecycleListener(namingContextListener);
+ if (getNamingContextListener() == null) {
+ NamingContextListener ncl = new NamingContextListener();
+ ncl.setName(getNamingContextName());
+ addLifecycleListener(ncl);
+ setNamingContextListener(ncl);
}
}
oldCCL = bindThread();
if (ok ) {
- if (instanceManager == null) {
+ if (getInstanceManager() == null) {
javax.naming.Context context = null;
- if (isUseNaming() && namingContextListener != null) {
- context = namingContextListener.getEnvContext();
+ if (isUseNaming() && getNamingContextListener() != null) {
+ context = getNamingContextListener().getEnvContext();
}
Map<String, Map<String, String>> injectionMap = buildInjectionMap(
getIgnoreAnnotations() ? new NamingResources(): getNamingResources());
- instanceManager = new DefaultInstanceManager(
- context, injectionMap, this, this.getClass().getClassLoader());
- getServletContext().setAttribute(InstanceManager.class.getName(), instanceManager);
+ setInstanceManager(new DefaultInstanceManager(context,
+ injectionMap, this, this.getClass().getClassLoader()));
+ getServletContext().setAttribute(
+ InstanceManager.class.getName(), getInstanceManager());
}
}
// forget to cleanup
Boolean listenerStarted =
temporaryExecutor.execute(new Callable<Boolean>() {
+ @Override
public Boolean call() throws Exception {
ClassLoader old = bindThread();
try {
- return listenerStart();
+ return Boolean.valueOf(listenerStart());
} finally {
unbindThread(old);
}
}
});
- if (!listenerStarted) {
+ if (!listenerStarted.booleanValue()) {
log.error( "Error listenerStart");
ok = false;
}
// to cleanup
Boolean filterStarted =
temporaryExecutor.execute(new Callable<Boolean>() {
+ @Override
public Boolean call() throws Exception {
ClassLoader old = bindThread();
try {
- return filterStart();
+ return Boolean.valueOf(filterStart());
} finally {
unbindThread(old);
}
}
});
- if (!filterStarted) {
+ if (!filterStarted.booleanValue()) {
log.error("Error filterStart");
ok = false;
}
// case the Servlets register some ThreadLocals that they forget
// to cleanup
temporaryExecutor.execute(new Callable<Void>() {
+ @Override
public Void call() throws Exception {
ClassLoader old = bindThread();
try {
// Send j2ee.state.running notification
if (ok && (this.getObjectName() != null)) {
Notification notification =
- new Notification("j2ee.state.running", this.getObjectName(),
- sequenceNumber++);
+ new Notification("j2ee.state.running", this.getObjectName(),
+ sequenceNumber.getAndIncrement());
broadcaster.sendNotification(notification);
}
if (this.getObjectName() != null) {
Notification notification =
new Notification("j2ee.state.stopping", this.getObjectName(),
- sequenceNumber++);
+ sequenceNumber.getAndIncrement());
broadcaster.sendNotification(notification);
}
// forget to cleanup
DedicatedThreadExecutor.executeInOwnThread(
new Callable<Void>() {
+ @Override
public Void call() throws Exception {
ClassLoader old = bindThread();
try {
if (this.getObjectName() != null) {
Notification notification =
new Notification("j2ee.state.stopped", this.getObjectName(),
- sequenceNumber++);
+ sequenceNumber.getAndIncrement());
broadcaster.sendNotification(notification);
}
// Send j2ee.object.deleted notification
Notification notification =
new Notification("j2ee.object.deleted", this.getObjectName(),
- sequenceNumber++);
+ sequenceNumber.getAndIncrement());
broadcaster.sendNotification(notification);
unregister(onameNamingResources);
/**
- * Get config base.
- */
- public File getConfigBase() {
- File configBase =
- new File(System.getProperty(Globals.CATALINA_BASE_PROP), "conf");
- if (!configBase.exists()) {
- return null;
- }
- Container container = this;
- Container host = null;
- Container engine = null;
- while (container != null) {
- if (container instanceof Host)
- host = container;
- if (container instanceof Engine)
- engine = container;
- container = container.getParent();
- }
- if (engine != null) {
- configBase = new File(configBase, engine.getName());
- }
- if (host != null) {
- configBase = new File(configBase, host.getName());
- }
- if (saveConfig) {
- configBase.mkdirs();
- }
- return configBase;
- }
-
-
- /**
* Get naming context full name.
*/
private String getNamingContextName() {
catalinaHomePath = catalinaHome.getCanonicalPath();
dir = new File(catalinaHomePath, workDir);
} catch (IOException e) {
+ log.warn(sm.getString("standardContext.workCreateException",
+ workDir, catalinaHomePath, getName()), e);
}
}
- dir.mkdirs();
+ if (!dir.exists() && !dir.mkdirs()) {
+ log.warn(sm.getString("standardContext.workCreateFail", dir,
+ getName()));
+ }
// Set the appropriate servlet context attribute
if (context == null) {
// Send j2ee.object.created notification
if (this.getObjectName() != null) {
- Notification notification = new Notification(
- "j2ee.object.created",
- this.getObjectName(),
- sequenceNumber++);
+ Notification notification = new Notification("j2ee.object.created",
+ this.getObjectName(), sequenceNumber.getAndIncrement());
broadcaster.sendNotification(notification);
}
}