You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Don Brown <mr...@twdata.org> on 2003/07/01 00:18:44 UTC

[PROPOSAL] Wildcard-matched actions

Perhaps now that 1.1 is final, this would be a good time to bring this up.
I've written a small extension to Struts that allows action mappings to
use wildcards in matching URIs.  The matched values can then be
substituted anywhere in the action mapping - similar to how Cocoon
operates (in fact the wildcard code was copied from Cocoon).  The code
only affects the processActionMapping method of the RequestProcessor.

Why you ask?

 - Much smaller config files
 - Use of wildcards encourages more consistency of naming action forms,
actions, and jsp files.
 - Allows for noun-based URLs in addition to current verb-based URLS,
particularly useful in REST-style web services
 - No performance loss: wildcard matching only occurs when a direct
mapping for the URI cannot be found

For example:

    <!-- Matches all edit forms -->
    <action    path="/edit*"
               type="org.apache.struts.webapp.example.Edit{1}Action"
          attribute="{1}Form"
              scope="request"
           validate="false">
      <forward name="failure"              path="/mainMenu.jsp"/>
      <forward name="success"              path="/{1}.jsp"/>
    </action>

By including this feature directly in Struts, wildcards would be available
to all Struts applications as opposed to now where wildcard support
requires a RequestProcessor extension.

For more information:

http://www.twdata.org/struts-wildcard/

Don


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Re: [PROPOSAL] Wildcard-matched actions

Posted by Don Brown <mr...@twdata.org>.
On Sunday 06 July 2003 02:12 am, Ted Husted wrote:
<snip />
> Don,
>
> Would your patch interact with
>
> http://issues.apache.org/bugzilla/show_bug.cgi?id=15921

I don't see why not.  My patch inserts a few lines in processMapping which 
calls a helper class that runs through all the action configs, matches one, 
clones it and replaces wildcard values with the literal values, and returns 
the new clone.  

I'll put the code in patch form and post it on bugzilla.

Don

>
>
> -Ted.
>
> Graham Leggett wrote:
> > Don Brown wrote:
> >> Perhaps now that 1.1 is final, this would be a good time to bring this
> >> up.
> >> I've written a small extension to Struts that allows action mappings to
> >> use wildcards in matching URIs.
> >
> > I submitted a patch to bugzilla a while back that did prefix matching in
> > matching URIs. A config called "foo" could be called, regardless of
> > whether it was accessed as "/bar/foo", or "/fred/foo". Very useful for
> > standard functionality that is reused in a site, such as a login form.
> > We've been using it for a while, and it works great.
> >
> > Wildcard matching would also be really useful.
> >
> > Regards,
> > Graham


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Re: [PROPOSAL] Wildcard-matched actions

Posted by Ted Husted <hu...@apache.org>.
Graham,

I don't see that ticket on the current patch list:


http://issues.apache.org/bugzilla/buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=VERIFIED&email1=&emailtype1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_id=&changedin=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&product=Struts&short_desc=&short_desc_type=allwordssubstr&long_desc=&long_desc_type=allwordssubstr&bug_file_loc=&bug_file_loc_type=allwordssubstr&keywords=PatchAvailable&keywords_type=anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&cmdtype=doit&newqueryname=&order=Bug+Number

[Select all status but RESOLVED and CLOSED, select Struts, enter 
"PatchAvailable" in keyword.]

do you have the ticket number?


Don,

Would your patch interact with

http://issues.apache.org/bugzilla/show_bug.cgi?id=15921


-Ted.

Graham Leggett wrote:
> Don Brown wrote:
> 
>> Perhaps now that 1.1 is final, this would be a good time to bring this 
>> up.
>> I've written a small extension to Struts that allows action mappings to
>> use wildcards in matching URIs.
> 
> 
> I submitted a patch to bugzilla a while back that did prefix matching in 
> matching URIs. A config called "foo" could be called, regardless of 
> whether it was accessed as "/bar/foo", or "/fred/foo". Very useful for 
> standard functionality that is reused in a site, such as a login form. 
> We've been using it for a while, and it works great.
> 
> Wildcard matching would also be really useful.
> 
> Regards,
> Graham


-- 
Ted Husted,
Struts in Action <http://husted.com/struts/book.html>



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Re: [PROPOSAL] Wildcard-matched actions

Posted by Graham Leggett <mi...@sharp.fm>.
Don Brown wrote:

> Perhaps now that 1.1 is final, this would be a good time to bring this up.
> I've written a small extension to Struts that allows action mappings to
> use wildcards in matching URIs.

I submitted a patch to bugzilla a while back that did prefix matching in 
matching URIs. A config called "foo" could be called, regardless of 
whether it was accessed as "/bar/foo", or "/fred/foo". Very useful for 
standard functionality that is reused in a site, such as a login form. 
We've been using it for a while, and it works great.

Wildcard matching would also be really useful.

Regards,
Graham
-- 
-----------------------------------------
minfrin@sharp.fm		"There's a moon
					over Bourbon Street
						tonight..."


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Re: [PROPOSAL] Wildcard-matched actions

Posted by Don Brown <mr...@twdata.org>.
And I forgot to mention, when using the wildcard matcher, only action mappings 
that actually contain wildcards will be tested.

Don

