Search in sources :

Example 16 with ExoContainer

use of org.exoplatform.container.ExoContainer in project kernel by exoplatform.

the class AbstractHttpSessionListener method sessionDestroyed.

/**
 * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
 */
public final void sessionDestroyed(HttpSessionEvent event) {
    final ExoContainer oldContainer = ExoContainerContext.getCurrentContainerIfPresent();
    // Keep the old ClassLoader
    final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    ExoContainer container = null;
    boolean hasBeenSet = false;
    try {
        container = getContainer(event);
        if (container == null)
            return;
        if (!container.equals(oldContainer)) {
            if (container instanceof PortalContainer) {
                PortalContainer.setInstance((PortalContainer) container);
            }
            ExoContainerContext.setCurrentContainer(container);
            hasBeenSet = true;
        }
        if (requirePortalEnvironment()) {
            final String ctxName = ContainerUtil.getServletContextName(event.getSession().getServletContext());
            if (!PortalContainer.isPortalContainerNameDisabled(ctxName) && container instanceof PortalContainer) {
                if (PortalContainer.getInstanceIfPresent() == null) {
                    // The portal container has not been set
                    PortalContainer.setInstance((PortalContainer) container);
                    hasBeenSet = true;
                }
                // Set the full classloader of the portal container
                Thread.currentThread().setContextClassLoader(((PortalContainer) container).getPortalClassLoader());
            } else {
                if (PropertyManager.isDevelopping()) {
                    LOG.info("The portal environment could not be set for the webapp '" + ctxName + "' because this servlet context has not been defined as a " + "dependency of any portal container or it is a disabled portal" + " container, the sessionDestroyed event will be ignored");
                }
                return;
            }
        }
        onSessionDestroyed(container, event);
    } finally {
        if (hasBeenSet) {
            if (container instanceof PortalContainer) {
                // Remove the current Portal Container and the current ExoContainer
                PortalContainer.setInstance(null);
            }
            // Re-set the old container
            ExoContainerContext.setCurrentContainer(oldContainer);
        }
        if (requirePortalEnvironment()) {
            // Re-set the old classloader
            Thread.currentThread().setContextClassLoader(currentClassLoader);
        }
    }
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) PortalContainer(org.exoplatform.container.PortalContainer)

Example 17 with ExoContainer

use of org.exoplatform.container.ExoContainer in project kernel by exoplatform.

the class Deserializer method resolveVariables.

/**
 * Resolve the variables of type ${my.var} for the current context which is composed
 * of the system properties, the portal container settings and the given settings
 * @param input the input value
 * @param props a set of parameters to add for the variable resolution
 * @return the resolve value
 */
public static String resolveVariables(String input, Map<String, Object> props) {
    final int NORMAL = 0;
    final int SEEN_DOLLAR = 1;
    final int IN_BRACKET = 2;
    if (input == null)
        return input;
    char[] chars = input.toCharArray();
    StringBuilder buffer = new StringBuilder();
    boolean properties = false;
    int state = NORMAL;
    int start = 0;
    for (int i = 0; i < chars.length; ++i) {
        char c = chars[i];
        if (c == '$' && state != IN_BRACKET)
            state = SEEN_DOLLAR;
        else if (c == '{' && state == SEEN_DOLLAR) {
            buffer.append(input.substring(start, i - 1));
            state = IN_BRACKET;
            start = i - 1;
        } else if (state == SEEN_DOLLAR)
            state = NORMAL;
        else if (c == '}' && state == IN_BRACKET) {
            if (start + 2 == i) {
                buffer.append("${}");
            } else {
                String value = null;
                String key = input.substring(start + 2, i);
                String defaultValue = null;
                int index = key.indexOf(':');
                if (index > -1) {
                    defaultValue = key.substring(index + 1);
                    key = key.substring(0, index);
                }
                if (key.equals(Deserializer.EXO_CONTAINER_PROP_NAME)) {
                    // The requested key is the name of current container
                    ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent();
                    if (container instanceof PortalContainer) {
                        // The current container is a portal container
                        RootContainer rootContainer = (RootContainer) ExoContainerContext.getTopContainer();
                        value = rootContainer.isPortalContainerConfigAware() ? "_" + container.getContext().getName() : "";
                    }
                } else if (key.startsWith(Deserializer.PORTAL_CONTAINER_VARIABLE_PREFIX)) {
                    // We try to get a value tied to the current portal container.
                    ExoContainer container = ExoContainerContext.getCurrentContainerIfPresent();
                    if (container instanceof PortalContainer) {
                        // The current container is a portal container
                        Object oValue = ((PortalContainer) container).getSetting(key.substring(Deserializer.PORTAL_CONTAINER_VARIABLE_PREFIX.length()));
                        value = oValue == null ? null : oValue.toString();
                    }
                } else {
                    if (props != null) {
                        // Some parameters have been given thus we need to check inside first
                        Object oValue = props.get(key);
                        value = oValue == null ? null : oValue.toString();
                    }
                    if (value == null) {
                        // No value could be found so far, thus we try to get it from the
                        // system properties
                        value = PrivilegedSystemHelper.getProperty(key);
                    }
                }
                if (value == null && defaultValue != null) {
                    value = defaultValue;
                }
                if (value != null) {
                    properties = true;
                    buffer.append(value);
                }
            }
            start = i + 1;
            state = NORMAL;
        }
    }
    if (properties == false)
        return input;
    if (start != chars.length)
        buffer.append(input.substring(start, chars.length));
    return buffer.toString();
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) RootContainer(org.exoplatform.container.RootContainer) PortalContainer(org.exoplatform.container.PortalContainer)

Example 18 with ExoContainer

use of org.exoplatform.container.ExoContainer in project kernel by exoplatform.

the class TestKernelExtension method testInterceptors.

public void testInterceptors() {
    ExoContainer parent = new ExoContainer();
    testInterceptorsInternal(parent);
    // Make sure that it is consistent
    testInterceptorsInternal(parent);
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer)

Aggregations

ExoContainer (org.exoplatform.container.ExoContainer)18 PortalContainer (org.exoplatform.container.PortalContainer)7 RootContainer (org.exoplatform.container.RootContainer)4 ArrayList (java.util.ArrayList)3 ConcurrentContainer (org.exoplatform.container.ConcurrentContainer)2 Container (org.exoplatform.container.spi.Container)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Singleton (javax.inject.Singleton)1 MBeanServer (javax.management.MBeanServer)1 ObjectInstance (javax.management.ObjectInstance)1 CachingContainer (org.exoplatform.container.CachingContainer)1 ComponentTask (org.exoplatform.container.ComponentTask)1 ConcurrentContainerMT (org.exoplatform.container.ConcurrentContainerMT)1 CyclicDependencyException (org.exoplatform.container.CyclicDependencyException)1 Dependency (org.exoplatform.container.Dependency)1 ComponentLifecycle (org.exoplatform.container.component.ComponentLifecycle)1 ComponentRequestLifecycle (org.exoplatform.container.component.ComponentRequestLifecycle)1 ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)1