On Sunday 01 March 2009 02:48:31 Jeromy Evans wrote: > Hi Andreas, > > The perfect place to filter the URLs is before they reach the > Container at all. > The next-best place is within a custom ActionMapper as Jelmer > suggested as that's what it's designed for. I don't think you'll gain > much performance filtering before the ActionMapper and it will confuse > the architecture a little. > > Modifying the default ActionMapper to accept a property that specifies > an exclusion pattern may be a good idea. > > The properties in struts.xml are available by dependency injection in > objects created by Struts2, but the filter is too soon to use that > feature. Instead you'll have to get a reference to the xwork > Container and ask it for the property: > > String pattern = > configuration.getContainer().getInstance(String.class, > "struts.action.url_exclude_pattern"); > > The Configuration instance is available from the > ConfigurationManager. The ConfigurationManager is created during the > InitOperations once when the filter initializes. This is when the > configuration is first read/provided (but it may be re-read/provided > later). The ConfigurationManager is available from the Dispatcher, > which is available in the PrepareOperations used by the > StrutsPrepareFilter. > > To access the configuration in your own version of the > StrutsPrepareFilter, you'll have to replace the filter and > PrepareOperations with a version that checks the URL and configuration > before creating the ActionContext. > > Configuration configuration = > dispatcher.getConfigurationManager().getConfiguration(); > > StrutsPrepareFilter will still need to chain to the next filter, so > you'll also have to modify the StrutsExecuteFilter so it doesn't run > but does chain to its next filter. Doesn't seem very elegant. > > Hope that gets you started.
This is what I've implemented here: https://issues.apache.org/struts/browse/WW-3017 If you look at the attachment "filters2.diff" (https://issues.apache.org/struts/secure/attachment/13965/filters2.diff) you'll see what I've done. I did think about modifying the action-mapper or sub-classing it, but that doesn't really cut it. The point is that I want to be able to configure this *one* place regardless of which action-mapper I use. For example, if I want to use the Restful2ActionMapper I want the same exclusion-logic to apply for it. I've implemented the check for exclusion *after* the action-context is created on purpose. The point is that I don't want Struts to try to auto-map an action based on the excluded URI, and possibly fail, but I *do* want to be able to use all the other goodies struts2 provides, like the s-tags etc. My patch implements just this and is very useful for me. Please take a look at the code and comment. -- Andreas Joseph Krogh <andr...@officenet.no> Senior Software Developer / CEO ------------------------+---------------------------------------------+ OfficeNet AS | The most difficult thing in the world is to | Rosenholmveien 25 | know how to do a thing and to watch | 1414 TrollÄsen | somebody else doing it wrong, without | NORWAY | comment. | | | Tlf: +47 24 15 38 90 | | Fax: +47 24 15 38 91 | | Mobile: +47 909 56 963 | | ------------------------+---------------------------------------------+ --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org For additional commands, e-mail: dev-h...@struts.apache.org