Search code examples
javadropwizardarmeria

Retrieve the Jetty instance in Dropwizard 2.0.0


We have a project made in Dropwizard version 2.0.0-RC, where we use REST-endpoints. After some issues we decided to use gRPC instead of using REST. There is a couple of 3rd party libraries to connect gRPC to Dropwizard, but we believe they are a bit outdated and not useable. So we are thinking about implementing Armeria and their GRPC solution.

To implement this, I need the Jetty instance to attach the GRPC.

This is how I can solve it (Mix between GRPC and Armeria):

Server server = Server.builder()
  .http(8080)
  .service(GrpcService.builder()...build())
  .serviceUnder("/", JettyService.forServer(jettyServer))
  .build();
server.start().join();

So I need the jettyServer to be the instance of Jetty with the type of org.eclipse.jetty.server. The rest of the code is Armerias way of embedding Jetty. Link to embedding jetty.

How can I retrieve the instance of Jetty?


Solution

  • I was able to solve this by using Dropwizard lifecycles to get the server.

    // variable server is of type org.eclipse.jetty.server.Server
    environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() {
        @Override
        public void serverStarted(Server server) {
          // ....
        }
    });
    

    With the instance, you can use Armeria to attach gRPC