org.apache.catalina.Host - java examples

Here are the examples of the java api org.apache.catalina.Host taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : HostManagerServlet.java
Copyright Apache License 2.0
Author : apache
/**
 * Remove the specified host.
 *
 * @param writer Writer to render results to
 * @param name host name
 */
protected synchronized void remove(PrintWriter writer, String name, StringManager smClient) {
    if (debug >= 1) {
        log(sm.getString("hostManagerServlet.remove", name));
    }
    // Validate the requested host name
    if ((name == null) || name.length() == 0) {
        writer.println(smClient.getString("hostManagerServlet.invalidHostName", name));
        return;
    }
    // Check if host exists
    if (engine.findChild(name) == null) {
        writer.println(smClient.getString("hostManagerServlet.noHost", name));
        return;
    }
    // Prevent removing our own host
    if (engine.findChild(name) == installedHost) {
        writer.println(smClient.getString("hostManagerServlet.cannotRemoveOwnHost", name));
        return;
    }
    // Remove host
    // Note that the host will not get physically removed
    try {
        Container child = engine.findChild(name);
        engine.removeChild(child);
        if (child instanceof ContainerBase)
            ((ContainerBase) child).destroy();
    } catch (Exception e) {
        writer.println(smClient.getString("hostManagerServlet.exception", e.toString()));
        return;
    }
    Host host = (StandardHost) engine.findChild(name);
    if (host == null) {
        writer.println(smClient.getString("hostManagerServlet.remove", name));
    } else {
        // Something failed
        writer.println(smClient.getString("hostManagerServlet.removeFailed", name));
    }
}

19 View Complete Implementation : TestTomcat.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetCustomContextPerAddWebappWithNullHost() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced(ReplicatedContext.clreplaced.getName());
    }
    File appFile = new File("test/deployment/context.war");
    Context context = tomcat.addWebapp(null, "/test", appFile.getAbsolutePath());
    replacedert.replacedertEquals(ReplicatedContext.clreplaced.getName(), context.getClreplaced().getName());
}

19 View Complete Implementation : Tomcat.java
Copyright Apache License 2.0
Author : apache
/*
     * Uses essentially the same logic as {@link ContainerBase#logName()}.
     */
private String getLoggerName(Host host, String contextName) {
    if (host == null) {
        host = getHost();
    }
    StringBuilder loggerName = new StringBuilder();
    loggerName.append(ContainerBase.clreplaced.getName());
    loggerName.append(".[");
    // Engine name
    loggerName.append(host.getParent().getName());
    loggerName.append("].[");
    // Host name
    loggerName.append(host.getName());
    loggerName.append("].[");
    // Context name
    if (contextName == null || contextName.equals("")) {
        loggerName.append("/");
    } else if (contextName.startsWith("##")) {
        loggerName.append("/");
        loggerName.append(contextName);
    }
    loggerName.append(']');
    return loggerName.toString();
}

19 View Complete Implementation : Tomcat.java
Copyright Apache License 2.0
Author : apache
/**
 * @see #addContext(String, String)
 */
public Context addContext(Host host, String contextPath, String dir) {
    return addContext(host, contextPath, contextPath, dir);
}

19 View Complete Implementation : TestTomcat.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetCustomContextPerAddWebappWithHost() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced(ReplicatedContext.clreplaced.getName());
    }
    File appFile = new File("test/deployment/context.war");
    Context context = tomcat.addWebapp(host, "/test", appFile.getAbsolutePath());
    replacedert.replacedertEquals(ReplicatedContext.clreplaced.getName(), context.getClreplaced().getName());
}

19 View Complete Implementation : MapperListener.java
Copyright Apache License 2.0
Author : apache
/**
 * Unregister host.
 */
private void unregisterHost(Host host) {
    String hostname = host.getName();
    mapper.removeHost(hostname);
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("mapperListener.unregisterHost", hostname, domain, service));
    }
}

19 View Complete Implementation : MapperListener.java
Copyright Apache License 2.0
Author : apache
// ------------------------------------------------------- Lifecycle Methods
@Override
public void startInternal() throws LifecycleException {
    setState(LifecycleState.STARTING);
    Engine engine = service.getContainer();
    if (engine == null) {
        return;
    }
    findDefaultHost();
    addListeners(engine);
    Container[] conHosts = engine.findChildren();
    for (Container conHost : conHosts) {
        Host host = (Host) conHost;
        if (!LifecycleState.NEW.equals(host.getState())) {
            // Registering the host will register the context and wrappers
            registerHost(host);
        }
    }
}

