use of org.apache.catalina.Service in project tomcat70 by apache.
the class MBeanFactory method getParentContainerFromChild.
/**
* Get Parent ContainerBase to add its child component
* from child component's ObjectName as a String
*/
private ContainerBase getParentContainerFromChild(ObjectName oname) throws Exception {
String hostName = oname.getKeyProperty("host");
String path = oname.getKeyProperty("path");
Service service = getService(oname);
StandardEngine engine = (StandardEngine) service.getContainer();
if (hostName == null) {
// child's container is Engine
return engine;
} else if (path == null) {
// child's container is Host
StandardHost host = (StandardHost) engine.findChild(hostName);
return host;
} else {
// child's container is Context
StandardHost host = (StandardHost) engine.findChild(hostName);
path = getPathStr(path);
StandardContext context = (StandardContext) host.findChild(path);
return context;
}
}
use of org.apache.catalina.Service in project tomcat70 by apache.
the class MBeanFactory method removeService.
/**
* Remove an existing Service.
*
* @param name MBean Name of the component to remove
*
* @exception Exception if a component cannot be removed
*/
public void removeService(String name) throws Exception {
if (!(container instanceof Server)) {
throw new Exception();
}
// Acquire a reference to the component to be removed
ObjectName oname = new ObjectName(name);
Service service = getService(oname);
((Server) container).removeService(service);
}
use of org.apache.catalina.Service in project tomcat70 by apache.
the class MBeanFactory method createConnector.
/**
* Create a new Connector
*
* @param parent MBean Name of the associated parent component
* @param address The IP address on which to bind
* @param port TCP port number to listen on
* @param isAjp Create a AJP/1.3 Connector
* @param isSSL Create a secure Connector
*
* @exception Exception if an MBean cannot be created or registered
*/
private String createConnector(String parent, String address, int port, boolean isAjp, boolean isSSL) throws Exception {
Connector retobj = new Connector();
if ((address != null) && (address.length() > 0)) {
retobj.setProperty("address", address);
}
// Set port number
retobj.setPort(port);
// Set the protocol
retobj.setProtocol(isAjp ? "AJP/1.3" : "HTTP/1.1");
// Set SSL
retobj.setSecure(isSSL);
retobj.setScheme(isSSL ? "https" : "http");
// Add the new instance to its parent component
// FIX ME - addConnector will fail
ObjectName pname = new ObjectName(parent);
Service service = getService(pname);
service.addConnector(retobj);
// Return the corresponding MBean name
ObjectName coname = retobj.getObjectName();
return (coname.toString());
}
use of org.apache.catalina.Service in project tomcat70 by apache.
the class MBeanFactory method createStandardContext.
/**
* Create a new StandardContext.
*
* @param parent MBean Name of the associated parent component
* @param path The context path for this Context
* @param docBase Document base directory (or WAR) for this Context
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createStandardContext(String parent, String path, String docBase, boolean xmlValidation, boolean xmlNamespaceAware, boolean tldValidation, boolean tldNamespaceAware) throws Exception {
// Create a new StandardContext instance
StandardContext context = new StandardContext();
path = getPathStr(path);
context.setPath(path);
context.setDocBase(docBase);
context.setXmlValidation(xmlValidation);
context.setXmlNamespaceAware(xmlNamespaceAware);
context.setTldValidation(tldValidation);
context.setTldNamespaceAware(tldNamespaceAware);
ContextConfig contextConfig = new ContextConfig();
context.addLifecycleListener(contextConfig);
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ObjectName deployer = new ObjectName(pname.getDomain() + ":type=Deployer,host=" + pname.getKeyProperty("host"));
if (mserver.isRegistered(deployer)) {
String contextName = context.getName();
mserver.invoke(deployer, "addServiced", new Object[] { contextName }, new String[] { "java.lang.String" });
String configPath = (String) mserver.getAttribute(deployer, "configBaseName");
String baseName = context.getBaseName();
File configFile = new File(new File(configPath), baseName + ".xml");
if (configFile.isFile()) {
context.setConfigFile(configFile.toURI().toURL());
}
mserver.invoke(deployer, "manageApp", new Object[] { context }, new String[] { "org.apache.catalina.Context" });
mserver.invoke(deployer, "removeServiced", new Object[] { contextName }, new String[] { "java.lang.String" });
} else {
log.warn("Deployer not found for " + pname.getKeyProperty("host"));
Service service = getService(pname);
Engine engine = (Engine) service.getContainer();
Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
host.addChild(context);
}
// Return the corresponding MBean name
return context.getObjectName().toString();
}
use of org.apache.catalina.Service in project tomcat70 by apache.
the class MBeanFactory method getService.
private Service getService(ObjectName oname) throws Exception {
if (container instanceof Service) {
// Don't bother checking the domain - this is the only option
return (Service) container;
}
StandardService service = null;
String domain = oname.getDomain();
if (container instanceof Server) {
Service[] services = ((Server) container).findServices();
for (int i = 0; i < services.length; i++) {
service = (StandardService) services[i];
if (domain.equals(service.getObjectName().getDomain())) {
break;
}
}
}
if (service == null || !service.getObjectName().getDomain().equals(domain)) {
throw new Exception("Service with the domain is not found");
}
return service;
}
Aggregations