You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Howard Lewis Ship <hl...@gmail.com> on 2011/04/04 19:29:26 UTC

Index vs. invalid path

Just had a thought (hopefully original) about dealing with the issue
of Index pages and bad paths.

This comes up with Tapestry often enough; an errant entry in a CSS
file, or a manually mangled URL, and an Index page is activated with
an invalid page activation context, resulting in an exception.

But it just occurred to me that in most cases, we will know what the
page activation context will look like (for example, a series of
digits is most likely) ... something that can be expressed as a
regular expression.

So how about something like:

@MatchExtraPath("\\d+")
public class Index
{
}

This would identify the page activation context (the extra path) as
needed to match the pattern \d+  (a series of at least one digit).

So, once the page is identified, the PageDispatcher (contributed to
the MasterDispatcher chain of command) can examine the page to see if
it has the @MatchExtraPath and, if so, continue searching if the extra
path does not match.

-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: Index vs. invalid path

Posted by Massimo Lusetti <ml...@gmail.com>.
On Wed, Apr 6, 2011 at 7:02 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> But what is the definition of "matched"?  Without significant changes
> to some public APIs to allow ValueEncoders to describe what they match
> OR a brute force approach of catching exceptions as indicators of a
> non-match we are left with only what the current APIs can do: match on
> the NUMBER of page activation context values present in the extra
> path.

I simply thought about it as: check if there's a matching activation
event handler method, if not it simply matter that it isn't a request
for that page so a 404 should come up.
And I'll go with what the ValueEncoders can do now without adding any
extra notions to it, the current API is sufficient IMHO, I value a bad
practice to overload a page with too much activation contexts which a
dramatically different.

Cheers.
-- 
Massimo
http://meridio.blogspot.com

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


Re: Index vs. invalid path

Posted by Howard Lewis Ship <hl...@gmail.com>.
But what is the definition of "matched"?  Without significant changes
to some public APIs to allow ValueEncoders to describe what they match
OR a brute force approach of catching exceptions as indicators of a
non-match we are left with only what the current APIs can do: match on
the NUMBER of page activation context values present in the extra
path.

On Wed, Apr 6, 2011 at 1:45 AM, Massimo Lusetti <ml...@gmail.com> wrote:
> On Mon, Apr 4, 2011 at 10:08 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
>
>> But a no-args activation method will still be a failure, and result in
>> HTML content (from the page, or from the exception page) being
>> streamed to the client instead of the requested content. We really
>> want to get a 404 down to the client, and the best way to do that is
>> to have the PageDispatcher return false (rather than process the
>> request and return true).
>
> To me the "correct" behavior is that if no activation context is
> matched a 404 error should be sent to the client. That's the current
> and actual behavior every web server out there produce in the case of
> a request to a resource not available.
>
> So I'm prone with the Igor idea and definitely would extend it to a
> default: If no activation context is matched a 404 error is thrown to
> the client, if a developer need to deal with various heterogeneous
> situation he could use EventContext or put a lot of different handler
> methods...
>
> Please don't add knowledge where not necessary.
>
> Cheers
> --
> Massimo
> http://meridio.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: Index vs. invalid path

Posted by Massimo Lusetti <ml...@gmail.com>.
On Mon, Apr 4, 2011 at 10:08 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> But a no-args activation method will still be a failure, and result in
> HTML content (from the page, or from the exception page) being
> streamed to the client instead of the requested content. We really
> want to get a 404 down to the client, and the best way to do that is
> to have the PageDispatcher return false (rather than process the
> request and return true).

To me the "correct" behavior is that if no activation context is
matched a 404 error should be sent to the client. That's the current
and actual behavior every web server out there produce in the case of
a request to a resource not available.

So I'm prone with the Igor idea and definitely would extend it to a
default: If no activation context is matched a 404 error is thrown to
the client, if a developer need to deal with various heterogeneous
situation he could use EventContext or put a lot of different handler
methods...

Please don't add knowledge where not necessary.

Cheers
-- 
Massimo
http://meridio.blogspot.com

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


Re: Index vs. invalid path

Posted by Howard Lewis Ship <hl...@gmail.com>.
But a no-args activation method will still be a failure, and result in
HTML content (from the page, or from the exception page) being
streamed to the client instead of the requested content. We really
want to get a 404 down to the client, and the best way to do that is
to have the PageDispatcher return false (rather than process the
request and return true).

