You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Jeromy Evans <je...@blueskyminds.com.au> on 2009/03/01 02:48:31 UTC
Re: Accessing properties set in struts.xml and/or struts.properties
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.
regards,
Jeromy Evans
On 27/02/2009, at 7:10 PM, Andreas Joseph Krogh wrote:
> On Friday 27 February 2009 08:50:16 Jelmer Kuperus wrote:
>> I implemented something similarar while back by implementing a custom
>> actionmapper. You can then set that one as the default by changing a
>> property
>>
>> It allowed me to get the behaviour i wanted without changing any
>> struts code. I remember there being some gotchas tho.
>
> Yea, I was hoping to avoid having to maintain my own implementation
> just for this feature so I'm hoping someone steps up and explains
> how the struts2-code works with respect to accessing the config-
> properties:-)
>
>> Personally i think exclusion would be a usefull feature
>
> Good:-)
>
> I see quite a lot of other improvements struts2 could benefit from,
> especially the taglibs, and will post a list soon of things me and
> my company would like to implement.
>
> --
> Andreas Joseph Krogh <an...@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: Accessing properties set in struts.xml and/or struts.properties
Posted by Andreas Joseph Krogh <an...@officenet.no>.
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 <an...@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-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org