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 <code>org.apache.catalina.Valve</code> 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 <code>invoke()</code> from <code>void</code> to <code>int</code>
with
return Valve.END_PIPELINE;
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;
|