Search in sources :

Example 21 with FilterMap

use of org.apache.tomcat.util.descriptor.web.FilterMap 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

FilterMap (org.apache.tomcat.util.descriptor.web.FilterMap)21 FilterDef (org.apache.tomcat.util.descriptor.web.FilterDef)14 Context (org.apache.catalina.Context)7 Tomcat (org.apache.catalina.startup.Tomcat)5 HashMap (java.util.HashMap)4 DispatcherType (javax.servlet.DispatcherType)4 HashSet (java.util.HashSet)3 Container (org.apache.catalina.Container)3 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)3 IOException (java.io.IOException)2 HttpURLConnection (java.net.HttpURLConnection)2 URL (java.net.URL)2 List (java.util.List)2 Wrapper (org.apache.catalina.Wrapper)2 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)2 TesterContext (org.apache.tomcat.unittest.TesterContext)2 ErrorPage (org.apache.tomcat.util.descriptor.web.ErrorPage)2 Test (org.junit.Test)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1