How to start stop DropWizzrd HTTP server programitically

59 views
Skip to first unread message

Kuttaiah Robin

unread,
Jun 6, 2019, 4:56:56 AM6/6/19
to dropwizard-user
Hello,

Am new to dropwizzard.  Can someone help me on how to start and stop Dropwizzard HTTP server programmatically in Java?

thanks,
Robin Kuttaiah 

Ryan Kennedy

unread,
Jun 6, 2019, 9:32:17 AM6/6/19
to dropwiz...@googlegroups.com
I recommend reading through the Get Started documentation if you haven’t already:

Ryan

--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dropwizard-user/1e3c6509-803f-4957-9649-037592a7379e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kuttaiah Robin

unread,
Jun 6, 2019, 10:53:40 AM6/6/19
to dropwizard-user
Thank you for your recommendation. I had gone through it.

I have a framework where I need to feed  Dropwizzard HTTPServer, so that framework will start and stop the server.
SpringBoot, Oracle J4C/Helidon can be plugged to that. We need to support Dropwizzarad as well.

In case of Helidon we do as shown below;

    public synchronized Startable<Void> getUserServer() {
        if (userServer == null) {
            final io.helidon.webserver.Routing.Builder routingBuilder = getRoutingBuilder();
            final io.helidon.webserver.ServerConfiguration.Builder serverConfigBuilder = getServerConfigBuilder();

            customizeServerConfig(serverConfigBuilder);
            customizeRouting(routingBuilder);

            final io.helidon.webserver.WebServer server = WebServer.create(serverConfigBuilder.build(), routingBuilder.build());
            this.userServer = new J4CStartable(server);
        }
        return userServer;
    }


private static class J4CStartable implements Startable<Void> {
        private final WebServer webserver;

        private J4CStartable(final WebServer webserver) {
            this.webserver = webserver;
        }

        @Override
        public CompletionStage<Void> start() {
            return this.webserver.start().exceptionally(t -> {
                if (t != null) {
                    final Throwable t2 = ExceptionUtils.getCause(t);
                    if (t2 instanceof SocketException && "Permission denied".equals(t2.getMessage()) && webserver.configuration().port() < 1024) {
                        throw new RuntimeException("Permission denied (Possibly trying to bind to port < 1024 as non-root user)", t);
                    } else {
                        throw new RuntimeException(t);
                    }
                }
                return null;
            }).thenApply(s -> null);
        }

        @Override
        public CompletionStage<Void> stop() {
            return this.webserver.shutdown().thenApply(s -> null);
        }
    }



When we execute below in tutorial which code starts the HTTP server?   I believe I would need the same stuff.

java -jar target/hello-world-0.0.1-SNAPSHOT.jar server hello-world.yml


Thank you once again.
regards,
Robin Kuttaiah


On Thursday, June 6, 2019 at 7:02:17 PM UTC+5:30, Ryan Kennedy wrote:
I recommend reading through the Get Started documentation if you haven’t already:

Ryan
On Thu, Jun 6, 2019 at 1:56 AM Kuttaiah Robin <kutt...@gmail.com> wrote:
Hello,

Am new to dropwizzard.  Can someone help me on how to start and stop Dropwizzard HTTP server programmatically in Java?

thanks,
Robin Kuttaiah 

--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwiz...@googlegroups.com.

Peter Stackle

unread,
Jun 6, 2019, 1:19:07 PM6/6/19
to dropwizard-user
-- moving reply from dropwizard-dev to here

Hey Robin,
This page goes into more detail about how the application starts up:

Depending on where in the lifecycle you want to cut in at, you could directly call the Application.run(args) method or if you want to bypass most everything Dropwizard is doing, you can look at what the ServerCommand.run() method does.

You also could look at the DropwizardTestSupport class from the dropwizard-testing module to see how the application is started/stopped for integration tests.

Peter
Reply all
Reply to author
Forward
0 new messages