19 View Complete Implementation : Tomcat.java
Copyright MIT License
Author : chenmudu
/**
 * Create the configured {@link Context} for the given <code>host</code>.
 * The default constructor of the clreplaced that was configured with
 * {@link StandardHost#setContextClreplaced(String)} will be used
 *
 * @param host
 *            host for which the {@link Context} should be created, or
 *            <code>null</code> if default host should be used
 * @param url
 *            path of the webapp which should get the {@link Context}
 * @return newly created {@link Context}
 */
private Context createContext(Host host, String url) {
    String contextClreplaced = StandardContext.clreplaced.getName();
    if (host == null) {
        host = this.getHost();
    }
    if (host instanceof StandardHost) {
        contextClreplaced = ((StandardHost) host).getContextClreplaced();
    }
    try {
        return (Context) Clreplaced.forName(contextClreplaced).getConstructor().newInstance();
    } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClreplacedNotFoundException e) {
        throw new IllegalArgumentException("Can't instantiate context-clreplaced " + contextClreplaced + " for host " + host + " and url " + url, e);
    }
}

19 View Complete Implementation : Tomcat.java
Copyright Apache License 2.0
Author : wangyingjie
/**
 * Sets the current host - all future webapps will
 * be added to this host. When tomcat starts, the
 * host will be the default host.
 *
 * @param host
 */
public void setHost(Host host) {
    this.host = host;
}

19 View Complete Implementation : TestTomcat.java
Copyright MIT License
Author : chenmudu
@Test
public void testGetCustomContextPerAddWebappWithNullHost() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced(ReplicatedContext.clreplaced.getName());
    }
    File appFile = new File("test/deployment/context.war");
    Context context = tomcat.addWebapp(null, "/test", appFile.getAbsolutePath());
    replacedert.replacedertEquals(ReplicatedContext.clreplaced.getName(), context.getClreplaced().getName());
}

19 View Complete Implementation : Tomcat.java
Copyright Apache License 2.0
Author : apache
/**
 * Sets the current host - all future webapps will
 * be added to this host. When tomcat starts, the
 * host will be the default host.
 *
 * @param host
 */
public void setHost(Host host) {
    this.host = host;
}

19 View Complete Implementation : TestTomcat.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetBrokenContextPerAddWepapp() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced("InvalidContextClreplacedName");
    }
    try {
        File appFile = new File("test/deployment/context.war");
        tomcat.addWebapp(null, "/test", appFile.getAbsolutePath());
        replacedert.fail();
    } catch (IllegalArgumentException e) {
    // OK
    }
}

19 View Complete Implementation : Tomcat.java
Copyright Apache License 2.0
Author : apache
/**
 * @see #addWebapp(String, String)
 *
 * @deprecated Use {@link
 *             #addWebapp(Host, String, String, LifecycleListener)} instead
 */
@Deprecated
public Context addWebapp(Host host, String contextPath, String docBase, ContextConfig config) {
    return addWebapp(host, contextPath, docBase, (LifecycleListener) config);
}

19 View Complete Implementation : HostManagerServlet.java
Copyright MIT License
Author : chenmudu
/**
 * Remove the specified host.
 *
 * @param writer Writer to render results to
 * @param name host name
 * @param smClient StringManager for the client's locale
 */
protected synchronized void remove(PrintWriter writer, String name, StringManager smClient) {
    if (debug >= 1) {
        log(sm.getString("hostManagerServlet.remove", name));
    }
    // Validate the requested host name
    if ((name == null) || name.length() == 0) {
        writer.println(smClient.getString("hostManagerServlet.invalidHostName", name));
        return;
    }
    // Check if host exists
    if (engine.findChild(name) == null) {
        writer.println(smClient.getString("hostManagerServlet.noHost", name));
        return;
    }
    // Prevent removing our own host
    if (engine.findChild(name) == installedHost) {
        writer.println(smClient.getString("hostManagerServlet.cannotRemoveOwnHost", name));
        return;
    }
    // Remove host
    // Note that the host will not get physically removed
    try {
        Container child = engine.findChild(name);
        engine.removeChild(child);
        if (child instanceof ContainerBase)
            ((ContainerBase) child).destroy();
    } catch (Exception e) {
        writer.println(smClient.getString("hostManagerServlet.exception", e.toString()));
        return;
    }
    Host host = (StandardHost) engine.findChild(name);
    if (host == null) {
        writer.println(smClient.getString("hostManagerServlet.removeSuccess", name));
    } else {
        // Something failed
        writer.println(smClient.getString("hostManagerServlet.removeFailed", name));
    }
}

