I’ve been using custom implementations of HttpInput.Interceptor and HttpOutput.Interceptor in Jetty 11 and earlier, overriding the readFrom and write methods to add my own logic.

I’m now migrating to Jetty 12, where these APIs are no longer available. Is there an alternative approach or recommended replacement in Jetty 12 to achieve the same behavior? How should this be implemented in the newer version?

Below is sample code what I am doing in jetty 9, 10, 11.

import org.eclipse.jetty.server.HttpInput; import org.eclipse.jetty.server.Request; import java.io.IOException; import java.nio.ByteBuffer; public class JettyInputInterceptor implements HttpInput.Interceptor { private final Request baseRequest; private final Reporting rhandler; JettyInputInterceptor(Reporting rhandler, Request baseRequest ) { this.rhandler = rhandler; this.baseRequest = baseRequest; } @Override public HttpInput.Content readFrom( HttpInput.Content content ) { long handle = rhandler.getRequestHandle(); if( content.hasContent() && handle != 0L ) { int size = content.remaining(); byte[] body = new byte[size]; content.get( body, 0, size ); ReturnValue<byte[]> rv = Native.filterBody( handle, body ); if( rv.getAction() == NativeThing.ACTIONI ) { ByteBuffer buf = ByteBuffer.wrap( rv.getValue() ); return new HttpInput.Content( buf ); } else if( rv.getAction() == NativeThing.ACTIONII ) { try { baseRequest.getResponse().setStatus( SC_BAD_REQUEST ); baseRequest.getResponse().closeOutput(); } catch( IOException e ) { e.printStackTrace(); } } return new HttpInput.Content( ByteBuffer.wrap( body ) ); } return content; } }

Vivek Dhyani's user avatar

New contributor

Vivek Dhyani is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.