Search in sources :

Example 41 with Service

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;
    }
}
Also used : StandardEngine(org.apache.catalina.core.StandardEngine) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service)

Example 42 with Service

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);
}
Also used : MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) ObjectName(javax.management.ObjectName)

Example 43 with 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());
}
Also used : Connector(org.apache.catalina.connector.Connector) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) ObjectName(javax.management.ObjectName)

Example 44 with Service

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();
}
Also used : ContextConfig(org.apache.catalina.startup.ContextConfig) StandardContext(org.apache.catalina.core.StandardContext) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) File(java.io.File) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) ObjectName(javax.management.ObjectName)

Example 45 with Service

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;
}
Also used : MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardService(org.apache.catalina.core.StandardService)

Aggregations

Service (org.apache.catalina.Service)62 StandardService (org.apache.catalina.core.StandardService)25 Engine (org.apache.catalina.Engine)20 Connector (org.apache.catalina.connector.Connector)20 StandardEngine (org.apache.catalina.core.StandardEngine)16 ObjectName (javax.management.ObjectName)13 StandardHost (org.apache.catalina.core.StandardHost)12 Container (org.apache.catalina.Container)8 Executor (org.apache.catalina.Executor)8 Server (org.apache.catalina.Server)8 MBeanServer (javax.management.MBeanServer)7 InstanceNotFoundException (javax.management.InstanceNotFoundException)6 MBeanException (javax.management.MBeanException)6 Host (org.apache.catalina.Host)6 File (java.io.File)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 RuntimeOperationsException (javax.management.RuntimeOperationsException)5 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)5 StandardContext (org.apache.catalina.core.StandardContext)5 JarFile (java.util.jar.JarFile)3