19 View Complete Implementation : Tomcat.java
Copyright MIT License
Author : chenmudu
/**
 * @param host The host in which the context will be deployed
 * @param contextPath The context mapping to use, "" for root context.
 * @param docBase Base directory for the context, for static files.
 *  Must exist, relative to the server home
 * @param config Custom context configurator helper
 * @return the deployed context
 * @see #addWebapp(String, String)
 *
 * @deprecated Use {@link
 *             #addWebapp(Host, String, String, LifecycleListener)} instead
 */
@Deprecated
public Context addWebapp(Host host, String contextPath, String docBase, ContextConfig config) {
    return addWebapp(host, contextPath, docBase, (LifecycleListener) config);
}

19 View Complete Implementation : TestTomcat.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetCustomContextPerAddContextWithHost() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced(ReplicatedContext.clreplaced.getName());
    }
    // No file system docBase required
    Context ctx = tomcat.addContext(host, "", null);
    replacedert.replacedertEquals(ReplicatedContext.clreplaced.getName(), ctx.getClreplaced().getName());
}

19 View Complete Implementation : Tomcat.java
Copyright Apache License 2.0
Author : apache
/**
 * Create the configured {@link Context} for the given <code>host</code>.
 * The default constructor of the clreplaced that was configured with
 * {@link StandardHost#setContextClreplaced(String)} will be used
 *
 * @param host
 *            host for which the {@link Context} should be created, or
 *            <code>null</code> if default host should be used
 * @param url
 *            path of the webapp which should get the {@link Context}
 * @return newly created {@link Context}
 */
private Context createContext(Host host, String url) {
    String contextClreplaced = StandardContext.clreplaced.getName();
    if (host == null) {
        host = this.getHost();
    }
    if (host instanceof StandardHost) {
        contextClreplaced = ((StandardHost) host).getContextClreplaced();
    }
    try {
        return (Context) Clreplaced.forName(contextClreplaced).getConstructor().newInstance();
    } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClreplacedNotFoundException e) {
        throw new IllegalArgumentException("Can't instantiate context-clreplaced " + contextClreplaced + " for host " + host + " and url " + url, e);
    }
}

19 View Complete Implementation : TestTomcat.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetBrokenContextPerAddContext() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced("InvalidContextClreplacedName");
    }
    // No file system docBase required
    try {
        tomcat.addContext(null, "", null);
        replacedert.fail();
    } catch (IllegalArgumentException e) {
    // OK
    }
}

19 View Complete Implementation : Tomcat.java
Copyright MIT License
Author : chenmudu
private void silence(Host host, String contextPath) {
    String loggerName = getLoggerName(host, contextPath);
    Logger logger = Logger.getLogger(loggerName);
    pinnedLoggers.put(loggerName, logger);
    if (silent) {
        logger.setLevel(Level.WARNING);
    } else {
        logger.setLevel(Level.INFO);
    }
}

19 View Complete Implementation : FrameworkListener.java
Copyright Apache License 2.0
Author : apache
protected void registerListenersForHost(Host host) {
    for (Container contextContainer : host.findChildren()) {
        Context context = (Context) contextContainer;
        registerContextListener(context);
    }
}

19 View Complete Implementation : Tomcat.java
Copyright Apache License 2.0
Author : apache
/**
 * @see #addWebapp(String, String)
 *
 * @param name Ignored. The path will be used
 *
 * @deprecated Use {@link #addWebapp(Host, String, String)}
 */
@Deprecated
public Context addWebapp(Host host, String contextPath, String name, String docBase) {
    return addWebapp(host, contextPath, docBase);
}

19 View Complete Implementation : TestTomcat.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetBrokenContextPerAddContext() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced("InvalidContextClreplacedName");
    }
    // No file system docBase required
    try {
        tomcat.addContext(null, "", null);
        replacedert.fail();
    } catch (IllegalArgumentException e) {
    // OK
    }
}

