Java Code Examples for org.apache.catalina.Context#getParent()

The following examples show how to use org.apache.catalina.Context#getParent() . 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: SimpleTcpCluster.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public String getManagerName(String name, Manager manager) {
    String clusterName = name ;
    if (clusterName == null) clusterName = manager.getContext().getName();
    if (getContainer() instanceof Engine) {
        Context context = manager.getContext();
        Container host = context.getParent();
        if (host instanceof Host && clusterName != null &&
                !(clusterName.startsWith(host.getName() +"#"))) {
            clusterName = host.getName() +"#" + clusterName ;
        }
    }
    return clusterName;
}
 
Example 2
Source File: MapperListener.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Register context.
 */
private void registerContext(Context context) {

    String contextPath = context.getPath();
    if ("/".equals(contextPath)) {
        contextPath = "";
    }
    Host host = (Host)context.getParent();

    WebResourceRoot resources = context.getResources();
    String[] welcomeFiles = context.findWelcomeFiles();
    List<WrapperMappingInfo> wrappers = new ArrayList<>();

    for (Container container : context.findChildren()) {
        prepareWrapperMappingInfo(context, (Wrapper) container, wrappers);

        if(log.isDebugEnabled()) {
            log.debug(sm.getString("mapperListener.registerWrapper",
                    container.getName(), contextPath, service));
        }
    }

    mapper.addContextVersion(host.getName(), host, contextPath,
            context.getWebappVersion(), context, welcomeFiles, resources,
            wrappers);

    if(log.isDebugEnabled()) {
        log.debug(sm.getString("mapperListener.registerContext",
                contextPath, service));
    }
}
 
Example 3
Source File: MapperListener.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Register context.
 */
private void registerContext(Context context) {

    String contextPath = context.getPath();
    if ("/".equals(contextPath)) {
        contextPath = "";
    }
    Container host = context.getParent();

    javax.naming.Context resources = context.getResources();
    String[] welcomeFiles = context.findWelcomeFiles();
    List<WrapperMappingInfo> wrappers = new ArrayList<WrapperMappingInfo>();

    for (Container container : context.findChildren()) {
        prepareWrapperMappingInfo(context, (Wrapper) container, wrappers);

        if(log.isDebugEnabled()) {
            log.debug(sm.getString("mapperListener.registerWrapper",
                    container.getName(), contextPath, connector));
        }
    }

    mapper.addContextVersion(host.getName(), host, contextPath,
            context.getWebappVersion(), context, welcomeFiles, resources,
            wrappers, context.getMapperContextRootRedirectEnabled(),
            context.getMapperDirectoryRedirectEnabled());

    if(log.isDebugEnabled()) {
        log.debug(sm.getString("mapperListener.registerContext",
                contextPath, connector));
    }
}
 
Example 4
Source File: SimpleTcpCluster.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * @param name
 * @param manager
 * @return TODO
 */
@Override
public String getManagerName(String name, Manager manager) {
    String clusterName = name ;
    if (clusterName == null) clusterName = manager.getContainer().getName();
    if (getContainer() instanceof Engine) {
        Context context = (Context) manager.getContainer() ;
        Container host = context.getParent();
        if (host instanceof Host && clusterName != null && 
                !(clusterName.startsWith(host.getName() +"#"))) {
            clusterName = host.getName() +"#" + clusterName ;
        }
    }
    return clusterName;
}
 
Example 5
Source File: MapperListener.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Register context.
 */
private void registerContext(Context context) {

    String contextPath = context.getPath();
    if ("/".equals(contextPath)) {
        contextPath = "";
    }
    Container host = context.getParent();

    javax.naming.Context resources = context.getResources();
    String[] welcomeFiles = context.findWelcomeFiles();
    List<WrapperMappingInfo> wrappers = new ArrayList<WrapperMappingInfo>();

    for (Container container : context.findChildren()) {
        prepareWrapperMappingInfo(context, (Wrapper) container, wrappers);

        if(log.isDebugEnabled()) {
            log.debug(sm.getString("mapperListener.registerWrapper",
                    container.getName(), contextPath, connector));
        }
    }

    mapper.addContextVersion(host.getName(), host, contextPath,
            context.getWebappVersion(), context, welcomeFiles, resources,
            wrappers, context.getMapperContextRootRedirectEnabled(),
            context.getMapperDirectoryRedirectEnabled());

    if(log.isDebugEnabled()) {
        log.debug(sm.getString("mapperListener.registerContext",
                contextPath, connector));
    }
}
 
Example 6
Source File: TomcatWsRegistry.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void removeWsContainer(String path, final String moduleId) {
    if (path == null) {
        return;
    }

    // assure context root with a leading slash
    if (!path.startsWith("/")) {
        path = "/" + path;
    }

    if (TomcatHelper.isStopping()) {
        return;
    }

    Context context = webserviceContexts.remove(new Key(path, moduleId));
    if (context == null) { // fake
        context = webserviceContexts.remove(new Key(path, null));
    }

    Integer refs = 1; // > 0 to avoid to destroy the context if not mandatory
    if (context != null) {
        final String name = context.getName();
        refs = fakeContextReferences.remove(name);
        if (refs != null && refs > 0) {
            fakeContextReferences.put(name, refs - 1);
        }
    }

    if ((WEBSERVICE_OLDCONTEXT_ACTIVE || (refs != null && refs == 0)) && context != null) {
        try {
            context.stop();
            context.destroy();
        } catch (final Exception e) {
            throw new TomEERuntimeException(e);
        }
        final Host host = (Host) context.getParent();
        host.removeChild(context);
    } // else let tomcat manages its context
}
 
