 |
Extending GlassFish's WebContainer
Posted by jfarcand on September 08, 2006 at 10:44 AM | Comments (6)
The GlassFish WebContainer is based on the Tomcat Servlet implementation called Catalina. The Catalina architecture, introduced in Tomcat 4.x, was designed to easily allow developer to extends it. There is several interception point in Catalina that can be extended:
- Valve: A Valve is a request processing component associated with a particular virtual-server(host) or web-module (servlet). A series of Valves are generally associated with each other into a Pipeline. Developer will usually inject their valves in order to have access to the Catalina internal objects, and manipulate the request/response object before filters or servlets are invoked. As an example, the access logging mechanism in GlassFish is implemented as a Valve.
- ContainerListener: A listener for significant Container generated events. As an example, every time a WAR is deployed, a ContainerListener implementation will be notified for every new created Servlet, TagLib or Filter.
- InstanceListener: A listener for significant events related to a specific servlet instance. An implementation of this interface will get notified everytime a Servlet is about to be invoked or when some operations are made on the Servlet (like when calling its ServletContextListeners).
- LifecycleListener: A listener for significant events (including "virtual server start" and "web module stop") generated by a component that implements the Lifecycle interface. An implementation of this interface will get notified by mostly all internal objects when an it is started|stopped (like when a new virtual-server is created). As an example, we are using this interface internally to notify the other GlassFish's containers.
Virtual server supports the injection of Valve, ContainerListener and LifecycleListener. Web module supports the same as the virtual server with the addition of the InstanceListener. Once you have your extension implemented, you need to install it in GlassFish. To install an extension:
For virtual-server
For web-module
Very easy, is it :-). This is supported starting in GlassFish v2 build 17.
technorati: web container glassfish
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Hi Jean-Francois,
You should check out the trace and jvm insight extensions we have created specifically for Tomcat which could easily be integrated into Glassfish as we do for JBoss AS / Apache Tomcat today. The benefit of our integration is that you get an awarding winning management console to analysis the performance profile and perform on-demand runtime object state inspections.
JXInsight 4.2.2 - Apache Tomcat Monitoring
http://blog.jinspired.com/?p=16
JXInsight 4.2.2 - Inspecting WebApps
http://blog.jinspired.com/?p=17
Regards,
William Louth
JXInsight Product Architect
JInspired
"Java EE tuning, testing, tracing, and monitoring with JXInsight"
http://www.jinspired.com
Posted by: williamlouth on September 11, 2006 at 11:57 AM
-
Hi William, this is interesting :-) Our Valve API is a little different than the one in Tomcat, so you might need to change your API a little. -- Jeanfrancois
Posted by: jfarcand on September 11, 2006 at 01:30 PM
-
Hello Jean ,
How would you include the Remote Address Filter?
-->
-Fret
Posted by: fret on June 29, 2007 at 08:12 AM
-
I am trying to use Valves, and I am a little confused a few things.
1. by the versioning terminology of Glassfish. I am using Sun Java System Application Server 9.1 (build b50g-beta3) - it seems like that would have the support for Valves, but I can't seem to get Valves to work.
2. I noticed that the Valve API (as you point out in the comment above) is different from Catalina's. Is there documentation (beyond the JavaDoc linked above) on the version used in Glassfish, and a discussion of the motivations and implications?
Question 1 is there because I cannot get the Valve to load or work. I don't know how to verify that a Valve was loaded, and certainly it isn't doing its job as far as add headers is concerned.
Thanks!
Benjamin
Posted by: br_31 on August 28, 2007 at 04:18 AM
-
Never mind my previous posting.
I figured it out - the importance of the property naming ("valve_XXX") escaped me the first time.
Another question regarding this:
If the user is deploying a J2EE application (EAR) there is no web-module entry in domain.xml. Is there a way to configure a valve at the web-module level then?
Thanks,
Benjamin
Posted by: br_31 on August 28, 2007 at 04:58 AM
-
Hi Benjamin,
can we continue the discussion on users@glassfish.dev.java.net so more people can reply (and more faster response :-)). Can you elaborate on what you want to do? I suspect you may want to read this. as I suspect it may help. See you on the users list :-)
Thanks! -- Jeanfrancois
Posted by: jfarcand on August 28, 2007 at 07:16 AM
|