19 View Complete Implementation : Tomcat.java
Copyright MIT License
Author : chenmudu
/**
 * @param host The host in which the context will be deployed
 * @param contextPath The context mapping to use, "" for root context.
 * @param contextName The context name
 * @param dir Base directory for the context, for static files.
 *  Must exist, relative to the server home
 * @return the deployed context
 * @see #addContext(String, String)
 */
public Context addContext(Host host, String contextPath, String contextName, String dir) {
    silence(host, contextName);
    Context ctx = createContext(host, contextPath);
    ctx.setName(contextName);
    ctx.setPath(contextPath);
    ctx.setDocBase(dir);
    ctx.addLifecycleListener(new FixContextListener());
    if (host == null) {
        getHost().addChild(ctx);
    } else {
        host.addChild(ctx);
    }
    return ctx;
}

19 View Complete Implementation : TestTomcat.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetCustomContextPerAddWebappWithNullHost() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced(ReplicatedContext.clreplaced.getName());
    }
    File appFile = new File("test/deployment/context.war");
    Context context = tomcat.addWebapp(null, "/test", appFile.getAbsolutePath());
    replacedert.replacedertEquals(ReplicatedContext.clreplaced.getName(), context.getClreplaced().getName());
}

19 View Complete Implementation : MapperListener.java
Copyright MIT License
Author : chenmudu
// ------------------------------------------------------- Lifecycle Methods
@Override
public void startInternal() throws LifecycleException {
    setState(LifecycleState.STARTING);
    /**
     * StandardEngine
     */
    Engine engine = service.getContainer();
    if (engine == null) {
        return;
    }
    /**
     * 为映射注入对应Host容器。
     */
    findDefaultHost();
    /**
     * 增加对应的监听。
     */
    addListeners(engine);
    Container[] conHosts = engine.findChildren();
    for (Container conHost : conHosts) {
        Host host = (Host) conHost;
        if (!LifecycleState.NEW.equals(host.getState())) {
            // Registering the host will register the context and wrappers
            /**
             * 注册Host的时候将会注册Context和多个Wrapper。
             * {@link MapperListener#registerHost(org.apache.catalina.Host)}
             */
            registerHost(host);
        }
    }
}

19 View Complete Implementation : MBeanFactory.java
Copyright Apache License 2.0
Author : apache
/**
 * 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);
            }
    }
}

19 View Complete Implementation : MBeanFactory.java
Copyright Apache License 2.0
Author : apache
/**
 * 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);
    @SuppressWarnings("deprecation")
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(hostName);
    // Remove this component from its parent component
    if (host != null) {
        engine.removeChild(host);
    }
}

19 View Complete Implementation : TestTomcat.java
Copyright MIT License
Author : chenmudu
@Test
public void testGetBrokenContextPerAddWepapp() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced("InvalidContextClreplacedName");
    }
    try {
        File appFile = new File("test/deployment/context.war");
        tomcat.addWebapp(null, "/test", appFile.getAbsolutePath());
        replacedert.fail();
    } catch (IllegalArgumentException e) {
    // OK
    }
}

19 View Complete Implementation : ThreadLocalLeakPreventionListener.java
Copyright MIT License
Author : chenmudu
private void registerListenersForHost(Host host) {
    for (Container contextContainer : host.findChildren()) {
        Context context = (Context) contextContainer;
        registerContextListener(context);
    }
}

19 View Complete Implementation : TestTomcat.java
Copyright MIT License
Author : chenmudu
@Test
public void testGetCustomContextPerAddContextWithHost() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced(ReplicatedContext.clreplaced.getName());
    }
    // No file system docBase required
    Context ctx = tomcat.addContext(host, "", null);
    replacedert.replacedertEquals(ReplicatedContext.clreplaced.getName(), ctx.getClreplaced().getName());
}

19 View Complete Implementation : ThreadLocalLeakPreventionListener.java
Copyright Apache License 2.0
Author : apache
private void registerListenersForHost(Host host) {
    for (Container contextContainer : host.findChildren()) {
        Context context = (Context) contextContainer;
        registerContextListener(context);
    }
}

19 View Complete Implementation : TestTomcat.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetCustomContextPerAddContextWithHost() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced(ReplicatedContext.clreplaced.getName());
    }
    // No file system docBase required
    Context ctx = tomcat.addContext(host, "", null);
    replacedert.replacedertEquals(ReplicatedContext.clreplaced.getName(), ctx.getClreplaced().getName());
}

19 View Complete Implementation : MappingData.java
Copyright MIT License
Author : chenmudu
/**
 * Mapping data.
 *
 * @author Remy Maucherat
 */
