Search in sources :

Example 1 with CookieProcessor

use of org.apache.tomcat.util.http.CookieProcessor in project tomcat by apache.

the class StandardContextSF method storeChildren.

/**
     * Store the specified context element children.
     *
     * @param aWriter Current output writer
     * @param indent Indentation level
     * @param aContext Context to store
     * @param parentDesc The element description
     * @throws Exception Configuration storing error
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aContext, StoreDescription parentDesc) throws Exception {
    if (aContext instanceof StandardContext) {
        StandardContext context = (StandardContext) aContext;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = context.findLifecycleListeners();
        ArrayList<LifecycleListener> listenersArray = new ArrayList<>();
        for (LifecycleListener listener : listeners) {
            if (!(listener instanceof ThreadLocalLeakPreventionListener)) {
                listenersArray.add(listener);
            }
        }
        storeElementArray(aWriter, indent, listenersArray.toArray());
        // Store nested <Valve> elements
        Valve[] valves = context.getPipeline().getValves();
        storeElementArray(aWriter, indent, valves);
        // Store nested <Loader> elements
        Loader loader = context.getLoader();
        storeElement(aWriter, indent, loader);
        // Store nested <Manager> elements
        if (context.getCluster() == null || !context.getDistributable()) {
            Manager manager = context.getManager();
            storeElement(aWriter, indent, manager);
        }
        // Store nested <Realm> element
        Realm realm = context.getRealm();
        if (realm != null) {
            Realm parentRealm = null;
            // @TODO is this case possible?
            if (context.getParent() != null) {
                parentRealm = context.getParent().getRealm();
            }
            if (realm != parentRealm) {
                storeElement(aWriter, indent, realm);
            }
        }
        // Store nested resources
        WebResourceRoot resources = context.getResources();
        storeElement(aWriter, indent, resources);
        // Store nested <WrapperListener> elements
        String[] wLifecycles = context.findWrapperLifecycles();
        getStoreAppender().printTagArray(aWriter, "WrapperListener", indent + 2, wLifecycles);
        // Store nested <WrapperLifecycle> elements
        String[] wListeners = context.findWrapperListeners();
        getStoreAppender().printTagArray(aWriter, "WrapperLifecycle", indent + 2, wListeners);
        // Store nested <Parameter> elements
        ApplicationParameter[] appParams = context.findApplicationParameters();
        storeElementArray(aWriter, indent, appParams);
        // Store nested naming resources elements (EJB,Resource,...)
        NamingResourcesImpl nresources = context.getNamingResources();
        storeElement(aWriter, indent, nresources);
        // Store nested watched resources <WatchedResource>
        String[] wresources = context.findWatchedResources();
        wresources = filterWatchedResources(context, wresources);
        getStoreAppender().printTagArray(aWriter, "WatchedResource", indent + 2, wresources);
        // Store nested <JarScanner> elements
        JarScanner jarScanner = context.getJarScanner();
        storeElement(aWriter, indent, jarScanner);
        // Store nested <CookieProcessor> elements
        CookieProcessor cookieProcessor = context.getCookieProcessor();
        storeElement(aWriter, indent, cookieProcessor);
    }
}
Also used : ApplicationParameter(org.apache.tomcat.util.descriptor.web.ApplicationParameter) ArrayList(java.util.ArrayList) Loader(org.apache.catalina.Loader) LifecycleListener(org.apache.catalina.LifecycleListener) Manager(org.apache.catalina.Manager) JarScanner(org.apache.tomcat.JarScanner) ThreadLocalLeakPreventionListener(org.apache.catalina.core.ThreadLocalLeakPreventionListener) CookieProcessor(org.apache.tomcat.util.http.CookieProcessor) StandardContext(org.apache.catalina.core.StandardContext) Valve(org.apache.catalina.Valve) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) Realm(org.apache.catalina.Realm) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 2 with CookieProcessor

use of org.apache.tomcat.util.http.CookieProcessor in project tomcat by apache.

the class Request method parseCookies.

/**
     * Parse cookies. This only parses the cookies into the memory efficient
     * ServerCookies structure. It does not populate the Cookie objects.
     */
protected void parseCookies() {
    if (cookiesParsed) {
        return;
    }
    cookiesParsed = true;
    ServerCookies serverCookies = coyoteRequest.getCookies();
    serverCookies.setLimit(connector.getMaxCookieCount());
    CookieProcessor cookieProcessor = getContext().getCookieProcessor();
    cookieProcessor.parseCookieHeader(coyoteRequest.getMimeHeaders(), serverCookies);
}
Also used : CookieProcessor(org.apache.tomcat.util.http.CookieProcessor) ServerCookies(org.apache.tomcat.util.http.ServerCookies)

Example 3 with CookieProcessor

use of org.apache.tomcat.util.http.CookieProcessor in project tomcat by apache.

the class Request method convertCookies.

/**
     * Converts the parsed cookies (parsing the Cookie headers first if they
     * have not been parsed) into Cookie objects.
     */
