jetty / jetty.project

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
https://eclipse.dev/jetty
Other
3.84k stars 1.91k forks source link

org.eclipse.jetty.maven.ServerSupport.configureHandlers(Server, List<ContextHandler>, RequestLog) removes handlers #12279

Closed vitalus closed 1 week ago

vitalus commented 1 week ago

Jetty version(s) Jetty 12.0.13

Description If jetty-eeXX-maven-plugin loads Jetty XMLs like jetty-cross-origin.xml where a org.eclipse.jetty.server.handler.CrossOriginHandler handler is created and added to Server object, then later an underlying method removes this handler..

    public static void configureHandlers(Server server, List<ContextHandler> contextHandlers, RequestLog requestLog) throws Exception 
    {
        if (server == null)
            throw new IllegalArgumentException("Server is null");

        if (requestLog != null)
            server.setRequestLog(requestLog);

        if (server.getDefaultHandler() == null)
            server.setDefaultHandler(new DefaultHandler());

        ContextHandlerCollection contexts = findContextHandlerCollection(server);
        if (contexts == null)
        {
            contexts = new ContextHandlerCollection();
            server.setHandler(contexts);
        } 

        if (contextHandlers != null)
        {   
            for (ContextHandler context:contextHandlers)
            {
                contexts.addHandler(context);
            }
        }
    }

Problem is in line with:

server.setHandler(contexts);

It should be probably addHandler(contexts) type of logic..