public clreplaced MappingData {

    public Host host = null;

    public Context context = null;

    public int contextSlashCount = 0;

    public Context[] contexts = null;

    public Wrapper wrapper = null;

    public boolean jspWildCard = false;

    public final MessageBytes contextPath = MessageBytes.newInstance();

    public final MessageBytes requestPath = MessageBytes.newInstance();

    public final MessageBytes wrapperPath = MessageBytes.newInstance();

    public final MessageBytes pathInfo = MessageBytes.newInstance();

    public final MessageBytes redirectPath = MessageBytes.newInstance();

    // Fields used by ApplicationMapping to implement javax.servlet.http.HttpServletMapping
    public MappingMatch matchType = null;

    public void recycle() {
        host = null;
        context = null;
        contextSlashCount = 0;
        contexts = null;
        wrapper = null;
        jspWildCard = false;
        contextPath.recycle();
        requestPath.recycle();
        wrapperPath.recycle();
        pathInfo.recycle();
        redirectPath.recycle();
        matchType = null;
    }
}

19 View Complete Implementation : MBeanFactory.java
Copyright MIT License
Author : chenmudu
/**
 * 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);
    }
}

19 View Complete Implementation : MappingData.java
Copyright Apache License 2.0
Author : apache
/**
 * Mapping data.
 *
 * @author Remy Maucherat
 */
public clreplaced MappingData {

    public Host host = null;

    public Context context = null;

    public int contextSlashCount = 0;

    public Context[] contexts = null;

    public Wrapper wrapper = null;

    public boolean jspWildCard = false;

    public final MessageBytes contextPath = MessageBytes.newInstance();

    public final MessageBytes requestPath = MessageBytes.newInstance();

    public final MessageBytes wrapperPath = MessageBytes.newInstance();

    public final MessageBytes pathInfo = MessageBytes.newInstance();

    public final MessageBytes redirectPath = MessageBytes.newInstance();

    public void recycle() {
        host = null;
        context = null;
        contextSlashCount = 0;
        contexts = null;
        wrapper = null;
        jspWildCard = false;
        contextPath.recycle();
        requestPath.recycle();
        wrapperPath.recycle();
        pathInfo.recycle();
        redirectPath.recycle();
    }
}

19 View Complete Implementation : Tomcat.java
Copyright Apache License 2.0
Author : apache
/**
 * @see #addContext(String, String)
 */
public Context addContext(Host host, String contextPath, String contextName, String dir) {
    silence(host, contextName);
    Context ctx = createContext(host, contextPath);
    ctx.setName(contextName);
    ctx.setPath(contextPath);
    ctx.setDocBase(dir);
    ctx.addLifecycleListener(new FixContextListener());
    if (host == null) {
        getHost().addChild(ctx);
    } else {
        host.addChild(ctx);
    }
    return ctx;
}

19 View Complete Implementation : TestTomcat.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetBrokenContextPerAddWepapp() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced("InvalidContextClreplacedName");
    }
    try {
        File appFile = new File("test/deployment/context.war");
        tomcat.addWebapp(null, "/test", appFile.getAbsolutePath());
        replacedert.fail();
    } catch (IllegalArgumentException e) {
    // OK
    }
}

19 View Complete Implementation : Tomcat.java
Copyright MIT License
Author : chenmudu
/*
     * Uses essentially the same logic as {@link ContainerBase#logName()}.
     */
private String getLoggerName(Host host, String contextName) {
    if (host == null) {
        host = getHost();
    }
    StringBuilder loggerName = new StringBuilder();
    loggerName.append(ContainerBase.clreplaced.getName());
    loggerName.append(".[");
    // Engine name
    loggerName.append(host.getParent().getName());
    loggerName.append("].[");
    // Host name
    loggerName.append(host.getName());
    loggerName.append("].[");
    // Context name
    if (contextName == null || contextName.equals("")) {
        loggerName.append("/");
    } else if (contextName.startsWith("##")) {
        loggerName.append("/");
        loggerName.append(contextName);
    }
    loggerName.append(']');
    return loggerName.toString();
}

