Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Global ServletFilter
Global ServletFilter [message #956505] Wed, 24 October 2012 11:13 Go to next message
Johan Eriksson is currently offline Johan Eriksson
Messages: 19
Registered: May 2012
Junior Member
I have an application with a number of web-bundles. I would like to install a global servlet-filter (i.e. one that intercepts requests to all bundles).

How would I do this ? Excuse me if this is stated in the documentation - I couldn't find it.

Thanks,

/Johan/
Re: Global ServletFilter [message #956527 is a reply to message #956505] Wed, 24 October 2012 11:34 Go to previous messageGo to next message
Violeta Georgieva is currently offline Violeta Georgieva
Messages: 214
Registered: October 2010
Senior Member
Hi,

If you are using Virgo Server for Apache Tomcat then:
1. Go to <VIRGO-HOME>/repository/ext/
2. Open org.eclipse.gemini.web.tomcat... jar file
3. The default web.xml is in 'conf' folder
4. Copy this file and paste it in <VIRGO-HOME>/configuration folder
5. Nest time when you start Virgo it will use the default web.xml from the configuration folder



Regards
Violeta
Re: Global ServletFilter [message #986956 is a reply to message #956527] Thu, 22 November 2012 09:22 Go to previous messageGo to next message
Johan Eriksson is currently offline Johan Eriksson
Messages: 19
Registered: May 2012
Junior Member
Thanks for your answer Violeta, this sounds easy enough.

A couple of questions though:

How would I deploy my filter ? Can I just drop in a bundle in the usr-repository ? And I would be able to get hold of the BundleContext for the filter via the ServletContext and/or via FrameworkUtil ?

Re: Global ServletFilter [message #986962 is a reply to message #956527] Thu, 22 November 2012 10:09 Go to previous messageGo to next message
attila Mising name is currently offline attila Mising name
Messages: 45
Registered: April 2010
Member
Doesn't seem to work with Virgo 3.5.0.RELEASE -> VTS
The default VIRGO_HOME/configuration/web.xml is ignored.
Is there any other setting necessary for this ?

Note : tomcat-server.xml is in the same folder
Re: Global ServletFilter [message #987040 is a reply to message #986962] Fri, 23 November 2012 01:37 Go to previous messageGo to next message
Tin N/A is currently offline Tin N/A
Messages: 46
Registered: December 2010
Member
If you're using Virgo Tomcat server, the most comprehensive solution is to write a Valve. Valves are configured in server.xml, but you'll probably need to put the code in an OSGi fragment that attaches to Tomcat's bundle, otherwise it won't be able to find it when it's initializing. Not sure which bundle you need to attach to, Violeta might know, or you may just configure the valve and see which bundle bombs when Tomcat is initialized Very Happy
Re: Global ServletFilter [message #987044 is a reply to message #987040] Fri, 23 November 2012 02:35 Go to previous messageGo to next message
attila Mising name is currently offline attila Mising name
Messages: 45
Registered: April 2010
Member
Thank you for the hint, however the point is the default web.xml approach.
Possibility for the customer to configure stuff like server level session timeout, some cache-control filters [using the plain tomcat expiry filter] and alike.
Re: Global ServletFilter [message #987236 is a reply to message #987044] Sat, 24 November 2012 16:48 Go to previous messageGo to next message
Violeta Georgieva is currently offline Violeta Georgieva
Messages: 214
Registered: October 2010
Senior Member
Hi,

Here is what I did (the bundle that provides the global filter is attached):


  • Downloaded Virgo Server for Apache Tomcat version 3.5.0.RELEASE
  • Put in <Virgo-Home>/configuration folder the default web.xml extracted from org.eclipse.gemini.web.tomcat... bundle that is placed in <Virgo-Home>/repository/ext folder
  • Put filter definition in default web.xml

  <filter>
  	<filter-name>GlobalFilter</filter-name>
  	<filter-class>custom.global.filter.GlobalFilter</filter-class>
  </filter>
  <filter-mapping>
  	<filter-name>GlobalFilter</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>


  • Put in <Virgo-Home>/repository/usr folder the attached bundle "custom.glocal.filter.jar"
  • When requesting http://localhost:8080, in the log files there is the following "System.out bundle context: org.eclipse.osgi.framework.internal.core.BundleContextImpl"


Quote:
How would I deploy my filter ? Can I just drop in a bundle in the usr-repository ? And I would be able to get hold of the BundleContext for the filter via the ServletContext and/or via FrameworkUtil ?


The bundle that provides the filter is a fragment bundle attached to com.springsource.org.apache.catalina bundle. It should be placed in <Virgo-Home>/repository/usr folder.
The BundleContext can be obtain via ServletContext. (see attached archive - there are sources also)
(BundleContext) filterConfig.getServletContext().getAttribute("osgi-bundlecontext");


Quote:
Doesn't seem to work with Virgo 3.5.0.RELEASE -> VTS
The default VIRGO_HOME/configuration/web.xml is ignored.
Is there any other setting necessary for this ?


Did you restart the server? Can you try "startup -clean"?

Quote:
If you're using Virgo Tomcat server, the most comprehensive solution is to write a Valve. ... Not sure which bundle you need to attach to, Violeta might know ...


In my work I'm trying to use standard servlet features as much as possible because the servlet API is backwards compatible, so if I can implement something with Filter and Valve then I use Filter.
The bundle must be attached to com.springsource.org.apache.catalina.

Regards
Violeta
Re: Global ServletFilter [message #987551 is a reply to message #987236] Tue, 27 November 2012 01:43 Go to previous messageGo to next message
attila Mising name is currently offline attila Mising name
Messages: 45
Registered: April 2010
Member
Quote:
The default VIRGO_HOME/configuration/web.xml is ignored...


Quote:
Did you restart the server? Can you try "startup -clean"?


Yes i did, however it works fine now - i cannot reproduce the problem.
As i have several Virgo instances i suppose i was configuring one instance and start another - i cannot find other explanation.

Thank you for your support.
Re: Global ServletFilter [message #989699 is a reply to message #987551] Fri, 07 December 2012 05:45 Go to previous messageGo to next message
Johan Eriksson is currently offline Johan Eriksson
Messages: 19
Registered: May 2012
Junior Member
This works fine - thanks Violeta !
Re: Global ServletFilter [message #1037934 is a reply to message #989699] Wed, 10 April 2013 03:36 Go to previous messageGo to next message
Samir Bayani is currently offline Samir Bayani
Messages: 2
Registered: April 2013
Junior Member
The filter entry in my web.xml looks similar to below,

<filter>
  	<filter-name>globalfilter</filter-name>
  	<filter-class>custom.global.filter.globalfilter</filter-class>
</filter>
<filter-mapping>
  	<filter-name>globalfilter</filter-name>
  	<url-pattern>/*</url-pattern>
</filter-mapping>


However, I am getting error while starting up the virgo container because of custom.global.filter.globalfilter ClassNotFoundException. This container startup problem is only with virgo-tomcat-server.3.6.1 and not with 3.5.0. In case of 3.5.0, everything seems to be working fine.
Re: Global ServletFilter [message #1039069 is a reply to message #1037934] Thu, 11 April 2013 14:11 Go to previous messageGo to next message
Violeta Georgieva is currently offline Violeta Georgieva
Messages: 214
Registered: October 2010
Senior Member
That's because the catalina bundle is with changed bundle symbolic name in 3.6.x version.

Open custom.glocal.filter.jar go to META-INF/MANIFEST and change the value for header Fragment-Host:

Fragment-Host: org.apache.catalina


Regards
Violeta
Re: Global ServletFilter [message #1041557 is a reply to message #1039069] Mon, 15 April 2013 04:46 Go to previous message
Samir Bayani is currently offline Samir Bayani
Messages: 2
Registered: April 2013
Junior Member
Thanks Violeta. It worked after updating Fragment-Host as you said.
Previous Topic:Virgo eclise tool : Error when change output folder
Next Topic:New maven plugin for plans generator
Goto Forum:
  


Current Time: Thu Apr 17 00:02:26 EDT 2014

Powered by FUDForum. Page generated in 0.03021 seconds