You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Andreas Joseph Krogh <an...@officenet.no> on 2009/02/25 22:27:25 UTC

Accessing properties set in struts.xml and/or struts.properties

Hi all.
I would like to extend the struts2 servlet-filters with a config-option telling it URI-patterns to exclude. My thoughts are to add a property:

struts.action.url_exclude_pattern=/lang/.*,/pages/.*

and have the StrutsPrepareFilter, StrutsExecuteFilter and StrutsPrepareAndExecuteFilter ignoring any URI matching these comma-separated patters. I'm planning to build up a list if patters to match in the filters' init-method and then bail out if any of them match in doFilter().

The problem I'm facing is accessing my new property (or any other struts2-property for that matter) in the servlet-filters. What is the "correct way" of accessing struts2-properties set in struts.xml or struts.properties?

Is this of interest to anyone else, and is there any chance this addition will get accepted and included in a future release? I hope so, or else I'll have to maintain my own implementations of the servlet-filters.

-- 
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


Re: Accessing properties set in struts.xml and/or struts.properties

Posted by Andreas Joseph Krogh <an...@officenet.no>.
On Thursday 26 February 2009 17:45:52 Chris Pratt wrote:
> You might have to specify it as a servlet filter init parameter instead of
> relying on struts.xml/properties.
>   (*Chris*)

Yes, I know that would do the trick, but my ambition was to keep all Struts2-related config in *one* place (struts.xml or struts.properties) instead of scattered around.

So, again: Is there a mechanism in place for accessing these properties in a uniform way from "everywhere"?

-- 
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


Re: Accessing properties set in struts.xml and/or struts.properties

Posted by Chris Pratt <th...@gmail.com>.
You might have to specify it as a servlet filter init parameter instead of
relying on struts.xml/properties.
  (*Chris*)

On Thu, Feb 26, 2009 at 3:18 AM, Andreas Joseph Krogh
<an...@officenet.no>wrote:

> On Wednesday 25 February 2009 22:27:25 Andreas Joseph Krogh wrote:
> > Hi all.
> > I would like to extend the struts2 servlet-filters with a config-option
> telling it URI-patterns to exclude. My thoughts are to add a property:
> >
> > struts.action.url_exclude_pattern=/lang/.*,/pages/.*
> >
> > and have the StrutsPrepareFilter, StrutsExecuteFilter and
> StrutsPrepareAndExecuteFilter ignoring any URI matching these
> comma-separated patters. I'm planning to build up a list if patters to match
> in the filters' init-method and then bail out if any of them match in
> doFilter().
> >
> > The problem I'm facing is accessing my new property (or any other
> struts2-property for that matter) in the servlet-filters. What is the
> "correct way" of accessing struts2-properties set in struts.xml or
> struts.properties?
> >
> > Is this of interest to anyone else, and is there any chance this addition
> will get accepted and included in a future release? I hope so, or else I'll
> have to maintain my own implementations of the servlet-filters.
>
> Anyone?
>
> --
> 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
>
>

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


Re: Accessing properties set in struts.xml and/or struts.properties

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
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 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


Re: Accessing properties set in struts.xml and/or struts.properties

Posted by Jelmer Kuperus <jk...@gmail.com>.
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.

Personally i think exclusion would be a usefull feature




Op 26 feb 2009 om 12:18 heeft Andreas Joseph Krogh  
<an...@officenet.no> het volgende geschreven:\

> On Wednesday 25 February 2009 22:27:25 Andreas Joseph Krogh wrote:
>> Hi all.
>> I would like to extend the struts2 servlet-filters with a config- 
>> option telling it URI-patterns to exclude. My thoughts are to add a  
>> property:
>>
>> struts.action.url_exclude_pattern=/lang/.*,/pages/.*
>>
>> and have the StrutsPrepareFilter, StrutsExecuteFilter and  
>> StrutsPrepareAndExecuteFilter ignoring any URI matching these comma- 
>> separated patters. I'm planning to build up a list if patters to  
>> match in the filters' init-method and then bail out if any of them  
>> match in doFilter().
>>
>> The problem I'm facing is accessing my new property (or any other  
>> struts2-property for that matter) in the servlet-filters. What is  
>> the "correct way" of accessing struts2-properties set in struts.xml  
>> or struts.properties?
>>
>> Is this of interest to anyone else, and is there any chance this  
>> addition will get accepted and included in a future release? I hope  
>> so, or else I'll have to maintain my own implementations of the  
>> servlet-filters.
>
> Anyone?
>
> -- 
> 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 Wednesday 25 February 2009 22:27:25 Andreas Joseph Krogh wrote:
> Hi all.
> I would like to extend the struts2 servlet-filters with a config-option telling it URI-patterns to exclude. My thoughts are to add a property:
> 
> struts.action.url_exclude_pattern=/lang/.*,/pages/.*
> 
> and have the StrutsPrepareFilter, StrutsExecuteFilter and StrutsPrepareAndExecuteFilter ignoring any URI matching these comma-separated patters. I'm planning to build up a list if patters to match in the filters' init-method and then bail out if any of them match in doFilter().
> 
> The problem I'm facing is accessing my new property (or any other struts2-property for that matter) in the servlet-filters. What is the "correct way" of accessing struts2-properties set in struts.xml or struts.properties?
> 
> Is this of interest to anyone else, and is there any chance this addition will get accepted and included in a future release? I hope so, or else I'll have to maintain my own implementations of the servlet-filters.

Anyone?

-- 
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