19 View Complete Implementation : MBeanFactory.java
Copyright Apache License 2.0
Author : apache
/**
 * 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);
    }
}

19 View Complete Implementation : Tomcat.java
Copyright Apache License 2.0
Author : apache
private void silence(Host host, String contextPath) {
    String loggerName = getLoggerName(host, contextPath);
    Logger logger = Logger.getLogger(loggerName);
    pinnedLoggers.put(loggerName, logger);
    if (silent) {
        logger.setLevel(Level.WARNING);
    } else {
        logger.setLevel(Level.INFO);
    }
}

19 View Complete Implementation : TestTomcat.java
Copyright Apache License 2.0
Author : apache
@Test
public void testGetCustomContextPerAddWebappWithHost() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced(ReplicatedContext.clreplaced.getName());
    }
    File appFile = new File("test/deployment/context.war");
    Context context = tomcat.addWebapp(host, "/test", appFile.getAbsolutePath());
    replacedert.replacedertEquals(ReplicatedContext.clreplaced.getName(), context.getClreplaced().getName());
}

19 View Complete Implementation : Tomcat.java
Copyright MIT License
Author : chenmudu
/**
 * @param host The host in which the context will be deployed
 * @param contextPath The context mapping to use, "" for root context.
 * @param dir Base directory for the context, for static files.
 *  Must exist, relative to the server home
 * @return the deployed context
 * @see #addContext(String, String)
 */
public Context addContext(Host host, String contextPath, String dir) {
    return addContext(host, contextPath, contextPath, dir);
}

19 View Complete Implementation : MapperListener.java
Copyright Apache License 2.0
Author : apache
/**
 * Unregister host.
 */
private void unregisterHost(Host host) {
    String hostname = host.getName();
    mapper.removeHost(hostname);
    // Default host may have changed
    findDefaultHost();
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("mapperListener.unregisterHost", hostname, domain, service));
    }
}

19 View Complete Implementation : MapperListener.java
Copyright Apache License 2.0
Author : apache
// ------------------------------------------------------- Lifecycle Methods
@Override
public void startInternal() throws LifecycleException {
    setState(LifecycleState.STARTING);
    @SuppressWarnings("deprecation")
    Engine engine = (Engine) service.getContainer();
    if (engine == null) {
        return;
    }
    findDefaultHost();
    addListeners(engine);
    Container[] conHosts = engine.findChildren();
    for (Container conHost : conHosts) {
        Host host = (Host) conHost;
        if (!LifecycleState.NEW.equals(host.getState())) {
            // Registering the host will register the context and wrappers
            registerHost(host);
        }
    }
}

19 View Complete Implementation : TestTomcat.java
Copyright MIT License
Author : chenmudu
@Test
public void testGetBrokenContextPerAddContext() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced("InvalidContextClreplacedName");
    }
    // No file system docBase required
    try {
        tomcat.addContext(null, "", null);
        replacedert.fail();
    } catch (IllegalArgumentException e) {
    // OK
    }
}

19 View Complete Implementation : MapperListener.java
Copyright MIT License
Author : chenmudu
/**
 * Unregister host.
 */
private void unregisterHost(Host host) {
    String hostname = host.getName();
    mapper.removeHost(hostname);
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("mapperListener.unregisterHost", hostname, domain, service));
    }
}

19 View Complete Implementation : TestTomcat.java
Copyright MIT License
Author : chenmudu
@Test
public void testGetCustomContextPerAddWebappWithHost() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClreplaced(ReplicatedContext.clreplaced.getName());
    }
    File appFile = new File("test/deployment/context.war");
    Context context = tomcat.addWebapp(host, "/test", appFile.getAbsolutePath());
    replacedert.replacedertEquals(ReplicatedContext.clreplaced.getName(), context.getClreplaced().getName());
}

19 View Complete Implementation : CrawlerSessionManagerValve.java
Copyright Apache License 2.0
Author : apache
private String getClientIdentifier(Host host, Context context, String clientIp) {
    StringBuilder result = new StringBuilder(clientIp);
    if (isHostAware) {
        result.append('-').append(host.getName());
    }
    if (isContextAware) {
        result.append(context.getName());
    }
    return result.toString();
}

18 View Complete Implementation : Tomcat.java
Copyright MIT License
Author : chenmudu
/**
 * @param host The host in which the context will be deployed
 * @param contextPath The context mapping to use, "" for root context.
 * @param docBase Base directory for the context, for static files.
 *  Must exist, relative to the server home
 * @return the deployed context
 * @see #addWebapp(String, String)
 */
