• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Global Filter for All Web Applications

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there ,

i was just wondering , how do i use a custom filter for all web applications and not for a specific webapp ?

i have edited the conf\web.xml just like a normal web.xml .
but i have no clue where to put the classes\filters\*.java,class files . because normally it will be under WEB-INF\classes\filters
so i tried putting the files in every possible folder under conf folder , still doesnt work .

any ideas please ?

 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't try to do run-time sharing. At build time, give the jar file to each web app.
 
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this is something that you need done for all web apps, AND if you know that you will be using Tomcat for the foreseeable future, then writing a Tomcat Valve -instead of a servlet filter- might be a better solution.
 
shaki shabez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Don't try to do run-time sharing. At build time, give the jar file to each web app.



it should run on the server as a global filter , the idea is making it a global filter to all webapps without interfering with the webapps .

If this is something that you need done for all web apps, AND if you know that you will be using Tomcat for the foreseeable future, then writing a Tomcat Valve -instead of a servlet filter- might be a better solution.



yes i have read the some guides about valves and filters , the problem is that the filter already been implemented as a class that extends Filter class
and it shouldnt be change .



thanks for both answers ,
can you think of a way on running a filter on a all web apps with just messing around with the conf\web.xml file ?
 
Tim Moores
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Changing something without changing something (either the config files or the Java class) will be difficult :-)
 
shaki shabez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Changing something without changing something (either the config files or the Java class) will be difficult :-)



ah theres no problem changing the conf\web.xml file , just cant change each web.xml for each web app .


maybe if i clarify what are my intentions , then maybe you can understand better why im asking this .

i want to build a web app , similar to the tomcat "App Manager" . meaning , when ull enter the webapp , you will get a list of all the
webapps on the server , if you will pick one web app , ull get a list of all servlets / JSP is running , each servlet and JSP
ull pick from that list , you will get some stats about that servlet/jsp .

so for conclusion , i want to build a web app which monitors all the web applications on the server , and their servlets / jsp .

im wondering if is it possible to config the confg\web.xml so that my app will run first , and maybe some how configuring myapp\WEB-INF\web.xml
so that my filter will work for all web apps ? maybe if ill use <url-mapping>/*<url-mapping> ?
 
Tim Moores
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you certain that you need to run code as part of the other web apps? Something like http://code.google.com/p/psi-probe/ shows a whole lot of information despite being a separate web app.
 
shaki shabez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Are you certain that you need to run code as part of the other web apps? Something like http://code.google.com/p/psi-probe/ shows a whole lot of information despite being a separate web app.




exactly !
just not the same features as the PSI-Probe , i just need basic monitoring of all requests done on the server .
 
Tim Moores
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe the (Extended) Access Log Valve can do that for you: http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html
 
shaki shabez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Maybe the (Extended) Access Log Valve can do that for you: http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html



i really appreciate the help .
altho , im not seeking for an alternative , i really do whish to use my custom made filter for all web apps , alternative one web app with a filter , to filter requests for all web apps.
 
Tim Moores
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. Have you tried setting up the filter in conf\web.xml ?
 
shaki shabez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:OK. Have you tried setting up the filter in conf\web.xml ?



yes , i have tried this :


but , i dont know where to put the filter files .
or , how to configure the above code to work on a filter on a specific web app .

i tried creating conf\classes\filters , and to put the files there , but it wont work . nither does putting the files under conf dir .

 
Tim Moores
Saloon Keeper
Posts: 7590
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The class files must be somewhere where Tomcat can find them - for example, in TOMCAT_HOME/lib in a jar file. You can't just create directories and expect Tomcat to include those in its classpath.

how to configure the above code to work on a filter on a specific web app


I thought the whole point was to use these classes for *all* web apps? If you need to do app-specific setup then you might as well include the filter in each web-xml file.
 
shaki shabez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
**EDIT :


The class files must be somewhere where Tomcat can find them - for example, in TOMCAT_HOME/lib in a jar file. You can't just create directories and expect Tomcat to include those in its classpath.



okie , apparently the server crashed or something i dont know . it seems that it wouldnt run at all .
i reinstalled the apache server , and now everything works including the filter .


altho i have just one little bug , i dont know if its my filter or just configuration problem .
when i try localhost:8080 , i can see my filter proccessing the request and finishing it . but i get a blank page instead of the tomcat home page .
and if i try localhost:8080/manager for instance .. then everything works as it should be , including my filter .

and idea ?
 
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Tomcat Manager app isn't some sort of magical construct that stomps on the J2EE spec and expects everything to work its way just because it doesn't want to do things the right way.

The Tomcat Manager app is, in fact, a perfectly normal J2EE-compliant webapp. The only difference between it and any other webapp is that it queries the Tomcat server's internal monitoring and control facilities, which themselves are J2EE and/or JRE compliant resources.

There are at least 2 ways to introspect Tomcat: The Management EJB (MEJB) and Java Management Extensions (JMX). In point of fact, there are more than 2 ways - maybe even more than 5 ways, depending on what you want to monitor. Stuff like the JSR-88 API.

None of these services require abnormal patches into Tomcat's internals, warping standard processes, misuse of classpaths or other arcane and over-complex attempts to create something that can break anytime a new Tomcat release comes out.
 
This tiny ad is suggesting that maybe she should go play in traffic.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic