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

441 Views Asked by At

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 );
2

There are 2 best solutions below

0
Joakim Erdfelt On BEST ANSWER

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

0
Horcrux7 On

The solution is a mix. For all what interacted with the Server instance like the InetAccessHandler I need to use the instances from jetty-server.jar (without ee8 in the package).

The ServletContextHandler come from the jetty-ee9-servlet.jar.

All handler that are added to the ServletContextHandler like the ErrorHandler must then come from the jetty-ee8-nested.jar.

If you do this all in the same class then you have a problem with different classes for Request in the Signatures of the different handler methods, org.eclipse.jetty.server.Request and org.eclipse.jetty.ee8.nested.Request. I have import the first class and the second write full qualified in the method signature.