You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by zack6849 <za...@zack6849.com> on 2014/11/24 21:05:56 UTC

URL Mapping for filter not the same on tomcat as it is on TomEE?

Hello, i've found some strange issue with the url mapping with tomcat, 
i've tested this on tomcat8 and TomEE, it seems easily reproducable.

I have a Filter listening to requests matching "/uploads/*" (all files 
inside of my uploads directory"

On TomEE, this filter is fired for requests just as one would expect, 
however on tomcat8, it does *not*

Example:

/uploads/test.jpg as a file request, the filter fires on TomEE, but not 
tomcat, same code, only difference being the servlet mapping.

Does anyone know what could be causing this?

Relevant code attached below


    |@WebFilter(urlPatterns = "/uploads/*")||
    ||public class StatisticsFilter implements Filter {||
    |

||

    |    @Override
         public void doFilter(ServletRequest req, ServletResponse resp,
    FilterChain chain) throws IOException, ServletException {
             chain.doFilter(req, resp);
             HttpServletRequest request = (HttpServletRequest) req;
             if (request.getRequestURI() != null) {
                 System.out.println("[STATS] Request was to " +
    request.getRequestURI());
                 Database database = new Database();
                 try {
                     ResultSet count = database.query("SELECT COUNT
    (`url`) as results FROM `requests` WHERE `url` = ?",
    request.getRequestURI());
                     boolean exists = count.getInt("results") > 0;
                     count.close();
                     if (!exists) {
                         database.executeUpdate("INSERT INTO 'requests'
    ('url', 'hits') VALUES (?, ?)", request.getRequestURI(), 0);
                     }
                     database.executeUpdate("UPDATE 'requests' SET
    'hits' = 'hits' + 1 WHERE 'url' = ?", request.getRequestURI());
                     database.closeConnection();
                     System.out.println(String.format("[STATS] [%s]
    Incrementing hits for %s", request.getRemoteAddr(),
    request.getRequestURI()));
                 } catch (SQLException e) {
                     e.printStackTrace();
                 }
             }
         }

         @Override
         public void init(FilterConfig filterConfig) throws
    ServletException {

         }

         @Override
         public void destroy() {

         }

    }|


Re: URL Mapping for filter not the same on tomcat as it is on TomEE?

Posted by Konstantin Kolinko <kn...@gmail.com>.
2014-11-24 23:05 GMT+03:00 zack6849 <za...@zack6849.com>:
> Hello, i've found some strange issue with the url mapping with tomcat, i've
> tested this on tomcat8 and TomEE, it seems easily reproducable.
>
> I have a Filter listening to requests matching "/uploads/*" (all files
> inside of my uploads directory"
>
> On TomEE, this filter is fired for requests just as one would expect,
> however on tomcat8, it does *not*
>
> Example:
>
> /uploads/test.jpg as a file request, the filter fires on TomEE, but not
> tomcat, same code, only difference being the servlet mapping.
>
> Does anyone know what could be causing this?
>
> Relevant code attached below
>
>
>    |@WebFilter(urlPatterns = "/uploads/*")||
>    ||public class StatisticsFilter implements Filter {||

1. What is in your web.xml?
2. Exact versions of Tomcat, Java = ?

(Are annotations processed? It is configurable in web.xml.)

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


Re: URL Mapping for filter not the same on tomcat as it is on TomEE?

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

Zack,

On 11/24/14 3:05 PM, zack6849 wrote:
> Hello, i've found some strange issue with the url mapping with
> tomcat, i've tested this on tomcat8 and TomEE, it seems easily
> reproducable.
> 
> I have a Filter listening to requests matching "/uploads/*" (all
> files inside of my uploads directory"

Note that the url-mapping applies to the URL and has nothing to do
with files. If you happen to have a file in the /uploads directory,
that may cause other behavior to occur, but the filter-mapping only
applies to the URL pattern and doesn't match "files".

> On TomEE, this filter is fired for requests just as one would
> expect, however on tomcat8, it does *not*
> 
> Example:
> 
> /uploads/test.jpg as a file request, the filter fires on TomEE, but
> not tomcat, same code, only difference being the servlet mapping.

So the code is the same, but the servlet mapping is different.

At first, you were talking about Filter mappings and now you are saying:

1. The mapping is for a Servlet
2. The Servlet mapping is "different"

Are the servlet mappings really different? If so, how?

> Does anyone know what could be causing this?

Well, since TomEEE uses Tomcat internally, I would suspect that they
would behave identically in these cases.

When you run under TomEE your Filter fires, and under tomcat it does
not fire? Is anything happening that would cause *another* filter to
fire and stop the request?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUdVXhAAoJEBzwKT+lPKRY2PwP/j83ru6frNeEQ7jEK7hKbclm
SlO9tRn9nMzPEUVZkpb81jmbz8W9LvxPzA1z31UE/Y0IbPH+HzzWPzATmX+nra12
efrzlJvcjYdzwKz7dAN2LpRXPGfZWGPHPtxplmLvc0t0SdKcLOXG54TsKe5969hg
1sGytkuet1fvNKw07dJFK58HR8hFW6EQp4jee2wQz7xJZhrYHrNWsCt7s5EVXhnO
toCGEZsaHSX8GdYLeDXcPd5uXLBUU4VRkR8xK1GXVEkCwb5tyqyS4/GgHukf8PJU
fMlXnyeAbAXAQ3Gf4fzQYXUG98mxG2/hlFbu1ff9sCgpuiBrl28fuarvq6XKWbFB
LfMiS65WR69n/TRo6tVl+L/7GAJ3bxLLVSYscfvQcK9Fn8V13eF/PLPFjeDB+DBS
KQEcSPgYxG8ae/zluENDnuHssBatMMZ8e4fne3OyWuCiITB+KeJeGKuHEZsm7E/s
zNp7EwFVkCy7sG2byoIt7uteQU5k7WXmiLirMJyGDiFdJi9+Zrmp6kXomLLlC82/
6+WJ+5VBZelgQnlWc9zbZ0/k/INp60KGye5WaW+KU2jDkoWjqs+MM16nSY0+Ra1Q
zeomV4CGcwg45N71esLJfNVt95yNRM2wP49BrAivbtWklETnMQHtye32l2D2aX4j
nQuqWX734uA1HuhI8xP0
=5foY
-----END PGP SIGNATURE-----

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