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

The following examples show how to use org.apache.catalina.Container#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: TomcatWsRegistry.java    From tomee with Apache License 2.0 6 votes vote down vote up
private void deployInFakeWebapp(final String path, final ClassLoader classLoader, final String authMethod, final String transportGuarantee,
                                final String realmName, final Container host, final HttpListener httpListener, final List<String> addresses, final String name) {
    Container context = host.findChild(name);
    if (context == null) {
        context = createNewContext(classLoader, authMethod, transportGuarantee, realmName, name);
        host.addChild(context);
    }

    final Integer ref = fakeContextReferences.get(name);
    if (ref == null) {
        fakeContextReferences.put(name, 0);
    } else {
        fakeContextReferences.put(name, ref + 1);
    }

    String mapping = path;
    if (!mapping.startsWith("/")) { // TODO: check it can happen or move it away
        mapping = '/' + mapping;
    }
    addServlet(host, (Context) context, mapping, httpListener, path, addresses, true, null);
}
 
Example 2
Source File: TomcatWebAppBuilder.java    From tomee with Apache License 2.0 6 votes vote down vote up
private static boolean undeploy(final StandardContext standardContext, final Container host) {
    final Container child = host.findChild(standardContext.getName());

    // skip undeployment if redeploying (StandardContext.redeploy())
    if (child instanceof org.apache.catalina.Context && org.apache.catalina.Context.class.cast(child).getPaused()) {
        return true;
    }

    // skip undeployment if restarting
    final TomEEWebappClassLoader tomEEWebappClassLoader = lazyClassLoader(
        org.apache.catalina.Context.class.isInstance(child) ? org.apache.catalina.Context.class.cast(child) : null);
    if (tomEEWebappClassLoader != null && tomEEWebappClassLoader.isRestarting()) {
        return true;
    }

    if (child != null) {
        host.removeChild(standardContext);
        return true;
    }
    return false;
}
 
Example 3
Source File: ContainerMBean.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Remove an existing child Container from association with this parent
 * Container.
 *
 * @param name Name of the existing child Container to be removed
 * @throws MBeanException if the child cannot be removed
 */
public void removeChild(String name) throws MBeanException{
    if (name != null) {
        Container container = doGetManagedResource();
        Container contained = container.findChild(name);
        container.removeChild(contained);
    }
}
 
Example 4
Source File: SingleSignOn.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private void expire(SingleSignOnSessionKey key) {
    if (engine == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.engineNull", key));
        return;
    }
    Container host = engine.findChild(key.getHostName());
    if (host == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.hostNotFound", key));
        return;
    }
    Context context = (Context) host.findChild(key.getContextName());
    if (context == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.contextNotFound", key));
        return;
    }
    Manager manager = context.getManager();
    if (manager == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerNotFound", key));
        return;
    }
    Session session = null;
    try {
        session = manager.findSession(key.getSessionId());
    } catch (IOException e) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerError", key), e);
        return;
    }
    if (session == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.sessionNotFound", key));
        return;
    }
    session.expire();
}
 
Example 5
Source File: SingleSignOn.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private void expire(SingleSignOnSessionKey key) {
    if (engine == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.engineNull", key));
        return;
    }
    Container host = engine.findChild(key.getHostName());
    if (host == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.hostNotFound", key));
        return;
    }
    Context context = (Context) host.findChild(key.getContextName());
    if (context == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.contextNotFound", key));
        return;
    }
    Manager manager = context.getManager();
    if (manager == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerNotFound", key));
        return;
    }
    Session session = null;
    try {
        session = manager.findSession(key.getSessionId());
    } catch (IOException e) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerError", key), e);
        return;
    }
    if (session == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.sessionNotFound", key));
        return;
    }
    session.expire();
}
 