On Mon, Apr 4, 2011 at 1:05 PM, Igor Drobiazko <ig...@gmail.com> wrote:
> What about @IgnoreInvalidContext anntation instead of @MatchExtraPath?
> Wouldn't it do the job? If the context is invalid, we check if
> @IgnoreInvalidContext is present. If so, the exception is caught and no-args
> activation method is invoked.
>
> On Mon, Apr 4, 2011 at 10:02 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
>
>> I think we're definitely seeing some different concerns within
>> Tapestry conflicting with each other.
>>
>> On Mon, Apr 4, 2011 at 12:47 PM, Igor Drobiazko
>> <ig...@gmail.com> wrote:
>> > Tapestry is known for taking over the plumbing work and this solution
>> > somehow goes against this philosophy. In most cases a user don't have to
>> > know how the context value is converted from string to a server-side
>> object
>> > and vice versa. Providing @MetchExtraPath annotationthe user adds some
>> kind
>> > of redundancy.
>> >
>> > On Mon, Apr 4, 2011 at 7:29 PM, Howard Lewis Ship <hl...@gmail.com>
>> wrote:
>> >
>> >> Just had a thought (hopefully original) about dealing with the issue
>> >> of Index pages and bad paths.
>> >>
>> >> This comes up with Tapestry often enough; an errant entry in a CSS
>> >> file, or a manually mangled URL, and an Index page is activated with
>> >> an invalid page activation context, resulting in an exception.
>> >>
>> >> But it just occurred to me that in most cases, we will know what the
>> >> page activation context will look like (for example, a series of
>> >> digits is most likely) ... something that can be expressed as a
>> >> regular expression.
>> >>
>> >> So how about something like:
>> >>
>> >> @MatchExtraPath("\\d+")
>> >> public class Index
>> >> {
>> >> }
>> >>
>> >> This would identify the page activation context (the extra path) as
>> >> needed to match the pattern \d+  (a series of at least one digit).
>> >>
>> >> So, once the page is identified, the PageDispatcher (contributed to
>> >> the MasterDispatcher chain of command) can examine the page to see if
>> >> it has the @MatchExtraPath and, if so, continue searching if the extra
>> >> path does not match.
>> >>
>> >> --
>> >> Howard M. Lewis Ship
>> >>
>> >> Creator of Apache Tapestry
>> >>
>> >> The source for Tapestry training, mentoring and support. Contact me to
>> >> learn how I can get you up and productive in Tapestry fast!
>> >>
>> >> (971) 678-5210
>> >> http://howardlewisship.com
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
>> >> For additional commands, e-mail: dev-help@tapestry.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > Best regards,
>> >
>> > Igor Drobiazko
>> > http://tapestry5.de
>> >
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>>
>> The source for Tapestry training, mentoring and support. Contact me to
>> learn how I can get you up and productive in Tapestry fast!
>>
>> (971) 678-5210
>> http://howardlewisship.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: dev-help@tapestry.apache.org
>>
>>
>
>
> --
> Best regards,
>
> Igor Drobiazko
> http://tapestry5.de
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: Index vs. invalid path

Posted by Igor Drobiazko <ig...@gmail.com>.
What about @IgnoreInvalidContext anntation instead of @MatchExtraPath?
Wouldn't it do the job? If the context is invalid, we check if
@IgnoreInvalidContext is present. If so, the exception is caught and no-args
activation method is invoked.