Example 7
Source File: StandardContextSF.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Store a Context as Separate file as configFile value from context exists.
 * filename can be relative to catalina.base.
 *
 * @see org.apache.catalina.storeconfig.IStoreFactory#store(java.io.PrintWriter,
 *      int, java.lang.Object)
 */
@Override
public void store(PrintWriter aWriter, int indent, Object aContext)
        throws Exception {

    if (aContext instanceof StandardContext) {
        StoreDescription desc = getRegistry().findDescription(
                aContext.getClass());
        if (desc.isStoreSeparate()) {
            URL configFile = ((StandardContext) aContext)
                    .getConfigFile();
            if (configFile != null) {
                if (desc.isExternalAllowed()) {
                    if (desc.isBackup())
                        storeWithBackup((StandardContext) aContext);
                    else
                        storeContextSeparate(aWriter, indent,
                                (StandardContext) aContext);
                    return;
                }
            } else if (desc.isExternalOnly()) {
                // Set a configFile so that the configuration is actually saved
                Context context = ((StandardContext) aContext);
                Host host = (Host) context.getParent();
                File configBase = host.getConfigBaseFile();
                ContextName cn = new ContextName(context.getName(), false);
                String baseName = cn.getBaseName();
                File xml = new File(configBase, baseName + ".xml");
                context.setConfigFile(xml.toURI().toURL());
                if (desc.isBackup())
                    storeWithBackup((StandardContext) aContext);
                else
                    storeContextSeparate(aWriter, indent,
                            (StandardContext) aContext);
                return;
            }
        }
    }
    super.store(aWriter, indent, aContext);

}
 
Example 8
Source File: InfinispanSessionCacheIdMapperUpdater.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public static SessionIdMapperUpdater addTokenStoreUpdaters(Context context, SessionIdMapper mapper, SessionIdMapperUpdater previousIdMapperUpdater) {
    ServletContext servletContext = context.getServletContext();
    String containerName = servletContext == null ? null : servletContext.getInitParameter(AdapterConstants.REPLICATION_CONFIG_CONTAINER_PARAM_NAME);
    String cacheName = servletContext == null ? null : servletContext.getInitParameter(AdapterConstants.REPLICATION_CONFIG_SSO_CACHE_PARAM_NAME);

    // the following is based on https://github.com/jbossas/jboss-as/blob/7.2.0.Final/clustering/web-infinispan/src/main/java/org/jboss/as/clustering/web/infinispan/DistributedCacheManagerFactory.java#L116-L122
    String host = context.getParent() == null ? "" : context.getParent().getName();
    String contextPath = context.getPath();
    if ("/".equals(contextPath)) {
        contextPath = "/ROOT";
    }
    String deploymentSessionCacheName = host + contextPath;

    if (containerName == null || cacheName == null || deploymentSessionCacheName == null) {
        LOG.warnv("Cannot determine parameters of SSO cache for deployment {0}.", host + contextPath);

        return previousIdMapperUpdater;
    }

    String cacheContainerLookup = DEFAULT_CACHE_CONTAINER_JNDI_NAME + "/" + containerName;

    try {
        EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) new InitialContext().lookup(cacheContainerLookup);

        Configuration ssoCacheConfiguration = cacheManager.getCacheConfiguration(cacheName);
        if (ssoCacheConfiguration == null) {
            Configuration cacheConfiguration = cacheManager.getCacheConfiguration(deploymentSessionCacheName);
            if (cacheConfiguration == null) {
                LOG.debugv("Using default configuration for SSO cache {0}.{1}.", containerName, cacheName);
                ssoCacheConfiguration = cacheManager.getDefaultCacheConfiguration();
            } else {
                LOG.debugv("Using distributed HTTP session cache configuration for SSO cache {0}.{1}, configuration taken from cache {2}",
                  containerName, cacheName, deploymentSessionCacheName);
                ssoCacheConfiguration = cacheConfiguration;
                cacheManager.defineConfiguration(cacheName, ssoCacheConfiguration);
            }
        } else {
            LOG.debugv("Using custom configuration of SSO cache {0}.{1}.", containerName, cacheName);
        }

        CacheMode ssoCacheMode = ssoCacheConfiguration.clustering().cacheMode();
        if (ssoCacheMode != CacheMode.REPL_ASYNC && ssoCacheMode != CacheMode.REPL_SYNC) {
            LOG.warnv("SSO cache mode is {0}, it is recommended to use replicated mode instead.", ssoCacheConfiguration.clustering().cacheModeString());
        }

        Cache<String, String[]> ssoCache = cacheManager.getCache(cacheName, true);
        final SsoSessionCacheListener listener = new SsoSessionCacheListener(ssoCache, mapper);
        ssoCache.addListener(listener);

        // Not possible to add listener for cross-DC support because of too old Infinispan in AS 7
        warnIfRemoteStoreIsUsed(ssoCache);

        LOG.debugv("Added distributed SSO session cache, lookup={0}, cache name={1}", cacheContainerLookup, cacheName);

        SsoCacheSessionIdMapperUpdater updater = new SsoCacheSessionIdMapperUpdater(ssoCache, previousIdMapperUpdater);

        return updater;
    } catch (NamingException ex) {
        LOG.warnv("Failed to obtain distributed session cache container, lookup={0}", cacheContainerLookup);
        return previousIdMapperUpdater;
    }
}