You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Goodenough <da...@btconnect.com> on 2010/08/20 11:40:11 UTC

trouble with url-pattern in a filter-mapping (tomcat 6)

I am trying to configure a filter to handle just requests to a single page 
which for the simplicity I will call page.htm (at the root of my application).

So I created a url-pattern which read:-

<url-pattern>page.htm</url-pattern>

and put it inside my <filter-mapping> tag.

But when I start tomcat6 it throws an exception complaining that this
url-pattern is invalid.

I tried with a leading /, I tried *ge.htm in case it wanted a wildcard in 
there somwhere, but none of them work.

This is in a <webapp version="2.4" if that makes a difference.

David

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: trouble with url-pattern in a filter-mapping (tomcat 6)

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: David Goodenough [mailto:david.goodenough@btconnect.com]
> Subject: Re: trouble with url-pattern in a filter-mapping (tomcat 6)
> 
> seems to me not to allow for anything without either a 
> leading / or a *.

Exactly as required by the spec.  Did you read it?

> SRV.11.2 Specification of Mappings
> In the Web application deployment descriptor, the following syntax is
> used to define
> mappings:
> • A string beginning with a ‘/’ character and ending with a ‘/*’ suffix
> is used for path mapping.
> • A string beginning with a ‘*.’ prefix is used as an extension mapping.
> • A string containing only the ’/’ character indicates the "default"
> servlet of the application. In this case the servlet path is the request
> URI minus the context path and the path info is null.
> • All other strings are used for exact matches only.

Note the last bullet means you must have an _exact_ match with the URL, including the leading '/'.

> Just changing it to a wildcard fixed it.  The only thing I 
> changed was the <uri-pattern> tag, from "page.htm" to "*.htm".

Which means every HTML file you've got will trigger the filter.

 - Chuck



Re: trouble with url-pattern in a filter-mapping (tomcat 6)

Posted by David Goodenough <da...@btconnect.com>.
On Friday 20 August 2010, Christopher Schultz wrote:
> David,
> 
> On 8/20/2010 11:27 AM, David Goodenough wrote:
> > On Friday 20 August 2010, Pid wrote:
> >> The url-pattern must start with a '/' character.
> >> 
> >> Please post the complete application web.xml.
> > 
> > Actually from reading the source the pattern MUST contain a wildcard.
> 
> You must have read it wrong: the spec requires that the followup
> url-patterns be supported:
> 
> "
> SRV.11.2 Specification of Mappings
> In the Web application deployment descriptor, the following syntax is
> used to define
> mappings:
> • A string beginning with a ‘/’ character and ending with a ‘/*’ suffix
> is used for path mapping.
> • A string beginning with a ‘*.’ prefix is used as an extension mapping.
> • A string containing only the ’/’ character indicates the "default"
> servlet of the application. In this case the servlet path is the request
> URI minus the context path and the path info is null.
> • All other strings are used for exact matches only.
> "
> 
> > Simple explicit matches do not work, at least not on 6.0.28.
> 
> That would be a horrible bug.
Well the validate routine seems to exhibit the bug.

   private boolean validateURLPattern(String urlPattern) {

        if (urlPattern == null)
            return (false);
        if (urlPattern.indexOf('\n') >= 0 || urlPattern.indexOf('\r') >= 0) {
            return (false);
        }
        if (urlPattern.startsWith("*.")) {
            if (urlPattern.indexOf('/') < 0) {
                checkUnusualURLPattern(urlPattern);
                return (true);
            } else
                return (false);
        }
        if ( (urlPattern.startsWith("/")) &&
                (urlPattern.indexOf("*.") < 0)) {
            checkUnusualURLPattern(urlPattern);
            return (true);
        } else
            return (false);

    }

seems to me not to allow for anything without either a leading / or
a *.  checkUnusualURLPattern does not help either.
> 
> Seriously, can you post your web.xml? You might have something else
> interfering with the mapping.
Just changing it to a wildcard fixed it.  The only thing I changed was the
<uri-pattern> tag, from "page.htm" to "*.htm".
> 
> Also, do you have another component in the environment, such as 
Apache
> httpd?
As Tomcat was throwing exceptions when it loaded the web.xml 
I doubt the any other component could cause it.  But no, no other 
components, raw Tomat.

David
> 
> -chris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: trouble with url-pattern in a filter-mapping (tomcat 6)

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David,

On 8/20/2010 11:27 AM, David Goodenough wrote:
> On Friday 20 August 2010, Pid wrote:
>>
>> The url-pattern must start with a '/' character.
>>
>> Please post the complete application web.xml.
>>
> Actually from reading the source the pattern MUST contain a wildcard.

You must have read it wrong: the spec requires that the followup
url-patterns be supported:

"
SRV.11.2 Specification of Mappings
In the Web application deployment descriptor, the following syntax is
used to define
mappings:
• A string beginning with a ‘/’ character and ending with a ‘/*’ suffix
is used for path mapping.
• A string beginning with a ‘*.’ prefix is used as an extension mapping.
• A string containing only the ’/’ character indicates the "default"
servlet of the application. In this case the servlet path is the request
URI minus the context path and the path info is null.
• All other strings are used for exact matches only.
"

> Simple explicit matches do not work, at least not on 6.0.28.

That would be a horrible bug.

Seriously, can you post your web.xml? You might have something else
interfering with the mapping.

Also, do you have another component in the environment, such as Apache
httpd?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxur78ACgkQ9CaO5/Lv0PC07QCfegMLha/RZXOWQsqhixM6AEvz
pooAn3aoPpwJyEJ9V/oi3beWb4fMbiDg
=pmAQ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: trouble with url-pattern in a filter-mapping (tomcat 6)

Posted by David Goodenough <da...@btconnect.com>.
On Friday 20 August 2010, Pid wrote:
> On 20/08/2010 10:40, David Goodenough wrote:
> > I am trying to configure a filter to handle just requests to a single
> > page which for the simplicity I will call page.htm (at the root of my
> > application).
> > 
> > So I created a url-pattern which read:-
> > 
> > <url-pattern>page.htm</url-pattern>
> > 
> > and put it inside my <filter-mapping> tag.
> > 
> > But when I start tomcat6 it throws an exception complaining that this
> > url-pattern is invalid.
> > 
> > I tried with a leading /, I tried *ge.htm in case it wanted a wildcard in
> > there somwhere, but none of them work.
> > 
> > This is in a <webapp version="2.4" if that makes a difference.
> 
> Tomcat6.0.x?
> 
> The url-pattern must start with a '/' character.
> 
> Please post the complete application web.xml.
> 
> 
> p
Actually from reading the source the pattern MUST contain a wildcard.
Simple explicit matches do not work, at least not on 6.0.28.  

David
> 
> > David
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: trouble with url-pattern in a filter-mapping (tomcat 6)

Posted by Pid <pi...@pidster.com>.
On 20/08/2010 10:40, David Goodenough wrote:
> I am trying to configure a filter to handle just requests to a single page 
> which for the simplicity I will call page.htm (at the root of my application).
> 
> So I created a url-pattern which read:-
> 
> <url-pattern>page.htm</url-pattern>
> 
> and put it inside my <filter-mapping> tag.
> 
> But when I start tomcat6 it throws an exception complaining that this
> url-pattern is invalid.
> 
> I tried with a leading /, I tried *ge.htm in case it wanted a wildcard in 
> there somwhere, but none of them work.
> 
> This is in a <webapp version="2.4" if that makes a difference.

Tomcat6.0.x?

The url-pattern must start with a '/' character.

Please post the complete application web.xml.


p

> David
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>