On Mon, Apr 4, 2011 at 10:02 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> I think we're definitely seeing some different concerns within
> Tapestry conflicting with each other.
>
> On Mon, Apr 4, 2011 at 12:47 PM, Igor Drobiazko
> <ig...@gmail.com> wrote:
> > Tapestry is known for taking over the plumbing work and this solution
> > somehow goes against this philosophy. In most cases a user don't have to
> > know how the context value is converted from string to a server-side
> object
> > and vice versa. Providing @MetchExtraPath annotationthe user adds some
> kind
> > of redundancy.
> >
> > On Mon, Apr 4, 2011 at 7:29 PM, Howard Lewis Ship <hl...@gmail.com>
> wrote:
> >
> >> Just had a thought (hopefully original) about dealing with the issue
> >> of Index pages and bad paths.
> >>
> >> This comes up with Tapestry often enough; an errant entry in a CSS
> >> file, or a manually mangled URL, and an Index page is activated with
> >> an invalid page activation context, resulting in an exception.
> >>
> >> But it just occurred to me that in most cases, we will know what the
> >> page activation context will look like (for example, a series of
> >> digits is most likely) ... something that can be expressed as a
> >> regular expression.
> >>
> >> So how about something like:
> >>
> >> @MatchExtraPath("\\d+")
> >> public class Index
> >> {
> >> }
> >>
> >> This would identify the page activation context (the extra path) as
> >> needed to match the pattern \d+  (a series of at least one digit).
> >>
> >> So, once the page is identified, the PageDispatcher (contributed to
> >> the MasterDispatcher chain of command) can examine the page to see if
> >> it has the @MatchExtraPath and, if so, continue searching if the extra
> >> path does not match.
> >>
> >> --
> >> Howard M. Lewis Ship
> >>
> >> Creator of Apache Tapestry
> >>
> >> The source for Tapestry training, mentoring and support. Contact me to
> >> learn how I can get you up and productive in Tapestry fast!
> >>
> >> (971) 678-5210
> >> http://howardlewisship.com
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: dev-help@tapestry.apache.org
> >>
> >>
> >
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
> > http://tapestry5.de
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Index vs. invalid path

Posted by Howard Lewis Ship <hl...@gmail.com>.
I think we're definitely seeing some different concerns within
Tapestry conflicting with each other.

On Mon, Apr 4, 2011 at 12:47 PM, Igor Drobiazko
<ig...@gmail.com> wrote:
> Tapestry is known for taking over the plumbing work and this solution
> somehow goes against this philosophy. In most cases a user don't have to
> know how the context value is converted from string to a server-side object
> and vice versa. Providing @MetchExtraPath annotationthe user adds some kind
> of redundancy.
>
> On Mon, Apr 4, 2011 at 7:29 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
>
>> Just had a thought (hopefully original) about dealing with the issue
>> of Index pages and bad paths.
>>
>> This comes up with Tapestry often enough; an errant entry in a CSS
>> file, or a manually mangled URL, and an Index page is activated with
>> an invalid page activation context, resulting in an exception.
>>
>> But it just occurred to me that in most cases, we will know what the
>> page activation context will look like (for example, a series of
>> digits is most likely) ... something that can be expressed as a
>> regular expression.
>>
>> So how about something like:
>>
>> @MatchExtraPath("\\d+")
>> public class Index
>> {
>> }
>>
>> This would identify the page activation context (the extra path) as
>> needed to match the pattern \d+  (a series of at least one digit).
>>
>> So, once the page is identified, the PageDispatcher (contributed to
>> the MasterDispatcher chain of command) can examine the page to see if
>> it has the @MatchExtraPath and, if so, continue searching if the extra
>> path does not match.
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>>
>> The source for Tapestry training, mentoring and support. Contact me to
>> learn how I can get you up and productive in Tapestry fast!
>>
>> (971) 678-5210
>> http://howardlewisship.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: dev-help@tapestry.apache.org
>>
>>
>
>
> --
> Best regards,
>
> Igor Drobiazko
> http://tapestry5.de
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: Index vs. invalid path

Posted by Igor Drobiazko <ig...@gmail.com>.
Tapestry is known for taking over the plumbing work and this solution
somehow goes against this philosophy. In most cases a user don't have to
know how the context value is converted from string to a server-side object
and vice versa. Providing @MetchExtraPath annotationthe user adds some kind
of redundancy.

On Mon, Apr 4, 2011 at 7:29 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> Just had a thought (hopefully original) about dealing with the issue
> of Index pages and bad paths.
>
> This comes up with Tapestry often enough; an errant entry in a CSS
> file, or a manually mangled URL, and an Index page is activated with
> an invalid page activation context, resulting in an exception.
>
> But it just occurred to me that in most cases, we will know what the
> page activation context will look like (for example, a series of
> digits is most likely) ... something that can be expressed as a
> regular expression.
>
> So how about something like:
>
> @MatchExtraPath("\\d+")
> public class Index
> {
> }
>
> This would identify the page activation context (the extra path) as
> needed to match the pattern \d+  (a series of at least one digit).
>
> So, once the page is identified, the PageDispatcher (contributed to
> the MasterDispatcher chain of command) can examine the page to see if
> it has the @MatchExtraPath and, if so, continue searching if the extra
> path does not match.
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Index vs. invalid path

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 04 Apr 2011 18:46:05 -0300, Josh Canfield <jo...@gmail.com>  
wrote:

