Search code examples
javajettyembedded-jettyjakarta-migration

How to migrate from embedded Jetty 10 to jetty 12 ee8?


I try to port from Jetty 10.x to Jetty 12.x ee8. After I have change the dependencies based on this list https://download.eclipse.org/tools/orbit/simrel/maven-jetty/release/12.0.6/. I get some compiler errors with the embedded Jetty.

There seems no ee8 Server class that I use org.eclipse.jetty.server.Server. This class extends from the org.eclipse.jetty.server.Handler.Wrapper.

But the handler from the jetty-ee8-nested extends from org.eclipse.jetty.ee8.nested.HandlerWrapper which is not compatible. For example the org.eclipse.jetty.ee8.nested.InetAccessHandler. The one expected the org.eclipse.jetty.server.Handler the other org.eclipse.jetty.ee8.nested.Handler

Is there another implementieren of Server which I have oversee? Where can i find it? How is the classname?

Or must I modify my code? For example how can I change the follow lines?

InetAccessHandler ipaccess = new InetAccessHandler();
ipaccess.setHandler( getHandler() );
setHandler( ipaccess );

Solution

  • First, there's a porting guide from Jetty 11 to Jetty 12: https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-migration-11-to-12

    It shows many of the things you are asking about.

    Ignore the classes in the org.eclipse.jetty.ee8.nested.* package, those are internal classes for the ee8 layer.

    Use org.eclipse.jetty.server.handler.InetAccessHandler.

    You can wrap that around any Handler, eg: org.eclipse.jetty.server.Handler.Sequence, a org.eclipse.jetty.ee8.webappWebAppContext, etc ...

    InetAccessHandler inetAccessHandler = new InetAccessHandler();
    // allow only http clients from localhost IPv4 or IPv6
    inetAccessHandler.include("127.0.0.1", "::1");
    server.setHandler(inetAccessHandler);
    
    Handler.Sequence handlers = new Handler.Sequence();
    inetAccessHandler.setHandler(handlers);
    
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar(warPath.toUri().toASCIIString());
    
    handlers.addHandler(webapp);
    

    This snippet is from https://github.com/jetty/jetty-examples/tree/12.0.x/embedded/ee8-webapp-context