Hi Dmitry, thanks for chipping in with code and fixing the issue! /peter
GTalk: neubauer.peter Skype peter.neubauer Phone +46 704 106975 LinkedIn http://www.linkedin.com/in/neubauer Twitter http://twitter.com/peterneubauer http://www.neo4j.org - New Energy for Data - The Graph Database. http://www.ops4j.org - New Energy for OSS Communities - Open Participation Software. http://www.oredev.org - Where Good Geeks Grok. On Sun, Jun 21, 2009 at 9:39 PM, <dmi...@ops4j.org> wrote: > Author: dmitry > Date: Sun Jun 21 21:39:46 2009 > New Revision: 15512 > > Log: > PAXWEB-154 - allow passing of dispatcher values as init parameters to filter > registration. Does not address web.xml parsing and war-extender at all. > > Added: > > projects/pax/web/pax-web-bundle/src/test/java/org/ops4j/pax/web/service/internal/model/FilterModelTest.java > Modified: > > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/WebContainerConstants.java > > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/internal/JettyServerImpl.java > > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/internal/model/FilterModel.java > > Modified: > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/WebContainerConstants.java > ============================================================================== > --- > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/WebContainerConstants.java > (original) > +++ > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/WebContainerConstants.java > Sun Jun 21 21:39:46 2009 > @@ -45,6 +45,20 @@ > */ > static final String FILTER_NAME = "filter-name"; > > + /** > + * Filter init param name for specifying a filter-mapping dispatch > behaviour > + * Must be a comma delimited string of: > + * <ol> > + * <li>request</li> > + * <li>forward</li> > + * <li>include</li> > + * <li>error</li> > + * </ol> > + * > + * values are not case sensitive. > + */ > + static final String FILTER_MAPPING_DISPATCHER = > "filter-mapping-dispatcher".intern(); > + > static final String PROPERTY_HTTP_USE_NIO = > "org.osgi.service.http.useNIO"; > static final String PROPERTY_HTTP_PORT = "org.osgi.service.http.port"; > static final String PROPERTY_HTTP_SECURE_PORT = > "org.osgi.service.http.port.secure"; > > Modified: > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/internal/JettyServerImpl.java > ============================================================================== > --- > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/internal/JettyServerImpl.java > (original) > +++ > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/internal/JettyServerImpl.java > Sun Jun 21 21:39:46 2009 > @@ -27,6 +27,7 @@ > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > import org.mortbay.jetty.Connector; > +import org.mortbay.jetty.Handler; > import org.mortbay.jetty.servlet.Context; > import org.mortbay.jetty.servlet.ErrorPageErrorHandler; > import org.mortbay.jetty.servlet.FilterHolder; > @@ -34,6 +35,7 @@ > import org.mortbay.jetty.servlet.ServletHandler; > import org.mortbay.jetty.servlet.ServletHolder; > import org.mortbay.jetty.servlet.ServletMapping; > +import org.mortbay.jetty.servlet.Dispatcher; > import org.mortbay.util.LazyList; > import org.mortbay.xml.XmlConfiguration; > import org.osgi.service.http.HttpContext; > @@ -261,6 +263,14 @@ > { > mapping.setServletNames( model.getServletNames() ); > } > + // set-up dispatcher > + int dispatcher= Handler.DEFAULT; > + for (String d : model.getDispatcher()) > + { > + dispatcher|= Dispatcher.type(d); > + } > + mapping.setDispatches(dispatcher); > + > final Context context = m_server.getOrCreateContext( model ); > final ServletHandler servletHandler = context.getServletHandler(); > if( servletHandler == null ) > @@ -273,6 +283,7 @@ > { > holder.setInitParameters( model.getInitParams() ); > } > + > // Jetty does not set the context class loader on adding the filters > so we do that instead > try > { > > Modified: > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/internal/model/FilterModel.java > ============================================================================== > --- > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/internal/model/FilterModel.java > (original) > +++ > projects/pax/web/pax-web-bundle/src/main/java/org/ops4j/pax/web/service/internal/model/FilterModel.java > Sun Jun 21 21:39:46 2009 > @@ -20,7 +20,10 @@ > import java.util.Dictionary; > import java.util.Enumeration; > import java.util.HashMap; > +import java.util.HashSet; > import java.util.Map; > +import java.util.Set; > +import java.util.StringTokenizer; > import javax.servlet.Filter; > import org.ops4j.lang.NullArgumentException; > import org.ops4j.pax.web.service.WebContainerConstants; > @@ -30,11 +33,21 @@ > extends Model > { > > + private static final Set<String> VALID_DISPATCHER_VALUES = new > HashSet<String>() { > + { > + add("request"); > + add("forward"); > + add("include"); > + add("error"); > + } > + }; > + > private final Filter m_filter; > private final String[] m_urlPatterns; > private final String[] m_servletNames; > private final Map<String, String> m_initParams; > private final String m_name; > + private final Set<String> m_dispatcher = new HashSet<String>(); > > public FilterModel( final ContextModel contextModel, > final Filter filter, > @@ -61,6 +74,43 @@ > name = getId(); > } > m_name = name; > + setupDispatcher(); > + } > + > + /* > + > + */ > + private void setupDispatcher() > + { > + String dispatches = m_initParams.get( > WebContainerConstants.FILTER_MAPPING_DISPATCHER ); > + if (dispatches != null && dispatches.trim().length() > 0) > + { > + if (dispatches.indexOf( "," ) > -1) { > + // parse > + StringTokenizer tok = new StringTokenizer(dispatches.trim(), > ","); > + while(tok.hasMoreTokens()) { > + String element = tok.nextToken(); > + if (element != null && element.trim().length() > 0) > + { > + if ( VALID_DISPATCHER_VALUES.contains( > element.trim().toLowerCase())) > + { > + m_dispatcher.add(element.trim()); > + } else > + { > + throw new IllegalArgumentException( "Incorrect > value of dispatcher " + element.trim()); > + } > + } > + } > + } else { > + if ( VALID_DISPATCHER_VALUES.contains( > dispatches.trim().toLowerCase())) > + { > + m_dispatcher.add(dispatches.trim()); > + } else > + { > + throw new IllegalArgumentException( "Incorrect value of > dispatcher " + dispatches.trim()); > + } > + } > + } > } > > public Filter getFilter() > @@ -88,6 +138,11 @@ > return m_initParams; > } > > + public String[] getDispatcher() > + { > + return m_dispatcher.toArray( new String[m_dispatcher.size()] ); > + } > + > private static Map<String, String> convertToMap( final Dictionary > dictionary ) > { > Map<String, String> converted = new HashMap<String, String>(); > > Added: > projects/pax/web/pax-web-bundle/src/test/java/org/ops4j/pax/web/service/internal/model/FilterModelTest.java > ============================================================================== > --- (empty file) > +++ > projects/pax/web/pax-web-bundle/src/test/java/org/ops4j/pax/web/service/internal/model/FilterModelTest.java > Sun Jun 21 21:39:46 2009 > @@ -0,0 +1,86 @@ > +package org.ops4j.pax.web.service.internal.model; > + > +import java.util.Hashtable; > +import java.util.Arrays; > +import javax.servlet.Filter; > +import static org.easymock.EasyMock.*; > +import org.junit.Test; > +import org.osgi.service.http.HttpContext; > +import org.ops4j.pax.web.service.WebContainerConstants; > + > +/** > + * Created by IntelliJ IDEA. > + * User: dsklyut > + * Date: Jun 18, 2009 > + * Time: 3:09:36 PM > + */ > +public class FilterModelTest > +{ > + > + �...@test > + public void registerWithNoDispatcherInitParams() > + { > + FilterModel fm = > + new FilterModel( new ContextModel( createMock( HttpContext.class > ), null, getClass().getClassLoader() ), > + createMock( Filter.class ), > + new String[]{ "/*" }, > + null, > + new Hashtable() > + ); > + > + System.out.println( Arrays.asList( fm.getDispatcher() ) ); > + } > + > + �...@test > + public void registerWithCorrectSubsetOfDispatcherInitParams() > + { > + FilterModel fm = > + new FilterModel( new ContextModel( createMock( HttpContext.class > ), null, getClass().getClassLoader() ), > + createMock( Filter.class ), > + new String[]{ "/*" }, > + null, > + new Hashtable() > + {{ > + put( > WebContainerConstants.FILTER_MAPPING_DISPATCHER, "REQUEST, FORWARD" ); > + }} > + ); > + > + System.out.println( Arrays.asList( fm.getDispatcher() ) ); > + } > + > + �...@test > + public void registerWithFullComplimentOfDispatcherInitParams() > + { > + FilterModel fm = > + new FilterModel( new ContextModel( createMock( HttpContext.class > ), null, getClass().getClassLoader() ), > + createMock( Filter.class ), > + new String[]{ "/*" }, > + null, > + new Hashtable() > + {{ > + put( > WebContainerConstants.FILTER_MAPPING_DISPATCHER, > + "REQUEST, FORWARD, ERROR , include" > + ); > + }} > + ); > + > + System.out.println( Arrays.asList( fm.getDispatcher() ) ); > + } > + > + �...@test( expected = IllegalArgumentException.class ) > + public void registerWithErrorInDispatcherInitParams() > + { > + new FilterModel( new ContextModel( createMock( HttpContext.class ), > null, getClass().getClassLoader() ), > + createMock( Filter.class ), > + new String[]{ "/*" }, > + null, > + new Hashtable() > + {{ > + put( > WebContainerConstants.FILTER_MAPPING_DISPATCHER, > + "REQuEST, ZFORWARD, , , include" > + ); > + }} > + ); > + > + } > +} > > _______________________________________________ > notify mailing list > not...@lists.ops4j.org > http://lists.ops4j.org/mailman/listinfo/notify > > _______________________________________________ general mailing list general@lists.ops4j.org http://lists.ops4j.org/mailman/listinfo/general