Example 6
Source File: SingleSignOn.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private void expire(SingleSignOnSessionKey key) {
    if (engine == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.engineNull", key));
        return;
    }
    Container host = engine.findChild(key.getHostName());
    if (host == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.hostNotFound", key));
        return;
    }
    Context context = (Context) host.findChild(key.getContextName());
    if (context == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.contextNotFound", key));
        return;
    }
    Manager manager = context.getManager();
    if (manager == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerNotFound", key));
        return;
    }
    Session session = null;
    try {
        session = manager.findSession(key.getSessionId());
    } catch (IOException e) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.managerError", key), e);
        return;
    }
    if (session == null) {
        containerLog.warn(sm.getString("singleSignOn.sessionExpire.sessionNotFound", key));
        return;
    }
    session.expire();
}
 
Example 7
Source File: TomcatWsRegistry.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void clearWsContainer(final String contextRoot, String virtualHost, final ServletInfo servletInfo, final String moduleId) {
    if (virtualHost == null) {
        virtualHost = engine.getDefaultHost();
    }

    final Container host = engine.findChild(virtualHost);
    if (host == null) {
        throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'.  Do you have a matchiing Host entry in the server.xml?");
    }

    final Context context = (Context) host.findChild("/" + contextRoot);
    if (context == null) {
        throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName());
    }

    final Wrapper wrapper = (Wrapper) context.findChild(servletInfo.servletName);
    if (wrapper == null) {
        throw new IllegalArgumentException("Could not find servlet " + servletInfo.servletName + " in web application context " + context.getName());
    }

    // clear the webservice ref in the servlet context
    final String webServicecontainerId = wrapper.findInitParameter(WsServlet.WEBSERVICE_CONTAINER);
    if (webServicecontainerId != null) {
        context.getServletContext().removeAttribute(webServicecontainerId);
        wrapper.removeInitParameter(WsServlet.WEBSERVICE_CONTAINER);
    }
}
 
Example 8
Source File: JvmRouteSessionIDBinderListener.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Callback from the cluster, when a message is received, The cluster will
 * broadcast it invoking the messageReceived on the receiver.
 * 
 * @param msg
 *            ClusterMessage - the message received from the cluster
 */
@Override
public void messageReceived(ClusterMessage msg) {
    if (msg instanceof SessionIDMessage) {
        SessionIDMessage sessionmsg = (SessionIDMessage) msg;
        if (log.isDebugEnabled())
            log.debug(sm.getString(
                    "jvmRoute.receiveMessage.sessionIDChanged", sessionmsg
                            .getOrignalSessionID(), sessionmsg
                            .getBackupSessionID(), sessionmsg
                            .getContextName()));
        Container container = getCluster().getContainer();
        Container host = null ;
        if(container instanceof Engine) {
            host = container.findChild(sessionmsg.getHost());
        } else {
            host = container ;
        }
        if (host != null) {
            Context context = (Context) host.findChild(sessionmsg
                    .getContextName());
            if (context != null) {
                try {
                    Session session = context.getManager().findSession(
                            sessionmsg.getOrignalSessionID());
                    if (session != null) {
                        session.setId(sessionmsg.getBackupSessionID());
                    } else if (log.isInfoEnabled())
                        log.info(sm.getString("jvmRoute.lostSession",
                                sessionmsg.getOrignalSessionID(),
                                sessionmsg.getContextName()));
                } catch (IOException e) {
                    log.error(e);
                }

            } else if (log.isErrorEnabled())
                log.error(sm.getString("jvmRoute.contextNotFound",
                        sessionmsg.getContextName(), ((StandardEngine) host
                                .getParent()).getJvmRoute()));
        } else if (log.isErrorEnabled())
            log.error(sm.getString("jvmRoute.hostNotFound", sessionmsg.getContextName()));
    }
    return;
}
 
Example 9
Source File: JvmRouteSessionIDBinderListener.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Callback from the cluster, when a message is received, The cluster will
 * broadcast it invoking the messageReceived on the receiver.
 * 
 * @param msg
 *            ClusterMessage - the message received from the cluster
 */
