Java Code Examples for org.apache.catalina.Engine#findChild()

The following examples show how to use org.apache.catalina.Engine#findChild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Remove an existing Host.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeHost(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String hostName = oname.getKeyProperty("host");
    Service service = getService(oname);
    Engine engine = service.getContainer();
    Host host = (Host) engine.findChild(hostName);

    // Remove this component from its parent component
    if(host!=null) {
        engine.removeChild(host);
    }
}
 
Example 2
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Remove an existing Host.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeHost(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String hostName = oname.getKeyProperty("host");
    Service service = getService(oname);
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(hostName);

    // Remove this component from its parent component
    if(host!=null) {
        engine.removeChild(host);
    }
}
 
Example 3
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Remove an existing Host.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeHost(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String hostName = oname.getKeyProperty("host");
    Service service = getService(oname);
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(hostName);

    // Remove this component from its parent component
    if(host!=null) {
        engine.removeChild(host);
    }
}
 
Example 4
Source File: VirtualHostClusterUtil.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static void removeVirtualHost(String hostName) {
    Engine engine = DataHolder.getInstance().getCarbonTomcatService().getTomcat().getEngine();
    Host host = (Host) engine.findChild(hostName);
    Context context = (Context) host.findChild("/");
    try {
        if (host.getState().isAvailable()) {
            if (context != null && context.getAvailable()) {
                context.setRealm(null);
                context.stop();
                context.destroy();
                log.info("Unloaded webapp from the host: " + host
                        + " as the context of: " + context);
            }
            host.removeChild(context);
            host.setRealm(null);
            host.stop();
            host.destroy();
            engine.removeChild(host);
        }
    }catch (LifecycleException e) {
        log.error("error while removing host from tomcat", e);
    }
    URLMappingHolder.getInstance().removeUrlMappingMap(
            host.getName());
    log.info("Unloaded host from the engine: " + host);

}
 
Example 5
Source File: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * 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
 * @param xmlValidation if XML descriptors should be validated
 * @param xmlNamespaceAware if the XML processor should namespace aware
 * @return the object name of the created context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent,
                                    String path,
                                    String docBase,
                                    boolean xmlValidation,
                                    boolean xmlNamespaceAware)
    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);

    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 = service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }

    // Return the corresponding MBean name
    return context.getObjectName().toString();

}
 
Example 6
Source File: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Remove an existing Context.
 *
 * @param contextName MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeContext(String contextName) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(contextName);
    String domain = oname.getDomain();
    StandardService service = (StandardService) getService(oname);

    Engine engine = service.getContainer();
    String name = oname.getKeyProperty("name");
    name = name.substring(2);
    int i = name.indexOf('/');
    String hostName = name.substring(0,i);
    String path = name.substring(i);
    ObjectName deployer = new ObjectName(domain+":type=Deployer,host="+
                                         hostName);
    String pathStr = getPathStr(path);
    if(mserver.isRegistered(deployer)) {
        mserver.invoke(deployer,"addServiced",
                       new Object[]{pathStr},
                       new String[] {"java.lang.String"});
        mserver.invoke(deployer,"unmanageApp",
                       new Object[] {pathStr},
                       new String[] {"java.lang.String"});
        mserver.invoke(deployer,"removeServiced",
                       new Object[] {pathStr},
                       new String[] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+hostName);
        Host host = (Host) engine.findChild(hostName);
        Context context = (Context) host.findChild(pathStr);
        // Remove this component from its parent component
        host.removeChild(context);
        if(context instanceof StandardContext)
        try {
            ((StandardContext)context).destroy();
        } catch (Exception e) {
            log.warn("Error during context [" + context.getName() + "] destroy ", e);
       }

    }

}
 
Example 7
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * 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();

}
 
Example 8
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Remove an existing Context.
 *
 * @param contextName MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeContext(String contextName) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(contextName);
    String domain = oname.getDomain();
    StandardService service = (StandardService) getService(oname);

    Engine engine = (Engine) service.getContainer();
    String name = oname.getKeyProperty("name");
    name = name.substring(2);
    int i = name.indexOf('/');
    String hostName = name.substring(0,i);
    String path = name.substring(i);
    ObjectName deployer = new ObjectName(domain+":type=Deployer,host="+
                                         hostName);
    String pathStr = getPathStr(path);
    if(mserver.isRegistered(deployer)) {
        mserver.invoke(deployer,"addServiced",
                       new Object[]{pathStr},
                       new String[] {"java.lang.String"});
        mserver.invoke(deployer,"unmanageApp",
                       new Object[] {pathStr},
                       new String[] {"java.lang.String"});
        mserver.invoke(deployer,"removeServiced",
                       new Object[] {pathStr},
                       new String[] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+hostName);
        Host host = (Host) engine.findChild(hostName);
        Context context = (Context) host.findChild(pathStr);
        // Remove this component from its parent component
        host.removeChild(context);
        if(context instanceof StandardContext)
        try {
            ((StandardContext)context).destroy();
        } catch (Exception e) {
            log.warn("Error during context [" + context.getName() + "] destroy ", e);
       }
   
    }

}
 
Example 9
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * 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();

}
 
Example 10
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Remove an existing Context.
 *
 * @param contextName MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeContext(String contextName) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(contextName);
    String domain = oname.getDomain();
    StandardService service = (StandardService) getService(oname);

    Engine engine = (Engine) service.getContainer();
    String name = oname.getKeyProperty("name");
    name = name.substring(2);
    int i = name.indexOf('/');
    String hostName = name.substring(0,i);
    String path = name.substring(i);
    ObjectName deployer = new ObjectName(domain+":type=Deployer,host="+
                                         hostName);
    String pathStr = getPathStr(path);
    if(mserver.isRegistered(deployer)) {
        mserver.invoke(deployer,"addServiced",
                       new Object[]{pathStr},
                       new String[] {"java.lang.String"});
        mserver.invoke(deployer,"unmanageApp",
                       new Object[] {pathStr},
                       new String[] {"java.lang.String"});
        mserver.invoke(deployer,"removeServiced",
                       new Object[] {pathStr},
                       new String[] {"java.lang.String"});
    } else {
        log.warn("Deployer not found for "+hostName);
        Host host = (Host) engine.findChild(hostName);
        Context context = (Context) host.findChild(pathStr);
        // Remove this component from its parent component
        host.removeChild(context);
        if(context instanceof StandardContext)
        try {
            ((StandardContext)context).destroy();
        } catch (Exception e) {
            log.warn("Error during context [" + context.getName() + "] destroy ", e);
       }
   
    }

}