> Thiago,
>>> I prefer another approach: according to my experience, it's rare to  
>>> have an
>>> Index page with activation context parameters.
>
> This is a little presumptuous. I have built a couple apps where I use
> the index page activation parameters to pull html content from a
> database.

So I guess we can provide a mixin and/or annotation that returns a 404  
when the activation context is not empty and let developers decide when  
and where to use it. I agree that we cannot make any good guesses for this  
scenario, so lets just provide a tool and document it.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Index vs. invalid path

Posted by Josh Canfield <jo...@gmail.com>.
Thiago,
>> I prefer another approach: according to my experience, it's rare to have an
>> Index page with activation context parameters.

This is a little presumptuous. I have built a couple apps where I use
the index page activation parameters to pull html content from a
database.

> The typical URL will be
> "/user/12345" but an errant CSS rule or relative URL to an image can
> result in "/user/images/icon.png" and a NumericFormatException trying
> to convert "images" to a Long (before accessing the User).

I haven't done the due diligence to know if it would be an easy matter
to simply return a 404 at the point we realize the types don't match,
but doesn't that seem like reasonable default behavior? In
non-production mode we can still return a useful body explaining what
happened. In production mode we give a standard "not found" body.

Josh

On Mon, Apr 4, 2011 at 1:04 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
> On Mon, Apr 4, 2011 at 12:08 PM, Thiago H. de Paula Figueiredo
> <th...@gmail.com> wrote:
>> On Mon, 04 Apr 2011 14:29:26 -0300, Howard Lewis Ship <hl...@gmail.com>
>> wrote:
>>
>>> @MatchExtraPath("\\d+")
>>> public class Index
>>> {
>>> }
>>
>> I prefer another approach: according to my experience, it's rare to have an
>> Index page with activation context parameters. Thus, I think we can create a
>> mixin that raises a 404 when page activation context is not empty,
>> automatically apply it to all Index pages and have a configuration symbol to
>> configure this, most probably with a false default value to provide
>> backwards compatibility.
>
> This may be true at the root level, but I often create index pages in
> subpackages for this purpose, i.e. root.pages.user.UserIndex that has
> a page activation context that's a user id.  The typical URL will be
> "/user/12345" but an errant CSS rule or relative URL to an image can
> result in "/user/images/icon.png" and a NumericFormatException trying
> to convert "images" to a Long (before accessing the User).
>
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
>> instructor
>> Owner, Ars Machina Tecnologia da Informação Ltda.
>> http://www.arsmachina.com.br
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: dev-help@tapestry.apache.org
>>
>>
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>

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


Re: Index vs. invalid path

Posted by Howard Lewis Ship <hl...@gmail.com>.
On Mon, Apr 4, 2011 at 12:08 PM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> On Mon, 04 Apr 2011 14:29:26 -0300, Howard Lewis Ship <hl...@gmail.com>
> wrote:
>
>> @MatchExtraPath("\\d+")
>> public class Index
>> {
>> }
>
> I prefer another approach: according to my experience, it's rare to have an
> Index page with activation context parameters. Thus, I think we can create a
> mixin that raises a 404 when page activation context is not empty,
> automatically apply it to all Index pages and have a configuration symbol to
> configure this, most probably with a false default value to provide
> backwards compatibility.

This may be true at the root level, but I often create index pages in
subpackages for this purpose, i.e. root.pages.user.UserIndex that has
a page activation context that's a user id.  The typical URL will be
"/user/12345" but an errant CSS rule or relative URL to an image can
result in "/user/images/icon.png" and a NumericFormatException trying
to convert "images" to a Long (before accessing the User).

>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
> instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: Index vs. invalid path

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 04 Apr 2011 14:29:26 -0300, Howard Lewis Ship <hl...@gmail.com>  
wrote:

> @MatchExtraPath("\\d+")
> public class Index
> {
> }

I prefer another approach: according to my experience, it's rare to have  
an Index page with activation context parameters. Thus, I think we can  
create a mixin that raises a 404 when page activation context is not  
empty, automatically apply it to all Index pages and have a configuration  
symbol to configure this, most probably with a false default value to  
provide backwards compatibility.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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