Home Index Changes Prefs Log in »

How can I make my Tomcat valves work with GlassFish?

GlassFish v3 supports Tomcat valves out-of-the-box, so no conversion is necessary.

In GlassFish v2, the org.apache.catalina.Valve interface is different from Tomcat. It was changed to implement an optimization which flattens the valve invocations of a pipeline (and therefore the stack frames required during the processing of a servlet request): Instead of having one valve invoke the next valve on the pipeline, the GlassFish web container invokes one valve at a time, and decides whether to invoke the next valve in the pipeline by examining the return value of the current valve invocation.

To adapt a Tomcat valve to GlassFish v2, the following changes are required:

  • Change the signature of the valve's implementation of invoke() from void to int
  • Replace every
  return;
with
  return Valve.END_PIPELINE;
  • Replace every call to
  getNext().invoke(request, response);
with
  return Valve.INVOKE_NEXT;
and move any code that follows (i.e., any valve logic that is executed on the way out) to this method:
  public void postInvoke(Request request, Response response)
      throws IOException, ServletException;
« Home Attachments Info Index Changes Prefs
This page (revision-4) was last changed on 10-Dec-08 10:05 AM, -0800 by 192.18.43.10