Search in sources :

Example 31 with HttpServer

use of org.glassfish.grizzly.http.server.HttpServer in project dukescript-presenters by dukescript.

the class Browser method server.

private static HttpServer server(RootPage r) {
    int from = 8080;
    int to = 65535;
    // NOI18N
    String port = System.getProperty("com.dukescript.presenters.browserPort");
    if (port != null) {
        from = to = Integer.parseInt(port);
    }
    HttpServer s = HttpServer.createSimpleServer(null, new PortRange(from, to));
    final ServerConfiguration conf = s.getServerConfiguration();
    conf.addHttpHandler(r, "/");
    return s;
}
Also used : PortRange(org.glassfish.grizzly.PortRange) ServerConfiguration(org.glassfish.grizzly.http.server.ServerConfiguration) HttpServer(org.glassfish.grizzly.http.server.HttpServer)

Example 32 with HttpServer

use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.

the class Main method startServer.

public static HttpServer startServer(String webRootPath) {
    final HttpServer server = new HttpServer();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            server.shutdownNow();
        }
    }));
    final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT);
    server.addListener(listener);
    final ServerConfiguration config = server.getServerConfiguration();
    // add handler for serving static content
    config.addHttpHandler(new CLStaticHttpHandler(Main.class.getClassLoader(), WEB_ROOT), APP_PATH);
    // add handler for serving JAX-RS resources
    config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class), APP_PATH);
    try {
        // Start the server.
        server.start();
    } catch (Exception ex) {
        throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
    }
    return server;
}
Also used : CLStaticHttpHandler(org.glassfish.grizzly.http.server.CLStaticHttpHandler) ServerConfiguration(org.glassfish.grizzly.http.server.ServerConfiguration) HttpServer(org.glassfish.grizzly.http.server.HttpServer) GrizzlyHttpContainer(org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer) ProcessingException(javax.ws.rs.ProcessingException) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener) ProcessingException(javax.ws.rs.ProcessingException)

Example 33 with HttpServer

use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.

the class App method main.

public static void main(String[] args) {
    try {
        System.out.println("XML with MOXy Jersey Example App");
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp());
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                server.shutdownNow();
            }
        }));
        server.start();
        System.out.println(String.format("Application started.%nTry out %s%nStop the application using CTRL+C", BASE_URI + "/customer"));
        Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
        Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) IOException(java.io.IOException)

Example 34 with HttpServer

use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.

the class Main method startServer.

public static HttpServer startServer(String webRootPath) {
    final HttpServer server = new HttpServer();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            server.shutdownNow();
        }
    }));
    final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT);
    server.addListener(listener);
    final ServerConfiguration config = server.getServerConfiguration();
    // add handler for serving static content
    config.addHttpHandler(new CLStaticHttpHandler(Main.class.getClassLoader(), WEB_ROOT), APP_PATH);
    // add handler for serving JAX-RS resources
    config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class), APP_PATH);
    try {
        // Start the server.
        server.start();
    } catch (Exception ex) {
        throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
    }
    return server;
}
Also used : CLStaticHttpHandler(org.glassfish.grizzly.http.server.CLStaticHttpHandler) ServerConfiguration(org.glassfish.grizzly.http.server.ServerConfiguration) HttpServer(org.glassfish.grizzly.http.server.HttpServer) GrizzlyHttpContainer(org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer) ProcessingException(javax.ws.rs.ProcessingException) IOException(java.io.IOException) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener) ProcessingException(javax.ws.rs.ProcessingException)

Example 35 with HttpServer

use of org.glassfish.grizzly.http.server.HttpServer in project jersey by jersey.

the class Main method main.

public static void main(String[] args) {
    try {
        final HttpServer server = startServer(args.length >= 1 ? args[0] : null);
        System.out.println(String.format("Application started.\n" + "Access it at %s\n" + "Stop the application using CTRL+C", getAppUri()));
        Thread.currentThread().join();
    } catch (InterruptedException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer)

Aggregations

HttpServer (org.glassfish.grizzly.http.server.HttpServer)57 IOException (java.io.IOException)33 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)21 Test (org.junit.Test)11 Client (javax.ws.rs.client.Client)10 ServerConfiguration (org.glassfish.grizzly.http.server.ServerConfiguration)6 ProcessingException (javax.ws.rs.ProcessingException)5 Response (javax.ws.rs.core.Response)5 NetworkListener (org.glassfish.grizzly.http.server.NetworkListener)5 URI (java.net.URI)4 HashMap (java.util.HashMap)3 GrizzlyHttpContainer (org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer)3 CLStaticHttpHandler (org.glassfish.grizzly.http.server.CLStaticHttpHandler)2 SSLContextConfigurator (org.glassfish.grizzly.ssl.SSLContextConfigurator)2 SSLEngineConfigurator (org.glassfish.grizzly.ssl.SSLEngineConfigurator)2 ClientConfig (org.glassfish.jersey.client.ClientConfig)2 CoreOptions.mavenBundle (org.ops4j.pax.exam.CoreOptions.mavenBundle)2 Bundle (org.osgi.framework.Bundle)2 InstrumentedExecutorService (com.codahale.metrics.InstrumentedExecutorService)1 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1