Search in sources :

Example 6 with StandardService

use of org.apache.catalina.core.StandardService in project tomcat by apache.

the class MBeanFactory method removeContext.

/**
     * 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);
            }
    }
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) StandardContext(org.apache.catalina.core.StandardContext) StandardService(org.apache.catalina.core.StandardService) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) ObjectName(javax.management.ObjectName)

Example 7 with StandardService

use of org.apache.catalina.core.StandardService in project tomcat by apache.

the class TesterDigestAuthenticatorPerformance method setUp.

@Before
public void setUp() throws Exception {
    ConcurrentMessageDigest.init("MD5");
    // Configure the Realm
    TesterMapRealm realm = new TesterMapRealm();
    realm.addUser(USER, PWD);
    realm.addUserRole(USER, ROLE);
    // Add the Realm to the Context
    Context context = new StandardContext();
    context.setName(CONTEXT_PATH);
    context.setRealm(realm);
    Host host = new StandardHost();
    context.setParent(host);
    Engine engine = new StandardEngine();
    host.setParent(engine);
    Service service = new StandardService();
    engine.setService(service);
    // Configure the Login config
    LoginConfig config = new LoginConfig();
    config.setRealmName(REALM);
    context.setLoginConfig(config);
    // Make the Context and Realm visible to the Authenticator
    authenticator.setContainer(context);
    authenticator.setNonceCountWindowSize(8 * 1024);
    authenticator.start();
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) TesterMapRealm(org.apache.catalina.startup.TesterMapRealm) StandardEngine(org.apache.catalina.core.StandardEngine) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) StandardService(org.apache.catalina.core.StandardService) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) Before(org.junit.Before)

Aggregations

StandardService (org.apache.catalina.core.StandardService)7 Service (org.apache.catalina.Service)4 Engine (org.apache.catalina.Engine)3 StandardEngine (org.apache.catalina.core.StandardEngine)3 MBeanServer (javax.management.MBeanServer)2 Context (org.apache.catalina.Context)2 Host (org.apache.catalina.Host)2 Server (org.apache.catalina.Server)2 StandardContext (org.apache.catalina.core.StandardContext)2 StandardHost (org.apache.catalina.core.StandardHost)2 Before (org.junit.Before)2 ObjectName (javax.management.ObjectName)1 Executor (org.apache.catalina.Executor)1 Lifecycle (org.apache.catalina.Lifecycle)1 LifecycleListener (org.apache.catalina.LifecycleListener)1 Connector (org.apache.catalina.connector.Connector)1 StandardServer (org.apache.catalina.core.StandardServer)1 TesterMapRealm (org.apache.catalina.startup.TesterMapRealm)1 LoginConfig (org.apache.tomcat.util.descriptor.web.LoginConfig)1