Home > Java > How to migrate from embedded jetty 10 to jetty 12 ee8?

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

WBOY
Release: 2024-02-05 11:56:49
forward
765 people have browsed it
Question content

I try to port from jetty 10.x to jetty 12.x ee8. After I changed the dependencies according to this list https://download.eclipse.org/tools/orbit/simrel/maven-jetty/release/12.0.6/. I'm getting some compiler errors while using embedded jetty.

There seems to be no ee8 server class, I use org.eclipse.jetty.server.server. This class extends from org.eclipse.jetty.server.handler.wrapper.

But the handler for jetty-ee8-nested extends from org.eclipse.jetty.ee8.nested.handlerwrapper, which is incompatible. For example org.eclipse.jetty.ee8.nested.inetaccesshandler. One expects org.eclipse.jetty.server.handler and the other org.eclipse.jetty.ee8.nested.handler

Is there another implementer of the server I oversee? Where can I find it? What about class names?

Or do I have to modify my code? For example, how do I change the following line?

InetAccessHandler ipaccess = new InetAccessHandler();
ipaccess.setHandler( getHandler() );
setHandler( ipaccess );
Copy after login


Correct answer


First, there is a migration 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 asked about.

Ignore Classes in the org.eclipse.jetty.ee8.nested.* package, these are internal classes of the ee8 layer.

Use org.eclipse.jetty.server.handler.inetaccesshandler.

You can wrap it around any handler, for example: org.eclipse.jetty.server.handler.sequence, 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);
Copy after login

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

The above is the detailed content of How to migrate from embedded jetty 10 to jetty 12 ee8?. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template