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:
invoke() from void to int
return;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;