You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Pradyut Bhattacharya <go...@outlook.in> on 2015/10/23 04:39:25 UTC

servlet filter not working over virtual directories in tomcat

Hi,
I  had configured virtual directories in glassfish3.x over which I could write filters.
For an example I could access files at c:/web from http://localhost/TestApp/web over which I could also place a filter at my web app's web/xml file with
<filter-mapping>
    <filter-name>dir_filter</filter-name>
    <url-pattern>/web/*</url-pattern>
</filter-mapping>Unfortunately Tomcat 8.0 is not allowing me to write a filter above that. It simply ignores the filters and shows the content in the web directory.
The problem is anybody can access all of the files in the "web" folder.
Any how can we place filter over the virtual directories.
FYI - i have made the web app named "TestApp" and the virtual config is located at "$tomcat_dir/conf/Catalina/localhost" directory with the file name "TestApp#web.xml" file and having the content<?xml version='1.0' encoding='utf-8'?> 
<Context docBase="C:/web" debug="0" privileged="true"></Context>
The question is also at stackoverflow - http://stackoverflow.com/questions/33290483/servlet-filter-not-working-over-virtual-directories-in-tomcat
Tomcat bugzilla - https://bz.apache.org/bugzilla/show_bug.cgi?id=58523

RegardsPraddy, India 		 	   		  

Re: servlet filter not working over virtual directories in tomcat

Posted by "André Warnier (tomcat)" <aw...@ice-sa.com>.
On 24.10.2015 05:11, Pradyut Bhattacharya wrote:

> The URL
pattern therefore needs to be "/*"

> Could not do anything with the above statement. May be an example could suffice.

Then maybe try this :

Instead of :

  <filter-mapping>
      <filter-name>dir_filter</filter-name>
      <url-pattern>/web/*</url-pattern>
</filter-mapping>

try :

  <filter-mapping>
      <filter-name>dir_filter</filter-name>
      <url-pattern>/*</url-pattern>
</filter-mapping>

Explanation : in <servlet-mapping> and <filter-mapping>, the <url-pattern> is *relative to 
the webapp context*. In your case, because of the way you have configured this, the webapp 
has a context of "/TestApp/web". Therefore, if you want the filter to apply to everything 
under "/TestApp/web", you have to map it to "/*".
So that, in URL-space, it will apply to "/TestApp/web/*".

The way you originally mapped it above, it would apply to "/TestApp/web/web/*", which is 
why it seemed not to be working.  The filter was there, but never invoked, because there 
was never any request URL matching "/TestApp/web/web/*".

Clearer ?

Note that this is the same as what Mark was saying, only in many more words.




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


RE: servlet filter not working over virtual directories in tomcat

Posted by Pradyut Bhattacharya <go...@outlook.in>.
Thank you Mark for replying. 


 


> The URL
pattern therefore needs to be "/*"


 


Could not do anything with the above statement. May be an example could suffice.


 


Somehow could see an example for PreResources in the internet and this is
how I did it without an TestApp#web.xml file in the Catalina/localhost folder.


 


<Context antiJARLocking="true"
path="/TestApp">


   
<Resources
className="org.apache.catalina.webresources.StandardRoot">


        <PreResources
className="org.apache.catalina.webresources.DirResourceSet"


            base="C:\\dir"


            internalPath="/"


            webAppMount="/web" />


   
</Resources>


</Context>


This works fine with filters.


 


Regards,


Pradyut

> Subject: Re: servlet filter not working over virtual directories in tomcat
> To: users@tomcat.apache.org
> From: markt@apache.org
> Date: Fri, 23 Oct 2015 08:15:09 +0100
> 
> On 23/10/2015 03:39, Pradyut Bhattacharya wrote:
> > Hi,
> > I  had configured virtual directories in glassfish3.x over which I could write filters.
> > For an example I could access files at c:/web from http://localhost/TestApp/web over which I could also place a filter at my web app's web/xml file with
> > <filter-mapping>
> >     <filter-name>dir_filter</filter-name>
> >     <url-pattern>/web/*</url-pattern>
> > </filter-mapping>Unfortunately Tomcat 8.0 is not allowing me to write a filter above that. It simply ignores the filters and shows the content in the web directory.
> > The problem is anybody can access all of the files in the "web" folder.
> > Any how can we place filter over the virtual directories.
> > FYI - i have made the web app named "TestApp" and the virtual config is located at "$tomcat_dir/conf/Catalina/localhost" directory with the file name "TestApp#web.xml" file and having the content<?xml version='1.0' encoding='utf-8'?> 
> > <Context docBase="C:/web" debug="0" privileged="true"></Context>
> > The question is also at stackoverflow - http://stackoverflow.com/questions/33290483/servlet-filter-not-working-over-virtual-directories-in-tomcat
> > Tomcat bugzilla - https://bz.apache.org/bugzilla/show_bug.cgi?id=58523
> 
> Tomcat is doing exactly what you have configured it to do. There is no
> Tomcat bug here, just user error.
> 
> With a context.xml file named TestApp#web.xml you have a defined a new
> web application with a context path of "/TestApp/web" and a docBase of
> "C:\web"
> 
> The URL pattern therefore needs to be "/*"
> 
> If you want to mount "C:\web" inside an existing web application using
> the path "/web" then you need to define a PreResources or PostResources
> element using the org.apache.catalina.webresources.DirResourceSet
> implementation. See
> http://tomcat.apache.org/tomcat-8.0-doc/config/resources.html for more
> details.
> 
> Mark
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

Re: servlet filter not working over virtual directories in tomcat

Posted by Mark Thomas <ma...@apache.org>.
On 23/10/2015 03:39, Pradyut Bhattacharya wrote:
> Hi,
> I  had configured virtual directories in glassfish3.x over which I could write filters.
> For an example I could access files at c:/web from http://localhost/TestApp/web over which I could also place a filter at my web app's web/xml file with
> <filter-mapping>
>     <filter-name>dir_filter</filter-name>
>     <url-pattern>/web/*</url-pattern>
> </filter-mapping>Unfortunately Tomcat 8.0 is not allowing me to write a filter above that. It simply ignores the filters and shows the content in the web directory.
> The problem is anybody can access all of the files in the "web" folder.
> Any how can we place filter over the virtual directories.
> FYI - i have made the web app named "TestApp" and the virtual config is located at "$tomcat_dir/conf/Catalina/localhost" directory with the file name "TestApp#web.xml" file and having the content<?xml version='1.0' encoding='utf-8'?> 
> <Context docBase="C:/web" debug="0" privileged="true"></Context>
> The question is also at stackoverflow - http://stackoverflow.com/questions/33290483/servlet-filter-not-working-over-virtual-directories-in-tomcat
> Tomcat bugzilla - https://bz.apache.org/bugzilla/show_bug.cgi?id=58523

Tomcat is doing exactly what you have configured it to do. There is no
Tomcat bug here, just user error.

With a context.xml file named TestApp#web.xml you have a defined a new
web application with a context path of "/TestApp/web" and a docBase of
"C:\web"

The URL pattern therefore needs to be "/*"

If you want to mount "C:\web" inside an existing web application using
the path "/web" then you need to define a PreResources or PostResources
element using the org.apache.catalina.webresources.DirResourceSet
implementation. See
http://tomcat.apache.org/tomcat-8.0-doc/config/resources.html for more
details.

Mark

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