use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class ManagerServlet method doPut.
/**
* Process a PUT request for the specified resource.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet-specified error occurs
*/
@Override
public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
StringManager smClient = StringManager.getManager(Constants.Package, request.getLocales());
// Identify the request parameters that we need
String command = request.getPathInfo();
if (command == null)
command = request.getServletPath();
String path = request.getParameter("path");
ContextName cn = null;
if (path != null) {
cn = new ContextName(path, request.getParameter("version"));
}
String tag = request.getParameter("tag");
boolean update = false;
if ((request.getParameter("update") != null) && (request.getParameter("update").equals("true"))) {
update = true;
}
// Prepare our output writer to generate the response message
response.setContentType("text/plain;charset=" + Constants.CHARSET);
PrintWriter writer = response.getWriter();
// Process the requested command
if (command == null) {
writer.println(smClient.getString("managerServlet.noCommand"));
} else if (command.equals("/deploy")) {
deploy(writer, cn, tag, update, request, smClient);
} else {
writer.println(smClient.getString("managerServlet.unknownCommand", command));
}
// Finish up the response
writer.flush();
writer.close();
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class ContextConfig method fixDocBase.
/**
* Adjust docBase.
* @throws IOException cannot access the context base path
*/
protected void fixDocBase() throws IOException {
Host host = (Host) context.getParent();
File appBase = host.getAppBaseFile();
String docBase = context.getDocBase();
if (docBase == null) {
// Trying to guess the docBase according to the path
String path = context.getPath();
if (path == null) {
return;
}
ContextName cn = new ContextName(path, context.getWebappVersion());
docBase = cn.getBaseName();
}
File file = new File(docBase);
if (!file.isAbsolute()) {
docBase = (new File(appBase, docBase)).getPath();
} else {
docBase = file.getCanonicalPath();
}
file = new File(docBase);
String origDocBase = docBase;
ContextName cn = new ContextName(context.getPath(), context.getWebappVersion());
String pathName = cn.getBaseName();
boolean unpackWARs = true;
if (host instanceof StandardHost) {
unpackWARs = ((StandardHost) host).isUnpackWARs();
if (unpackWARs && context instanceof StandardContext) {
unpackWARs = ((StandardContext) context).getUnpackWAR();
}
}
boolean docBaseInAppBase = docBase.startsWith(appBase.getPath() + File.separatorChar);
if (docBase.toLowerCase(Locale.ENGLISH).endsWith(".war") && !file.isDirectory()) {
URL war = UriUtil.buildJarUrl(new File(docBase));
if (unpackWARs) {
docBase = ExpandWar.expand(host, war, pathName);
file = new File(docBase);
docBase = file.getCanonicalPath();
if (context instanceof StandardContext) {
((StandardContext) context).setOriginalDocBase(origDocBase);
}
} else {
ExpandWar.validate(host, war, pathName);
}
} else {
File docDir = new File(docBase);
File warFile = new File(docBase + ".war");
URL war = null;
if (warFile.exists() && docBaseInAppBase) {
war = UriUtil.buildJarUrl(warFile);
}
if (docDir.exists()) {
if (war != null && unpackWARs) {
// Check if WAR needs to be re-expanded (e.g. if it has
// changed). Note: HostConfig.deployWar() takes care of
// ensuring that the correct XML file is used.
// This will be a NO-OP if the WAR is unchanged.
ExpandWar.expand(host, war, pathName);
}
} else {
if (war != null) {
if (unpackWARs) {
docBase = ExpandWar.expand(host, war, pathName);
file = new File(docBase);
docBase = file.getCanonicalPath();
} else {
docBase = warFile.getCanonicalPath();
ExpandWar.validate(host, war, pathName);
}
}
if (context instanceof StandardContext) {
((StandardContext) context).setOriginalDocBase(origDocBase);
}
}
}
// Re-calculate now docBase is a canonical path
docBaseInAppBase = docBase.startsWith(appBase.getPath() + File.separatorChar);
if (docBaseInAppBase) {
docBase = docBase.substring(appBase.getPath().length());
docBase = docBase.replace(File.separatorChar, '/');
if (docBase.startsWith("/")) {
docBase = docBase.substring(1);
}
} else {
docBase = docBase.replace(File.separatorChar, '/');
}
context.setDocBase(docBase);
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class HostConfig method deployDescriptors.
/**
* Deploy XML context descriptors.
* @param configBase The config base
* @param files The XML descriptors which should be deployed
*/
protected void deployDescriptors(File configBase, String[] files) {
if (files == null)
return;
ExecutorService es = host.getStartStopExecutor();
List<Future<?>> results = new ArrayList<>();
for (int i = 0; i < files.length; i++) {
File contextXml = new File(configBase, files[i]);
if (files[i].toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
ContextName cn = new ContextName(files[i], true);
if (isServiced(cn.getName()) || deploymentExists(cn.getName()))
continue;
results.add(es.submit(new DeployDescriptor(this, cn, contextXml)));
}
}
for (Future<?> result : results) {
try {
result.get();
} catch (Exception e) {
log.error(sm.getString("hostConfig.deployDescriptor.threaded.error"), e);
}
}
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class HostConfig method deployDirectories.
/**
* Deploy exploded webapps.
* @param appBase The base path for applications
* @param files The exploded webapps that should be deployed
*/
protected void deployDirectories(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 dir = new File(appBase, files[i]);
if (dir.isDirectory()) {
ContextName cn = new ContextName(files[i], false);
if (isServiced(cn.getName()) || deploymentExists(cn.getName()))
continue;
results.add(es.submit(new DeployDirectory(this, cn, dir)));
}
}
for (Future<?> result : results) {
try {
result.get();
} catch (Exception e) {
log.error(sm.getString("hostConfig.deployDir.threaded.error"), e);
}
}
}
use of org.apache.catalina.util.ContextName in project tomee by apache.
the class Contexts method realWarPath.
public static File realWarPath(final Context standardContext) {
if (standardContext == null) {
return null;
}
final File docBase;
Container container = standardContext;
while (container != null) {
if (container instanceof Host) {
break;
}
container = container.getParent();
}
String baseName = null;
if (standardContext.getDocBase() != null) {
File file = new File(standardContext.getDocBase());
if (!file.isAbsolute()) {
if (container == null) {
docBase = new File(engineBase(standardContext), standardContext.getDocBase());
} else {
final String appBase = ((Host) container).getAppBase();
file = new File(appBase);
if (!file.isAbsolute()) {
file = new File(engineBase(standardContext), appBase);
}
docBase = new File(file, standardContext.getDocBase());
}
} else {
docBase = file;
}
} else {
final String path = standardContext.getPath();
if (path == null) {
throw new IllegalStateException("Can't find docBase");
} else {
baseName = new ContextName(path, standardContext.getWebappVersion()).getBaseName();
docBase = new File(baseName);
}
}
if (!docBase.exists() && baseName != null) {
// for old compatibility, will be removed soon
if (Host.class.isInstance(container)) {
final File file = new File(Host.class.cast(container).getAppBaseFile(), baseName);
if (file.exists()) {
return file;
}
}
return oldRealWarPath(standardContext);
}
final String name = docBase.getName();
if (name.endsWith(".war")) {
final File extracted = new File(docBase.getParentFile(), name.substring(0, name.length() - ".war".length()));
if (extracted.exists()) {
return extracted;
}
}
return docBase;
}
Aggregations