use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class ContextConfig method antiLocking.
protected void antiLocking() {
if ((context instanceof StandardContext) && ((StandardContext) context).getAntiResourceLocking()) {
Host host = (Host) context.getParent();
String docBase = context.getDocBase();
if (docBase == null) {
return;
}
originalDocBase = docBase;
File docBaseFile = new File(docBase);
if (!docBaseFile.isAbsolute()) {
docBaseFile = new File(host.getAppBaseFile(), docBase);
}
String path = context.getPath();
if (path == null) {
return;
}
ContextName cn = new ContextName(path, context.getWebappVersion());
docBase = cn.getBaseName();
if (originalDocBase.toLowerCase(Locale.ENGLISH).endsWith(".war")) {
antiLockingDocBase = new File(System.getProperty("java.io.tmpdir"), deploymentCount++ + "-" + docBase + ".war");
} else {
antiLockingDocBase = new File(System.getProperty("java.io.tmpdir"), deploymentCount++ + "-" + docBase);
}
antiLockingDocBase = antiLockingDocBase.getAbsoluteFile();
if (log.isDebugEnabled()) {
log.debug("Anti locking context[" + context.getName() + "] setting docBase to " + antiLockingDocBase.getPath());
}
// Cleanup just in case an old deployment is lying around
ExpandWar.delete(antiLockingDocBase);
if (ExpandWar.copy(docBaseFile, antiLockingDocBase)) {
context.setDocBase(antiLockingDocBase.getPath());
}
}
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class HostConfig method deployApps.
/**
* Deploy applications for any directories or WAR files that are found
* in our "application root" directory.
* @param name The context name which should be deployed
*/
protected void deployApps(String name) {
File appBase = host.getAppBaseFile();
File configBase = host.getConfigBaseFile();
ContextName cn = new ContextName(name, false);
String baseName = cn.getBaseName();
if (deploymentExists(cn.getName())) {
return;
}
// Deploy XML descriptor from configBase
File xml = new File(configBase, baseName + ".xml");
if (xml.exists()) {
deployDescriptor(cn, xml);
return;
}
// Deploy WAR
File war = new File(appBase, baseName + ".war");
if (war.exists()) {
deployWAR(cn, war);
return;
}
// Deploy expanded folder
File dir = new File(appBase, baseName);
if (dir.exists())
deployDirectory(cn, dir);
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class HostConfig method deployWARs.
/**
* Deploy WAR files.
* @param appBase The base path for applications
* @param files The WARs to deploy
*/
protected void deployWARs(File appBase, String[] files) {
if (files == null)
return;
ExecutorService es = host.getStartStopExecutor();
List<Future<?>> results = new ArrayList<>();
for (int i = 0; i < files.length; i++) {
if (files[i].equalsIgnoreCase("META-INF"))
continue;
if (files[i].equalsIgnoreCase("WEB-INF"))
continue;
File war = new File(appBase, files[i]);
if (files[i].toLowerCase(Locale.ENGLISH).endsWith(".war") && war.isFile() && !invalidWars.contains(files[i])) {
ContextName cn = new ContextName(files[i], true);
if (isServiced(cn.getName())) {
continue;
}
if (deploymentExists(cn.getName())) {
DeployedApplication app = deployed.get(cn.getName());
boolean unpackWAR = unpackWARs;
if (unpackWAR && host.findChild(cn.getName()) instanceof StandardContext) {
unpackWAR = ((StandardContext) host.findChild(cn.getName())).getUnpackWAR();
}
if (!unpackWAR && app != null) {
// Need to check for a directory that should not be
// there
File dir = new File(appBase, cn.getBaseName());
if (dir.exists()) {
if (!app.loggedDirWarning) {
log.warn(sm.getString("hostConfig.deployWar.hiddenDir", dir.getAbsoluteFile(), war.getAbsoluteFile()));
app.loggedDirWarning = true;
}
} else {
app.loggedDirWarning = false;
}
}
continue;
}
// Check for WARs with /../ /./ or similar sequences in the name
if (!validateContextPath(appBase, cn.getBaseName())) {
log.error(sm.getString("hostConfig.illegalWarName", files[i]));
invalidWars.add(files[i]);
continue;
}
results.add(es.submit(new DeployWar(this, cn, war)));
}
}
for (Future<?> result : results) {
try {
result.get();
} catch (Exception e) {
log.error(sm.getString("hostConfig.deployWar.threaded.error"), e);
}
}
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class HostConfig method checkUndeploy.
/**
* Check for old versions of applications using parallel deployment that are
* now unused (have no active sessions) and undeploy any that are found.
*/
public synchronized void checkUndeploy() {
// Need ordered set of names
SortedSet<String> sortedAppNames = new TreeSet<>();
sortedAppNames.addAll(deployed.keySet());
if (sortedAppNames.size() < 2) {
return;
}
Iterator<String> iter = sortedAppNames.iterator();
ContextName previous = new ContextName(iter.next(), false);
do {
ContextName current = new ContextName(iter.next(), false);
if (current.getPath().equals(previous.getPath())) {
// Current and previous are same path - current will always
// be a later version
Context previousContext = (Context) host.findChild(previous.getName());
Context currentContext = (Context) host.findChild(current.getName());
if (previousContext != null && currentContext != null && currentContext.getState().isAvailable() && !isServiced(previous.getName())) {
Manager manager = previousContext.getManager();
if (manager != null) {
int sessionCount;
if (manager instanceof DistributedManager) {
sessionCount = ((DistributedManager) manager).getActiveSessionsFull();
} else {
sessionCount = manager.getActiveSessions();
}
if (sessionCount == 0) {
if (log.isInfoEnabled()) {
log.info(sm.getString("hostConfig.undeployVersion", previous.getName()));
}
DeployedApplication app = deployed.get(previous.getName());
String[] resources = app.redeployResources.keySet().toArray(new String[0]);
// Version is unused - undeploy it completely
// The -1 is a 'trick' to ensure all redeploy
// resources are removed
undeploy(app);
deleteRedeployResources(app, resources, -1, true);
}
}
}
}
previous = current;
} while (iter.hasNext());
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class FailedContext method getMBeanKeyProperties.
@Override
public String getMBeanKeyProperties() {
Container c = this;
StringBuilder keyProperties = new StringBuilder();
int containerCount = 0;
// each container
while (!(c instanceof Engine)) {
if (c instanceof Context) {
keyProperties.append(",context=");
ContextName cn = new ContextName(c.getName(), false);
keyProperties.append(cn.getDisplayName());
} else if (c instanceof Host) {
keyProperties.append(",host=");
keyProperties.append(c.getName());
} else if (c == null) {
// May happen in unit testing and/or some embedding scenarios
keyProperties.append(",container");
keyProperties.append(containerCount++);
keyProperties.append("=null");
break;
} else {
// Should never happen...
keyProperties.append(",container");
keyProperties.append(containerCount++);
keyProperties.append('=');
keyProperties.append(c.getName());
}
c = c.getParent();
}
return keyProperties.toString();
}
Aggregations