@Override
public void messageReceived(ClusterMessage msg) {
    if (msg instanceof SessionIDMessage) {
        SessionIDMessage sessionmsg = (SessionIDMessage) msg;
        if (log.isDebugEnabled())
            log.debug(sm.getString(
                    "jvmRoute.receiveMessage.sessionIDChanged", sessionmsg
                            .getOrignalSessionID(), sessionmsg
                            .getBackupSessionID(), sessionmsg
                            .getContextName()));
        Container container = getCluster().getContainer();
        Container host = null ;
        if(container instanceof Engine) {
            host = container.findChild(sessionmsg.getHost());
        } else {
            host = container ;
        }
        if (host != null) {
            Context context = (Context) host.findChild(sessionmsg
                    .getContextName());
            if (context != null) {
                try {
                    Session session = context.getManager().findSession(
                            sessionmsg.getOrignalSessionID());
                    if (session != null) {
                        session.setId(sessionmsg.getBackupSessionID());
                    } else if (log.isInfoEnabled())
                        log.info(sm.getString("jvmRoute.lostSession",
                                sessionmsg.getOrignalSessionID(),
                                sessionmsg.getContextName()));
                } catch (IOException e) {
                    log.error(e);
                }

            } else if (log.isErrorEnabled())
                log.error(sm.getString("jvmRoute.contextNotFound",
                        sessionmsg.getContextName(), ((StandardEngine) host
                                .getParent()).getJvmRoute()));
        } else if (log.isErrorEnabled())
            log.error(sm.getString("jvmRoute.hostNotFound", sessionmsg.getContextName()));
    }
    return;
}
 
Example 10
Source File: TomcatWsRegistry.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public List<String> setWsContainer(final HttpListener httpListener,
                                   final ClassLoader classLoader,
                                   String contextRoot, String virtualHost, final ServletInfo servletInfo,
                                   final String realmName, final String transportGuarantee, final String authMethod,
                                   final String moduleId) throws Exception {

    if (virtualHost == null) {
        virtualHost = engine.getDefaultHost();
    }

    final Container host = engine.findChild(virtualHost);
    if (host == null) {
        throw new IllegalArgumentException("Invalid virtual host '" + virtualHost + "'.  Do you have a matchiing Host entry in the server.xml?");
    }

    if ("ROOT".equals(contextRoot)) { // doesn't happen in tomee itself but with all our tooling around
        contextRoot = "";
    }
    if (!contextRoot.startsWith("/") && !contextRoot.isEmpty()) {
        contextRoot = "/" + contextRoot;
    }

    final Context context = (Context) host.findChild(contextRoot);
    if (context == null) {
        throw new IllegalArgumentException("Could not find web application context " + contextRoot + " in host " + host.getName());
    }

    final Wrapper wrapper = (Wrapper) context.findChild(servletInfo.servletName);
    if (wrapper == null) {
        throw new IllegalArgumentException("Could not find servlet " + servletInfo.servletName + " in web application context " + context.getName());
    }

    // for Pojo web services, we need to change the servlet class which is the service implementation
    // by the WsServler class
    wrapper.setServletClass(WsServlet.class.getName());
    if (wrapper.getServlet() != null) {
        wrapper.unload(); // deallocate previous one
        wrapper.load(); // reload this one withuot unloading it to keep the instance - unload is called during stop()
        // boolean controlling this method call can't be set to false through API so let do it ourself
        wrapper.getServlet().init(StandardWrapper.class.cast(wrapper)); // or Reflections.set(wrapper, "instanceInitialized", false);
    }

    setWsContainer(context, wrapper, httpListener);

    // add service locations
    final List<String> addresses = new ArrayList<>();
    for (final Connector connector : connectors) {
        for (final String mapping : wrapper.findMappings()) {
            final URI address = new URI(connector.getScheme(), null, host.getName(), connector.getPort(), (contextRoot.startsWith("/") ? "" : "/") + contextRoot + mapping, null, null);
            addresses.add(address.toString());
        }
    }
    return addresses;
}