use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class MBeanUtils method createObjectName.
/**
* Create an <code>ObjectName</code> for this
* <code>ContextResourceLink</code> object.
*
* @param domain Domain in which this name is to be created
* @param resourceLink The ContextResourceLink to be named
* @return a new object name
* @exception MalformedObjectNameException if a name cannot be created
*/
public static ObjectName createObjectName(String domain, ContextResourceLink resourceLink) throws MalformedObjectNameException {
ObjectName name = null;
String quotedResourceLinkName = ObjectName.quote(resourceLink.getName());
Object container = resourceLink.getNamingResources().getContainer();
if (container instanceof Server) {
name = new ObjectName(domain + ":type=ResourceLink" + ",resourcetype=Global" + ",name=" + quotedResourceLinkName);
} else if (container instanceof Context) {
Context context = ((Context) container);
ContextName cn = new ContextName(context.getName(), false);
Container host = context.getParent();
name = new ObjectName(domain + ":type=ResourceLink" + ",resourcetype=Context,host=" + host.getName() + ",context=" + cn.getDisplayName() + ",name=" + quotedResourceLinkName);
}
return (name);
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class MBeanUtils method createObjectName.
/**
* Create an <code>ObjectName</code> for this
* <code>ContextResource</code> object.
*
* @param domain Domain in which this name is to be created
* @param resource The ContextResource to be named
* @return a new object name
* @exception MalformedObjectNameException if a name cannot be created
*/
public static ObjectName createObjectName(String domain, ContextResource resource) throws MalformedObjectNameException {
ObjectName name = null;
String quotedResourceName = ObjectName.quote(resource.getName());
Object container = resource.getNamingResources().getContainer();
if (container instanceof Server) {
name = new ObjectName(domain + ":type=Resource" + ",resourcetype=Global,class=" + resource.getType() + ",name=" + quotedResourceName);
} else if (container instanceof Context) {
Context context = ((Context) container);
ContextName cn = new ContextName(context.getName(), false);
Container host = context.getParent();
name = new ObjectName(domain + ":type=Resource" + ",resourcetype=Context,host=" + host.getName() + ",context=" + cn.getDisplayName() + ",class=" + resource.getType() + ",name=" + quotedResourceName);
}
return (name);
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class StandardContextSF method store.
/**
* Store a Context as Separate file as configFile value from context exists.
* filename can be relative to catalina.base.
*
* @see org.apache.catalina.storeconfig.IStoreFactory#store(java.io.PrintWriter,
* int, java.lang.Object)
*/
@Override
public void store(PrintWriter aWriter, int indent, Object aContext) throws Exception {
if (aContext instanceof StandardContext) {
StoreDescription desc = getRegistry().findDescription(aContext.getClass());
if (desc.isStoreSeparate()) {
URL configFile = ((StandardContext) aContext).getConfigFile();
if (configFile != null) {
if (desc.isExternalAllowed()) {
if (desc.isBackup())
storeWithBackup((StandardContext) aContext);
else
storeContextSeparate(aWriter, indent, (StandardContext) aContext);
return;
}
} else if (desc.isExternalOnly()) {
// Set a configFile so that the configuration is actually saved
Context context = ((StandardContext) aContext);
Host host = (Host) context.getParent();
File configBase = host.getConfigBaseFile();
ContextName cn = new ContextName(context.getName(), false);
String baseName = cn.getBaseName();
File xml = new File(configBase, baseName + ".xml");
context.setConfigFile(xml.toURI().toURL());
if (desc.isBackup())
storeWithBackup((StandardContext) aContext);
else
storeContextSeparate(aWriter, indent, (StandardContext) aContext);
return;
}
}
}
super.store(aWriter, indent, aContext);
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class ContainerBase 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 Wrapper) {
keyProperties.insert(0, ",servlet=");
keyProperties.insert(9, c.getName());
} else if (c instanceof Context) {
keyProperties.insert(0, ",context=");
ContextName cn = new ContextName(c.getName(), false);
keyProperties.insert(9, cn.getDisplayName());
} else if (c instanceof Host) {
keyProperties.insert(0, ",host=");
keyProperties.insert(6, 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();
}
use of org.apache.catalina.util.ContextName in project tomcat by apache.
the class HTMLManagerServlet method upload.
protected String upload(HttpServletRequest request, StringManager smClient) {
String message = "";
try {
while (true) {
Part warPart = request.getPart("deployWar");
if (warPart == null) {
message = smClient.getString("htmlManagerServlet.deployUploadNoFile");
break;
}
String filename = warPart.getSubmittedFileName();
if (!filename.toLowerCase(Locale.ENGLISH).endsWith(".war")) {
message = smClient.getString("htmlManagerServlet.deployUploadNotWar", filename);
break;
}
// Get the filename if uploaded name includes a path
if (filename.lastIndexOf('\\') >= 0) {
filename = filename.substring(filename.lastIndexOf('\\') + 1);
}
if (filename.lastIndexOf('/') >= 0) {
filename = filename.substring(filename.lastIndexOf('/') + 1);
}
// Identify the appBase of the owning Host of this Context
// (if any)
File file = new File(host.getAppBaseFile(), filename);
if (file.exists()) {
message = smClient.getString("htmlManagerServlet.deployUploadWarExists", filename);
break;
}
ContextName cn = new ContextName(filename, true);
String name = cn.getName();
if ((host.findChild(name) != null) && !isDeployed(name)) {
message = smClient.getString("htmlManagerServlet.deployUploadInServerXml", filename);
break;
}
if (isServiced(name)) {
message = smClient.getString("managerServlet.inService", name);
} else {
addServiced(name);
try {
warPart.write(file.getAbsolutePath());
// Perform new deployment
check(name);
} finally {
removeServiced(name);
}
}
break;
}
} catch (Exception e) {
message = smClient.getString("htmlManagerServlet.deployUploadFail", e.getMessage());
log(message, e);
}
return message;
}
Aggregations