package com.github.jhpoelen.fbob;

import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;

import java.io.IOException;
import java.net.URI;

public class Main {
    public static HttpServer startServer() {
        final ResourceConfig rc = new ResourceConfig().packages("com.github.jhpoelen.fbob");
        return GrizzlyHttpServerFactory.createHttpServer(URI.create(getBaseURI()), rc);
    }

    public static String getBaseURI() {
        String port = System.getenv("PORT");
         return "http://localhost:" + (port == null ? 8080 : port) + "/myapp/";
    }

    public static void main(String[] args) throws IOException {
        final HttpServer server = startServer();
        System.out.println(String.format("Jersey app started with WADL available at "
                + "%sapplication.wadl\nHit CTRL^C to stop it...", getBaseURI()));

        // register shutdown hook
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Stopping server..");
                server.shutdownNow();
            }
        }, "shutdownHook"));

        try {
            server.start();
            Thread.currentThread().join();
        } catch (Exception e) {
            System.err.println("There was an error while starting Grizzly HTTP server.");
        }
    }
}


@@ -742,24 +742,99 @@
 Exception %7B%0A
+        System.out.println(String.format(%22%25s starting...%22, getBaseURI()));%0A
         fina
@@ -916,114 +916,18 @@
 at(%22
-Jersey app started with WADL available at %22%0A                + %22%25sapplication.wadl%5CnHit CTRL%5EC to stop it..
+%25s started
 .%22, 
@@ -1143,27 +1143,53 @@
 tln(
-%22Stopping server..%22
+String.format(%22%25s stopping...%22, getBaseURI())
 );%0A 
@@ -1221,24 +1221,104 @@
 tdownNow();%0A
+                System.out.println(String.format(%22%25s stopped.%22, getBaseURI()));%0A
             
@@ -1395,51 +1395,8 @@
 ();%0A
-            Thread.currentThread().join();%0A
     

remove thread join