public Context addWebapp(Host host, String contextPath, String docBase) {
    LifecycleListener listener = null;
    try {
        Clreplaced<?> clazz = Clreplaced.forName(getHost().getConfigClreplaced());
        listener = (LifecycleListener) clazz.getConstructor().newInstance();
    } catch (ReflectiveOperationException e) {
        // Wrap in IAE since we can't easily change the method signature to
        // to throw the specific checked exceptions
        throw new IllegalArgumentException(e);
    }
    return addWebapp(host, contextPath, docBase, listener);
}

18 View Complete Implementation : TestMapper.java
Copyright MIT License
Author : chenmudu
@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    mapper = new Mapper();
    mapper.addHost("sjbjdvwsbvhrb", new String[0], createHost("blah1"));
    mapper.addHost("sjbjdvwsbvhr/", new String[0], createHost("blah1"));
    mapper.addHost("wekhfewuifweuibf", new String[0], createHost("blah2"));
    mapper.addHost("ylwrehirkuewh", new String[0], createHost("blah3"));
    mapper.addHost("iohgeoihro", new String[0], createHost("blah4"));
    mapper.addHost("fwehoihoihwfeo", new String[0], createHost("blah5"));
    mapper.addHost("owefojiwefoi", new String[0], createHost("blah6"));
    mapper.addHost("iowejoiejfoiew", new String[0], createHost("blah7"));
    mapper.addHost("ohewoihfewoih", new String[0], createHost("blah8"));
    mapper.addHost("fewohfoweoih", new String[0], createHost("blah9"));
    mapper.addHost("ttthtiuhwoih", new String[0], createHost("blah10"));
    mapper.addHost("lkwefjwojweffewoih", new String[0], createHost("blah11"));
    mapper.addHost("zzzuyopjvewpovewjhfewoih", new String[0], createHost("blah12"));
    mapper.addHost("xxxxgqwiwoih", new String[0], createHost("blah13"));
    mapper.addHost("qwigqwiwoih", new String[0], createHost("blah14"));
    mapper.addHost("qwerty.net", new String[0], createHost("blah15"));
    mapper.addHost("*.net", new String[0], createHost("blah16"));
    mapper.addHost("zzz.com", new String[0], createHost("blah17"));
    mapper.addHostAlias("iowejoiejfoiew", "iowejoiejfoiew_alias");
    mapper.setDefaultHostName("ylwrehirkuewh");
    String[] welcomes = new String[2];
    welcomes[0] = "boo/baba";
    welcomes[1] = "bobou";
    Host host = createHost("blah7");
    mapper.addContextVersion("iowejoiejfoiew", host, "", "0", createContext("context0"), new String[0], null, null);
    mapper.addContextVersion("iowejoiejfoiew", host, "/foo", "0", createContext("context1"), new String[0], null, null);
    mapper.addContextVersion("iowejoiejfoiew", host, "/foo/bar", "0", createContext("context2"), welcomes, null, null);
    mapper.addWrappers("iowejoiejfoiew", "/foo", "0", Arrays.asList(new WrapperMappingInfo[] { new WrapperMappingInfo("/", createWrapper("context1-defaultWrapper"), false, false) }));
    mapper.addWrappers("iowejoiejfoiew", "/foo/bar", "0", Arrays.asList(new WrapperMappingInfo[] { new WrapperMappingInfo("/fo/*", createWrapper("wrapper0"), false, false), new WrapperMappingInfo("/", createWrapper("wrapper1"), false, false), new WrapperMappingInfo("/blh", createWrapper("wrapper2"), false, false), new WrapperMappingInfo("*.jsp", createWrapper("wrapper3"), false, false), new WrapperMappingInfo("/blah/bou/*", createWrapper("wrapper4"), false, false), new WrapperMappingInfo("/blah/bobou/*", createWrapper("wrapper5"), false, false), new WrapperMappingInfo("*.htm", createWrapper("wrapper6"), false, false) }));
    mapper.addContextVersion("iowejoiejfoiew", host, "/foo/bar/bla", "0", createContext("context3"), new String[0], null, Arrays.asList(new WrapperMappingInfo[] { new WrapperMappingInfo("/bobou/*", createWrapper("wrapper7"), false, false) }));
    host = createHost("blah16");
    mapper.addContextVersion("*.net", host, "", "0", createContext("context4"), new String[0], null, null);
    mapper.addWrappers("*.net", "", "0", Arrays.asList(new WrapperMappingInfo[] { new WrapperMappingInfo("/", createWrapper("context4-defaultWrapper"), false, false) }));
}