Discussions

General J2EE: how to make a filter intercept request to all webapp in a server

  1. Hi there,

    I need to install a filter(javax.servlet.Filter) that intercepts http requests to any web application installed in a web server...there is a way to make that???

    I mean if client query http://server:port/webapp1/... or http://server:port/webapp2/... the filter has to be executed

    Thanks in advance...

    Threaded Messages (5)

  2. Not that I know of[ Go to top ]

    I don't think that is possible using standard J2EE features. Perhaps your application / web server has some features for that? I think Jetty has, but they won't be standard functions, meaning they won't be portable across app/web servers.

    Anyone else knows more about this?
  3. You should be able to with Tomcat[ Go to top ]

    In Tomcat, applications are configured by the global web.xml file followed by the app-specific one in WEB-INF. So, if you go to <TOMCAT_HOME>/conf/web.xml and add the following as the first child of the web-app element, it should work for all web apps:

      <filter>
         <filter-name>My Filter</filter-name>
         <filter-class>blah.blah.filter.MyFilter</filter-class>
      </filter>
      
      <filter-mapping>
         <filter-name>My Filter</filter-name>
         <url-pattern>/*</url-pattern>
      </filter-mapping>
  4. You should be able to with Tomcat[ Go to top ]

    But in production we are using WAS, there is a way?? :(

    Thanks!!
  5. I don't know WAS, but whatever you would have to do would be different than Tomcat.

    You might be best off defining the filter in each application's web.xml individually, so that it will be portable.
  6. Forgive me - just a test[ Go to top ]

    Sorry all, this is just a test.