You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2010/02/14 19:37:17 UTC
svn commit: r910059 - in /incubator/jspwiki/trunk: src/WebContent/WEB-INF/
src/java/org/apache/wiki/action/ src/java/org/apache/wiki/ui/migrator/
src/java/org/apache/wiki/ui/stripes/ tests/java/org/apache/wiki/
Author: ajaquith
Date: Sun Feb 14 18:37:15 2010
New Revision: 910059
URL: http://svn.apache.org/viewvc?rev=910059&view=rev
Log:
Changed a few classes that depend on Stripes to use "lazy initialization." WikiContextFactory and StripesURLConstructor must lazily initialize because they depend on StripesFilter being initialized first. Cleaned up TestEngine also: it now initializes a full mock Stripes filter stack at startup.
Modified:
incubator/jspwiki/trunk/src/WebContent/WEB-INF/web.xml
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/migrator/JspMigrator.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/HandlerInfo.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiSessionTest.java
Modified: incubator/jspwiki/trunk/src/WebContent/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/WEB-INF/web.xml?rev=910059&r1=910058&r2=910059&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/WEB-INF/web.xml (original)
+++ incubator/jspwiki/trunk/src/WebContent/WEB-INF/web.xml Sun Feb 14 18:37:15 2010
@@ -39,6 +39,13 @@
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>templates.default</param-value>
</context-param>
+ <!-- Look for ActionBean implementations in the JSPWiki "action" package.
+ If you have custom WikiActionBeans you want JSPWiki to use, specify them
+ here (comma-delimited). -->
+ <context-param>
+ <param-name>ActionResolver.Packages</param-name>
+ <param-value>org.apache.wiki.action</param-value>
+ </context-param>
<!-- Configuration of the Stripes Filter. The Stripes MVC framework provides
essential request routing, form processing and type conversion services
@@ -50,13 +57,6 @@
<display-name>Stripes Filter</display-name>
<filter-name>StripesFilter</filter-name>
<filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
- <!-- Look for ActionBean implementations in the JSPWiki "action" package.
- If you have custom WikiActionBeans you want JSPWiki to use, specify them
- here (comma-delimited). -->
- <init-param>
- <param-name>ActionResolver.Packages</param-name>
- <param-value>org.apache.wiki.action</param-value>
- </init-param>
<!-- Tell Stripes to auto-discover custom extensions from the "ui.stripes"
package. Extensions JSPWiki uses includes WikiActionBeanContext,
WikiRuntimeConfiguration, WikiInterceptor and the various TypeConverter
@@ -83,7 +83,7 @@
<param-name>MultipartWrapper.Class</param-name>
<param-value>net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper</param-value>
</init-param>
- <!-- Exception handler classes -->
+ <!-- Exception handler -->
<init-param>
<param-name>ExceptionHandler.Class</param-name>
<param-value>org.apache.wiki.ui.stripes.WikiExceptionHandler</param-value>
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java?rev=910059&r1=910058&r2=910059&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java Sun Feb 14 18:37:15 2010
@@ -22,21 +22,27 @@
package org.apache.wiki.action;
import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
-import java.util.Set;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
+import net.sourceforge.stripes.action.ActionBean;
+import net.sourceforge.stripes.config.Configuration;
+import net.sourceforge.stripes.controller.ActionResolver;
+import net.sourceforge.stripes.controller.AnnotatedClassActionResolver;
+import net.sourceforge.stripes.controller.StripesFilter;
+import net.sourceforge.stripes.controller.UrlBindingFactory;
import net.sourceforge.stripes.mock.MockHttpServletRequest;
import net.sourceforge.stripes.mock.MockHttpServletResponse;
import net.sourceforge.stripes.mock.MockHttpSession;
-import net.sourceforge.stripes.util.ResolverUtil;
+import org.apache.wiki.InternalWikiException;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiProvider;
@@ -81,15 +87,6 @@
*/
public static final String ATTR_WIKISESSION = "wikiSession";
- /** Default list of packages to search for WikiActionBean implementations. */
- public static final String DEFAULT_ACTIONBEAN_PACKAGES = "org.apache.wiki.action";
-
- /**
- * Property in jspwiki.properties that specifies packages to search for
- * WikiActionBean implementations.
- */
- public static final String PROPS_ACTIONBEAN_PACKAGES = "jspwiki.actionBean.packages";
-
private static final Logger log = LoggerFactory.getLogger( WikiContextFactory.class );
private static final long serialVersionUID = 1L;
@@ -137,6 +134,8 @@
private String m_mockContextPath;
+ private boolean m_contextMap_inited = false;
+
/** Maps (pre-3.0) request contexts map to WikiActionBeans. */
private final Map<String, HandlerInfo> m_contextMap = new HashMap<String, HandlerInfo>();
@@ -153,15 +152,9 @@
super();
m_engine = engine;
- initRequestContextMap( properties );
-
-
// Set the path prefix for constructing synthetic Stripes mock requests;
// trailing slash is removed.
m_mockContextPath = StripesURLConstructor.getContextPath( engine );
-
- // TODO: make packages to search in ActionBeanResolver configurable
- // (currently hard-coded)
}
/**
@@ -176,6 +169,10 @@
*/
public HandlerInfo findEventHandler( String requestContext )
{
+ if ( !m_contextMap_inited )
+ {
+ initRequestContextMap();
+ }
HandlerInfo handler = m_contextMap.get( requestContext );
if( handler == null )
{
@@ -246,6 +243,11 @@
*/
public WikiActionBeanContext newViewContext( HttpServletRequest request, HttpServletResponse response, WikiPage page )
{
+ if ( !m_contextMap_inited )
+ {
+ initRequestContextMap();
+ }
+
// Create a new "view" WikiActionBeanContext, and swallow any exceptions
WikiActionBeanContext ctx = null;
try
@@ -276,55 +278,47 @@
}
/**
- * Searches a set of named packages for WikiActionBean implementations, and
- * returns any it finds.
- *
- * @param beanPackages the packages to search on the current classpath,
- * separated by commas
- * @return the discovered classes
- */
- private Set<Class<? extends WikiActionBean>> findBeanClasses( String[] beanPackages )
- {
- ResolverUtil<WikiActionBean> resolver = new ResolverUtil<WikiActionBean>();
- resolver.findImplementations( WikiActionBean.class, beanPackages );
- return resolver.getClasses();
- }
-
- /**
* Initializes the internal map that matches wiki request contexts with
- * HandlerInfo objects.
- *
- * @param properties
+ * HandlerInfo objects. The internal map is lazily inited, because it
+ * <em>must</em> happen after the StripesFilter initializes.
*/
- private void initRequestContextMap( Properties properties )
+ private void initRequestContextMap()
{
- // Look up all classes that are WikiActionBeans.
- String beanPackagesProp = properties.getProperty( PROPS_ACTIONBEAN_PACKAGES, DEFAULT_ACTIONBEAN_PACKAGES ).trim();
- String[] beanPackages = beanPackagesProp.split( "," );
- Set<Class<? extends WikiActionBean>> beanClasses = findBeanClasses( beanPackages );
-
- // Stash the contexts and corresponding classes into a Map.
- for( Class<? extends WikiActionBean> beanClass : beanClasses )
+ Configuration stripesConfig = StripesFilter.getConfiguration();
+ if ( stripesConfig == null )
+ {
+ throw new InternalWikiException( "Could not obtain Stripes configuration. FATAL." );
+ }
+ ActionResolver resolver = stripesConfig.getActionResolver();
+ if ( resolver instanceof AnnotatedClassActionResolver )
{
- Map<Method, HandlerInfo> handlerMethods = HandlerInfo.getHandlerInfoCollection( beanClass );
- for( HandlerInfo handler : handlerMethods.values() )
+ UrlBindingFactory urlBindings = ((AnnotatedClassActionResolver)resolver).getUrlBindingFactory();
+ Collection<Class<? extends ActionBean>> beanClasses = urlBindings.getActionBeanClasses();
+
+ // Stash the contexts and corresponding classes into a Map.
+ for( Class<? extends ActionBean> beanClass : beanClasses )
{
- String requestContext = handler.getRequestContext();
- if( m_contextMap.containsKey( requestContext ) )
- {
- HandlerInfo duplicateHandler = m_contextMap.get( requestContext );
- log.error( "Bean class " + beanClass.getCanonicalName() + " contains @WikiRequestContext annotation '"
- + requestContext + "' that duplicates one already declared for "
- + duplicateHandler.getActionBeanClass() );
- }
- else
+ Map<Method, HandlerInfo> handlerMethods = HandlerInfo.getHandlerInfoCollection( beanClass );
+ for( HandlerInfo handler : handlerMethods.values() )
{
- m_contextMap.put( requestContext, handler );
- log.debug( "Discovered request context '" + requestContext + "' for WikiActionBean="
- + beanClass.getCanonicalName() + ",event=" + handler.getEventName() );
+ String requestContext = handler.getRequestContext();
+ if( m_contextMap.containsKey( requestContext ) )
+ {
+ HandlerInfo duplicateHandler = m_contextMap.get( requestContext );
+ log.error( "Bean class " + beanClass.getCanonicalName() + " contains @WikiRequestContext annotation '"
+ + requestContext + "' that duplicates one already declared for "
+ + duplicateHandler.getActionBeanClass() );
+ }
+ else
+ {
+ m_contextMap.put( requestContext, handler );
+ log.debug( "Discovered request context '" + requestContext + "' for WikiActionBean="
+ + beanClass.getCanonicalName() + ",event=" + handler.getEventName() );
+ }
}
}
}
+ m_contextMap_inited = true;
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/migrator/JspMigrator.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/migrator/JspMigrator.java?rev=910059&r1=910058&r2=910059&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/migrator/JspMigrator.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/migrator/JspMigrator.java Sun Feb 14 18:37:15 2010
@@ -27,9 +27,8 @@
import java.io.IOException;
import java.util.*;
-import org.apache.wiki.action.WikiContextFactory;
-
import net.sourceforge.stripes.action.ActionBean;
+import net.sourceforge.stripes.controller.AnnotatedClassActionResolver;
import net.sourceforge.stripes.util.ResolverUtil;
@@ -147,8 +146,7 @@
protected static Set<Class<? extends ActionBean>> findBeanClasses()
{
// Find all ActionBean implementations on the classpath
- String beanPackagesProp = System.getProperty( WikiContextFactory.PROPS_ACTIONBEAN_PACKAGES,
- WikiContextFactory.DEFAULT_ACTIONBEAN_PACKAGES ).trim();
+ String beanPackagesProp = System.getProperty( AnnotatedClassActionResolver.PACKAGES, "org.apache.wiki.action" ).trim();
String[] beanPackages = beanPackagesProp.split( "," );
ResolverUtil<ActionBean> resolver = new ResolverUtil<ActionBean>();
resolver.findImplementations( ActionBean.class, beanPackages );
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/HandlerInfo.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/HandlerInfo.java?rev=910059&r1=910058&r2=910059&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/HandlerInfo.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/HandlerInfo.java Sun Feb 14 18:37:15 2010
@@ -31,13 +31,13 @@
import javax.servlet.jsp.el.ELException;
+import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.HandlesEvent;
import net.sourceforge.stripes.util.bean.EvaluationException;
import net.sourceforge.stripes.util.bean.PropertyExpression;
import net.sourceforge.stripes.util.bean.PropertyExpressionEvaluation;
-import org.apache.wiki.action.WikiActionBean;
import org.apache.wiki.auth.permissions.PagePermission;
import org.apache.wiki.auth.permissions.PermissionFactory;
import org.apache.wiki.tags.SpamProtectTag;
@@ -52,9 +52,9 @@
*/
public class HandlerInfo
{
- private static final Map<Class<? extends WikiActionBean>, Map<Method, HandlerInfo>> CACHED_INFO = new HashMap<Class<? extends WikiActionBean>, Map<Method, HandlerInfo>>();
+ private static final Map<Class<? extends ActionBean>, Map<Method, HandlerInfo>> CACHED_INFO = new HashMap<Class<? extends ActionBean>, Map<Method, HandlerInfo>>();
- private final Class<? extends WikiActionBean> m_beanClass;
+ private final Class<? extends ActionBean> m_beanClass;
private final Method m_handlerMethod;
@@ -78,7 +78,7 @@
/**
* Private constructor that identifies relevant Permission and wiki request
- * context information for a supplied WikiActionBean's event method. The
+ * context information for a supplied ActionBean's event method. The
* supplied event method must have previously been determined to have a
* {@link HandlesEvent} annotation. This constructor also looks for a
* {@link HandlerPermission} annotation to determine the correct Permission
@@ -94,7 +94,7 @@
* @param method the method that denotes the event handler
* @param eventHandler the name of the event the method handles
*/
- private HandlerInfo( Class<? extends WikiActionBean> beanClass, Method method, String eventHandler )
+ private HandlerInfo( Class<? extends ActionBean> beanClass, Method method, String eventHandler )
{
// Determine the permission annotated by @HandlerPermission (if
// supplied)
@@ -195,14 +195,14 @@
/**
* Returns the HandlerInfo object associated with the default Stripes event
- * handler method for a supplied class. All Stripes ActionBeans (and JSPWiki
- * WikiActionBeans, by definition) must contain a method with the
- * {@link net.sourceforge.stripes.action.DefaultHandler} annotation.
+ * handler method for a supplied class. All Stripes ActionBeans must contain
+ * a method with the {@link net.sourceforge.stripes.action.DefaultHandler}
+ * annotation.
*
* @param beanClass the ActionBean subclass to inspect
* @return the event info object for the default handler method
*/
- public static final HandlerInfo getDefaultHandlerInfo( Class<? extends WikiActionBean> beanClass )
+ public static final HandlerInfo getDefaultHandlerInfo( Class<? extends ActionBean> beanClass )
{
Map<Method, HandlerInfo> eventInfoCollection = CACHED_INFO.get( beanClass );
if( eventInfoCollection == null )
@@ -224,15 +224,15 @@
}
/**
- * Looks up and returns the HandlerInfo for a supplied WikiActionBean class
- * and event handler name. The supplied WikiActionBean class must contain a
+ * Looks up and returns the HandlerInfo for a supplied ActionBean class
+ * and event handler name. The supplied ActionBean class must contain a
* Stripes event handler method whose {@link HandlesEvent} annotation value
* matches the <code>eventHandler</code> parameter value.
*
* @param eventHandler the Stripes ActionBean method to inspect
* @return the event info object for the handler method
*/
- public static final HandlerInfo getHandlerInfo( Class<? extends WikiActionBean> beanClass, String eventHandler )
+ public static final HandlerInfo getHandlerInfo( Class<? extends ActionBean> beanClass, String eventHandler )
{
Collection<HandlerInfo> handlerInfos = getHandlerInfoCollection( beanClass ).values();
for( HandlerInfo handlerInfo : handlerInfos )
@@ -253,7 +253,7 @@
* @param beanClass the ActionBean subclass to inspect
* @return the map
*/
- public static final Map<Method, HandlerInfo> getHandlerInfoCollection( Class<? extends WikiActionBean> beanClass )
+ public static final Map<Method, HandlerInfo> getHandlerInfoCollection( Class<? extends ActionBean> beanClass )
{
// If we've already figured out the method info, return the cached Map
Map<Method, HandlerInfo> eventInfoCollection = CACHED_INFO.get( beanClass );
@@ -283,12 +283,12 @@
}
/**
- * Returns the WikiActionBean class that is the parent of the event method
+ * Returns the ActionBean class that is the parent of the event method
* used to instantiate the HandlerInfo object.
*
- * @return the WikiActionBean class
+ * @return the ActionBean class
*/
- public Class<? extends WikiActionBean> getActionBeanClass()
+ public Class<? extends ActionBean> getActionBeanClass()
{
return m_beanClass;
}
@@ -322,7 +322,7 @@
* the event handler method contains an additional
* {@link WikiRequestContext} annotation, the annotation value will be used.
* Otherwise, a default wiki request context will be returned, based on the
- * WikiActionBean's class name plus the event name, separated by ".".
+ * ActionBean's class name plus the event name, separated by ".".
* </p>
* <p>
* For example, consider the two event handler methods in FooActionBean
@@ -330,7 +330,7 @@
* </p>
*
* <pre>
- * public class FooActionBean extends WikiActionBean
+ * public class FooActionBean extends ActionBean
* {
* @WikiRequestContext("view")
* @HandlesEvent("view")
Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java?rev=910059&r1=910058&r2=910059&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java Sun Feb 14 18:37:15 2010
@@ -30,6 +30,8 @@
import javax.servlet.http.HttpServletRequest;
import net.sourceforge.stripes.action.UrlBinding;
+import net.sourceforge.stripes.config.BootstrapPropertyResolver;
+import net.sourceforge.stripes.controller.AnnotatedClassActionResolver;
import net.sourceforge.stripes.controller.DynamicMappingFilter;
import net.sourceforge.stripes.controller.StripesFilter;
import net.sourceforge.stripes.mock.*;
@@ -54,6 +56,7 @@
import org.apache.wiki.providers.AbstractFileProvider;
import org.apache.wiki.providers.ProviderException;
import org.apache.wiki.tags.SpamProtectTag;
+import org.apache.wiki.ui.stripes.ShortUrlFilter;
import org.apache.wiki.ui.stripes.SpamInterceptor;
import org.apache.wiki.util.FileUtil;
import org.apache.wiki.util.TextUtil;
@@ -141,9 +144,9 @@
public TestEngine( Properties props )
throws WikiException
{
- super( new MockServletContext( "test" ), "test", cleanTestProps( props ) );
+ super( configureServletContext( new MockServletContext( "TestEngine" ) ), "test", cleanTestProps( props ) );
- // Stash the WikiEngine in the servlet context
+ // Configure and stash the WikiEngine in the servlet context
ServletContext servletContext = this.getServletContext();
servletContext.setAttribute("org.apache.wiki.WikiEngine", this);
}
@@ -156,7 +159,7 @@
public MockHttpServletRequest newHttpRequest()
{
UrlBinding binding = ViewActionBean.class.getAnnotation( UrlBinding.class );
- String url = binding == null ? "/Wiki.action" : binding.value();
+ String url = binding == null ? "/Wiki.jsp" : binding.value();
return newHttpRequest( url );
}
@@ -415,6 +418,21 @@
WikiContext context = this.getWikiContextFactory().newViewContext( request, null, page );
saveText( context, content );
}
+
+ /**
+ * Shuts down the WikiEngine in an orderly fashion. All of the filters
+ * in MockServletContext are destroyed. In particular, StripesFilter's
+ * configuration stash is cleaned up.
+ */
+ public void shutdown()
+ {
+ MockServletContext servletContext = (MockServletContext)getServletContext();
+ for ( Filter filter : servletContext.getFilters() )
+ {
+ filter.destroy();
+ }
+ super.shutdown();
+ }
public static void trace()
{
@@ -454,7 +472,7 @@
MockServletContext servletContext = (MockServletContext)getServletContext();
if ( servletContext.getFilters().size() == 0 )
{
- initMockContext( servletContext );
+ getFilterChain();
}
return new MockRoundtrip( servletContext, beanClass );
}
@@ -473,7 +491,7 @@
MockServletContext servletContext = (MockServletContext)getServletContext();
if ( servletContext.getFilters().size() == 0 )
{
- initMockContext( servletContext );
+ getFilterChain();
}
return new MockRoundtrip( servletContext, url );
}
@@ -494,7 +512,7 @@
MockServletContext servletContext = (MockServletContext)getServletContext();
if ( servletContext.getFilters().size() == 0 )
{
- initMockContext( servletContext );
+ getFilterChain();
}
MockRoundtrip trip = new MockRoundtrip( servletContext, beanClass );
WikiSession session = WikiSession.getWikiSession( this, trip.getRequest() );
@@ -503,24 +521,13 @@
}
/**
- * Initializes a supplied MockServletContext with the Stripes filters and
- * dummy servlet added.
+ * Initializes a MockFilterChain for a supplied MockServletContext.
* @param servletContext the mock context
* @return a configured MockFilterChain appropriate for the servlet context
*/
- public static MockFilterChain initMockContext( MockServletContext servletContext )
+ public MockFilterChain getFilterChain()
{
- // Configure the StripesFilter
- Map<String,String> filterParams = new HashMap<String,String>();
- filterParams.put( "ActionResolver.Packages", "org.apache.wiki.action" );
- filterParams.put( "Extension.Packages", "org.apache.wiki.ui.stripes" );
- filterParams.put( "ExceptionHandler.Class", "org.apache.wiki.ui.stripes.WikiExceptionHandler" );
- servletContext.addFilter( StripesFilter.class, "StripesFilter", filterParams );
-
- // Configure the DynamicMappingFilter and dummy servlet
- filterParams = new HashMap<String,String>();
- servletContext.addFilter( DynamicMappingFilter.class, "DynamicMappingFilter", filterParams );
- servletContext.setServlet( MockServlet.class, "MockServlet", new HashMap<String,String>() );
+ MockServletContext servletContext = (MockServletContext)getServletContext();
// Create FilterConfig
MockFilterConfig filterConfig = new MockFilterConfig();
@@ -537,6 +544,36 @@
chain.setServlet( new MockServlet() );
return chain;
}
+
+ /**
+ * Initializes a supplied MockServletContext with the Stripes filters and
+ * dummy servlet added.
+ * @param servletContext the mock context
+ * @return a configured MockFilterChain appropriate for the servlet context
+ */
+ public static MockServletContext configureServletContext( MockServletContext servletContext )
+ {
+ // Create the ServletContext and add init params
+ Map<String,String> initParams = new HashMap<String,String>();
+ initParams.put( AnnotatedClassActionResolver.PACKAGES, "org.apache.wiki.action" );
+ servletContext.addAllInitParameters( initParams );
+
+ // Configure the ShortURLFilter
+ servletContext.addFilter( ShortUrlFilter.class, "ShortURLFilter", null );
+
+ // Configure the StripesFilter
+ Map<String,String> filterParams = new HashMap<String,String>();
+ filterParams.put( BootstrapPropertyResolver.PACKAGES, "org.apache.wiki.ui.stripes" );
+ filterParams.put( "ExceptionHandler.Class", "org.apache.wiki.ui.stripes.WikiExceptionHandler" );
+ servletContext.addFilter( StripesFilter.class, "StripesFilter", filterParams );
+
+ // Configure the DynamicMappingFilter and dummy servlet
+ filterParams = new HashMap<String,String>();
+ servletContext.addFilter( DynamicMappingFilter.class, "DynamicMappingFilter", filterParams );
+ servletContext.setServlet( MockServlet.class, "MockServlet", new HashMap<String,String>() );
+
+ return servletContext;
+ }
/**
* Dummy servlet that returns a {@link java.io.FileNotFoundException}
@@ -567,6 +604,9 @@
m_config = config;
}
+ /**
+ * Must throw a FileNotFoundException to force DynamicMappingFilter to resolve the ActionBean.
+ */
public void service( ServletRequest request, ServletResponse response ) throws ServletException, IOException
{
throw new FileNotFoundException( "File not found: required for DynamicMappingFilter." );
Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiSessionTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiSessionTest.java?rev=910059&r1=910058&r2=910059&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiSessionTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiSessionTest.java Sun Feb 14 18:37:15 2010
@@ -20,6 +20,7 @@
*/
package org.apache.wiki;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.Principal;
import java.util.HashSet;
@@ -36,7 +37,6 @@
import net.sourceforge.stripes.mock.MockFilterChain;
import net.sourceforge.stripes.mock.MockHttpServletRequest;
import net.sourceforge.stripes.mock.MockHttpServletResponse;
-import net.sourceforge.stripes.mock.MockServletContext;
import org.apache.commons.lang.ArrayUtils;
import org.apache.wiki.api.WikiException;
@@ -347,15 +347,18 @@
* @throws ServletException
* @throws IOException
*/
- private static void runSecurityFilter(WikiEngine engine, HttpServletRequest request) throws ServletException, IOException
+ private static void runSecurityFilter(TestEngine engine, HttpServletRequest request) throws ServletException, IOException
{
- // Create a mock servlet context and stash the wiki engine in it
- MockServletContext servletCtx = new MockServletContext( "JSPWiki" );
- servletCtx.setAttribute( "org.apache.wiki.WikiEngine", engine );
-
// Init the mock filter configuration
- MockFilterChain chain = TestEngine.initMockContext( servletCtx );
- chain.doFilter( request, new MockHttpServletResponse() );
+ MockFilterChain chain = engine.getFilterChain();
+ try
+ {
+ chain.doFilter( request, new MockHttpServletResponse() );
+ }
+ catch ( FileNotFoundException e )
+ {
+ // We expect our MockFilter to throw this. No big deal.
+ }
}
public static Test suite()