I am trying to create new Adapter for Http11NioProcessor. I have added the following code. I have debug stop points on every method but they never get hit. I have verified the factory.addProtocolHandlerCustomizers(....) does get hit.

Has this feature ever been validated to work?

@Configuration
public class MyConfig implements WebServerFactoryCustomizer<TomcatServletWebServerFactory>  {

@Override
    public void customize(TomcatServletWebServerFactory factory) {
        factory.addProtocolHandlerCustomizers(new TomcatProtocolHandlerCustomizer() {
            @Override
            public void customize(ProtocolHandler protocolHandler) {
                protocolHandler.setAdapter(new Adapter() {
                    @Override
                    public void service(Request req, Response res) throws Exception {
                        System.out.println("Test");
                    }

                    @Override
                    public boolean prepare(Request req, Response res) throws Exception {
                        if( "chunked".equalsIgnoreCase(req.getHeader("transfer-encoding")) && req.getHeader("content-length") != null){
                            res.setStatus(400);
                            res.doWrite(ByteBuffer.wrap("You cannot send both content-length and transfer-encoding headers on request".getBytes(StandardCharsets.UTF_8)));
                            return false;
                        }
                        return true;
                    }

                    @Override
                    public boolean asyncDispatch(Request req, Response res, SocketEvent status) throws Exception {
                        return true;
                    }

                    @Override
                    public void log(Request req, Response res, long time) {}

                    @Override
                    public void checkRecycled(Request req, Response res) {
                        System.out.println("Test");
                    }

                    @Override
                    public String getDomain() {
                        return null;
                    }
                });
            }
        });
    }



}

Screen Shot 2022-03-28 at 1 53 07 PM

Comment From: wilkinsona

Tomcat expects to have control over the adapter and sets it when the connector is initialized. This will be replacing your custom adapter. You might be able to hook into Tomcat's lifecycle and configure the adapter once the connector's been initialized, but I'm not sure if that's something that the Tomcat team would recommend. You could try asking on the Tomcat users mailing list or Stack Overflow.