protected void convertCookies() {
    if (cookiesConverted) {
        return;
    }
    cookiesConverted = true;
    if (getContext() == null) {
        return;
    }
    parseCookies();
    ServerCookies serverCookies = coyoteRequest.getCookies();
    CookieProcessor cookieProcessor = getContext().getCookieProcessor();
    int count = serverCookies.getCookieCount();
    if (count <= 0) {
        return;
    }
    cookies = new Cookie[count];
    int idx = 0;
    for (int i = 0; i < count; i++) {
        ServerCookie scookie = serverCookies.getCookie(i);
        try {
            /*
                we must unescape the '\\' escape character
                */
            Cookie cookie = new Cookie(scookie.getName().toString(), null);
            int version = scookie.getVersion();
            cookie.setVersion(version);
            scookie.getValue().getByteChunk().setCharset(cookieProcessor.getCharset());
            cookie.setValue(unescape(scookie.getValue().toString()));
            cookie.setPath(unescape(scookie.getPath().toString()));
            String domain = scookie.getDomain().toString();
            if (domain != null) {
                //avoid NPE
                cookie.setDomain(unescape(domain));
            }
            String comment = scookie.getComment().toString();
            cookie.setComment(version == 1 ? unescape(comment) : null);
            cookies[idx++] = cookie;
        } catch (IllegalArgumentException e) {
        // Ignore bad cookie
        }
    }
    if (idx < count) {
        Cookie[] ncookies = new Cookie[idx];
        System.arraycopy(cookies, 0, ncookies, 0, idx);
        cookies = ncookies;
    }
}
Also used : ServerCookie(org.apache.tomcat.util.http.ServerCookie) Cookie(javax.servlet.http.Cookie) CookieProcessor(org.apache.tomcat.util.http.CookieProcessor) ServerCookie(org.apache.tomcat.util.http.ServerCookie) ServerCookies(org.apache.tomcat.util.http.ServerCookies)

Example 4 with CookieProcessor

use of org.apache.tomcat.util.http.CookieProcessor in project tomee by apache.

the class TomcatWebAppBuilder method beforeStart.

/**
     * {@inheritDoc}
     */
@Override
public void beforeStart(final StandardContext standardContext) {
    if (standardContext.getResources() != null && LazyStopStandardRoot.class.isInstance(standardContext.getResources())) {
        // reset after reload
        Reflections.set(standardContext, "resources", LazyStopStandardRoot.class.cast(standardContext.getResources()).getDelegate());
    }
    final ServletContext sc = standardContext.getServletContext();
    if (sc != null && !SystemInstance.get().getOptions().get(OPENEJB_JSESSION_ID_SUPPORT, true)) {
        final Set<SessionTrackingMode> defaultTrackingModes = sc.getEffectiveSessionTrackingModes();
        if (defaultTrackingModes.contains(SessionTrackingMode.URL)) {
            final Set<SessionTrackingMode> newModes = new HashSet<>();
            newModes.remove(SessionTrackingMode.URL);
            sc.setSessionTrackingModes(newModes);
        }
    }
    initContextLoader(standardContext);
    // used to add custom filters first - our arquillian integration uses it for instance
    // needs to be done now (= before start event) because of addFilterMapBefore() usage
    final String filters = SystemInstance.get().getProperty("org.apache.openejb.servlet.filters");
    if (filters != null) {
        final String[] names = filters.split(",");
        for (final String name : names) {
            final String[] clazzMapping = name.split("=");
            final FilterDef filterDef = new FilterDef();
            filterDef.setFilterClass(clazzMapping[0]);
            filterDef.setFilterName(clazzMapping[0]);
            standardContext.addFilterDef(filterDef);
            final FilterMap filterMap = new FilterMap();
            filterMap.setFilterName(clazzMapping[0]);
            filterMap.addURLPattern(clazzMapping[1]);
            standardContext.addFilterMapBefore(filterMap);
        }
    }
    // mainly to get back compatibility with tomcat <= 8.0
    final String cookieProcessor = SystemInstance.get().getProperty("tomee.tomcat.cookieProcessor");
    if (cookieProcessor != null) {
        // not that important for now if we use the container loader, we mainly want to be able to access
        // the legacy one
        final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            final Class<?> cookieProcessorClass = contextClassLoader.loadClass(cookieProcessor.trim());
            standardContext.setCookieProcessor(CookieProcessor.class.cast(cookieProcessorClass.newInstance()));
        } catch (final Exception e) {
            throw new IllegalArgumentException("Cannot set CookieProcessor: " + cookieProcessor);
        }
    }
}
Also used : FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) SessionTrackingMode(javax.servlet.SessionTrackingMode) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) LifecycleException(org.apache.catalina.LifecycleException) NameNotFoundException(javax.naming.NameNotFoundException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) CookieProcessor(org.apache.tomcat.util.http.CookieProcessor) ServletContext(javax.servlet.ServletContext) HashSet(java.util.HashSet)

Aggregations

CookieProcessor (org.apache.tomcat.util.http.CookieProcessor)4 ServerCookies (org.apache.tomcat.util.http.ServerCookies)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 NameNotFoundException (javax.naming.NameNotFoundException)1 NamingException (javax.naming.NamingException)1 ServletContext (javax.servlet.ServletContext)1 SessionTrackingMode (javax.servlet.SessionTrackingMode)1 Cookie (javax.servlet.http.Cookie)1 LifecycleException (org.apache.catalina.LifecycleException)1 LifecycleListener (org.apache.catalina.LifecycleListener)1 Loader (org.apache.catalina.Loader)1 Manager (org.apache.catalina.Manager)1 Realm (org.apache.catalina.Realm)1 Valve (org.apache.catalina.Valve)1 WebResourceRoot (org.apache.catalina.WebResourceRoot)1 StandardContext (org.apache.catalina.core.StandardContext)1 ThreadLocalLeakPreventionListener (org.apache.catalina.core.ThreadLocalLeakPreventionListener)1 NamingResourcesImpl (org.apache.catalina.deploy.NamingResourcesImpl)1