Search in sources :

Example 6 with HttpServer

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

the class App method main.

/**
     * Main application entry point.
     *
     * @param args application arguments.
     */
public static void main(String[] args) {
    try {
        System.out.println("JAX-RS Type Injection Jersey Example App");
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, create(), false);
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                server.shutdownNow();
            }
        }));
        server.start();
        System.out.println(String.format("Application started.%n" + "To test injection into a programmatic resource, try out:%n  %s%s%s%n" + "To test instance injection into an annotated resource, try out:%n  %s%s%s%n" + "To test method injection into an annotated resource, try out:%n  %s%s%s%n" + "Stop the application using CTRL+C", BASE_URI, ROOT_PATH_PROGRAMMATIC, "?q1=<value_1>&q2=<value_2>&q2=<value_3>", BASE_URI, ROOT_PATH_ANNOTATED_INSTANCE, "?q1=<value_1>&q2=<value_2>&q2=<value_3>", BASE_URI, ROOT_PATH_ANNOTATED_METHOD, "?q1=<value_1>&q2=<value_2>&q2=<value_3>"));
        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 7 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("Jersey HTTP PATCH Support Example App");
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, create(), false);
        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/%s\nStop the application using CTRL+C", BASE_URI, ROOT_PATH));
        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 8 with HttpServer

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

the class App method main.

/**
     * Main application entry point.
     *
     * @param args application arguments.
     */
public static void main(String[] args) {
    try {
        System.out.println("HTTP TRACE Support Jersey Example App");
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, create(), false);
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                server.shutdownNow();
            }
        }));
        server.start();
        System.out.println(String.format("Application started.\n" + "To test TRACE with a programmatic resource, send HTTP TRACE request to:%n  %s%s%n" + "To test TRACE with an annotated resource, send HTTP TRACE request to:%n  %s%s%n" + "Stop the application using CTRL+C", BASE_URI, ROOT_PATH_PROGRAMMATIC, BASE_URI, ROOT_PATH_ANNOTATED));
        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 9 with HttpServer

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

the class Server method start.

/**
     * Start SSL-secured HTTP test server.
     *
     * @throws IOException in case there is an error while reading server key store or trust store.
     * @return an instance of the started SSL-secured HTTP test server.
     */
public static Server start() throws IOException {
    // Grizzly ssl configuration
    SSLContextConfigurator sslContext = new SSLContextConfigurator();
    // set up security context
    // contains server keypair
    sslContext.setKeyStoreFile(KEYSTORE_SERVER_FILE);
    sslContext.setKeyStorePass(KEYSTORE_SERVER_PWD);
    // contains client certificate
    sslContext.setTrustStoreFile(TRUSTORE_SERVER_FILE);
    sslContext.setTrustStorePass(TRUSTORE_SERVER_PWD);
    ResourceConfig rc = new ResourceConfig();
    rc.registerClasses(RootResource.class, SecurityFilter.class, AuthenticationExceptionMapper.class);
    final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc, true, new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true));
    // start Grizzly embedded server //
    LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
    grizzlyServer.start();
    return new Server(grizzlyServer);
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) SSLContextConfigurator(org.glassfish.grizzly.ssl.SSLContextConfigurator)

Example 10 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("JSON with MOXy Jersey Example App");
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp(), false);
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                server.shutdownNow();
            }
        }));
        server.start();
        System.out.println(String.format("Application started.%nStop the application using CTRL+C"));
        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)

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