On Saturday 05 July 2003 01:18 pm, Don Brown wrote:
> Actually, the way I wrote the code, wildcards are only matched if an exact
> match cannot be found but before the "unknown" action mapping is executed.
> So, there is no performance penalty for existing applications that use
> specific matchings.  The order:
>
>  - Try to find an action mapping that matches the path exactly
>  - Try to find an action mapping using wildcard matching
>  - Try to locate the mapping for "unknown" paths
>
> Don
>
> On Saturday 05 July 2003 08:31 am, Craig R. McClanahan wrote:
> > On Sat, 5 Jul 2003, Niall Pemberton wrote:
> > > Date: Sat, 5 Jul 2003 01:32:45 +0100
> > > From: Niall Pemberton <ni...@blueyonder.co.uk>
> > > Reply-To: Struts Developers List <st...@jakarta.apache.org>
> > > To: Struts Developers List <st...@jakarta.apache.org>
> > > Subject: Re: [PROPOSAL] Wildcard-matched actions
> > >
> > > I like it.
> > >
> > > Perhaps you should create an enhancement request in bugzilla and attach
> > > a patch with your code.
> >
> > The idea makes some sense, and gets us more towards a general purpose
> > "site map" approach to mapping arbitrary URLs to arbitrary actions.  My
> > one concern will be performance related, since this kind of matching will
> > be slower than the existing approach.  This could perhaps be alleviated
> > by having a per-module-setting (or some smart initialization code) that
> > only used the wildcard matching code if the module actually has some
> > actions that need it, and uses the optimized version otherwise.
> >
> > > Niall
> >
> > Craig
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Re: [PROPOSAL] Wildcard-matched actions

Posted by Don Brown <mr...@twdata.org>.
Actually, the way I wrote the code, wildcards are only matched if an exact 
match cannot be found but before the "unknown" action mapping is executed.  
So, there is no performance penalty for existing applications that use 
specific matchings.  The order:

 - Try to find an action mapping that matches the path exactly
 - Try to find an action mapping using wildcard matching
 - Try to locate the mapping for "unknown" paths

Don



On Saturday 05 July 2003 08:31 am, Craig R. McClanahan wrote:
> On Sat, 5 Jul 2003, Niall Pemberton wrote:
> > Date: Sat, 5 Jul 2003 01:32:45 +0100
> > From: Niall Pemberton <ni...@blueyonder.co.uk>
> > Reply-To: Struts Developers List <st...@jakarta.apache.org>
> > To: Struts Developers List <st...@jakarta.apache.org>
> > Subject: Re: [PROPOSAL] Wildcard-matched actions
> >
> > I like it.
> >
> > Perhaps you should create an enhancement request in bugzilla and attach a
> > patch with your code.
>
> The idea makes some sense, and gets us more towards a general purpose
> "site map" approach to mapping arbitrary URLs to arbitrary actions.  My
> one concern will be performance related, since this kind of matching will
> be slower than the existing approach.  This could perhaps be alleviated by
> having a per-module-setting (or some smart initialization code) that only
> used the wildcard matching code if the module actually has some actions
> that need it, and uses the optimized version otherwise.
>
> > Niall
>
> Craig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Re: [PROPOSAL] Wildcard-matched actions

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sat, 5 Jul 2003, Niall Pemberton wrote:

> Date: Sat, 5 Jul 2003 01:32:45 +0100
> From: Niall Pemberton <ni...@blueyonder.co.uk>
> Reply-To: Struts Developers List <st...@jakarta.apache.org>
> To: Struts Developers List <st...@jakarta.apache.org>
> Subject: Re: [PROPOSAL] Wildcard-matched actions
>
> I like it.
>
> Perhaps you should create an enhancement request in bugzilla and attach a
> patch with your code.

The idea makes some sense, and gets us more towards a general purpose
"site map" approach to mapping arbitrary URLs to arbitrary actions.  My
one concern will be performance related, since this kind of matching will
be slower than the existing approach.  This could perhaps be alleviated by
having a per-module-setting (or some smart initialization code) that only
used the wildcard matching code if the module actually has some actions
that need it, and uses the optimized version otherwise.

>
> Niall

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Re: [PROPOSAL] Wildcard-matched actions

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
I like it.

Perhaps you should create an enhancement request in bugzilla and attach a
patch with your code.

Niall


----- Original Message ----- 
From: "Don Brown" <mr...@twdata.org>
To: <st...@jakarta.apache.org>
Sent: Monday, June 30, 2003 11:18 PM
Subject: [PROPOSAL] Wildcard-matched actions


> Perhaps now that 1.1 is final, this would be a good time to bring this up.
> I've written a small extension to Struts that allows action mappings to
> use wildcards in matching URIs.  The matched values can then be
> substituted anywhere in the action mapping - similar to how Cocoon
> operates (in fact the wildcard code was copied from Cocoon).  The code
> only affects the processActionMapping method of the RequestProcessor.
>
> Why you ask?
>
>  - Much smaller config files
>  - Use of wildcards encourages more consistency of naming action forms,
> actions, and jsp files.
>  - Allows for noun-based URLs in addition to current verb-based URLS,
> particularly useful in REST-style web services
>  - No performance loss: wildcard matching only occurs when a direct
> mapping for the URI cannot be found
>
> For example:
>
>     <!-- Matches all edit forms -->
>     <action    path="/edit*"
>                type="org.apache.struts.webapp.example.Edit{1}Action"
>           attribute="{1}Form"
>               scope="request"
>            validate="false">
>       <forward name="failure"              path="/mainMenu.jsp"/>
>       <forward name="success"              path="/{1}.jsp"/>
>     </action>
>
> By including this feature directly in Struts, wildcards would be available
> to all Struts applications as opposed to now where wildcard support
> requires a RequestProcessor extension.
>
> For more information:
>
> http://www.twdata.org/struts-wildcard/
>
> Don
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org