Search in sources :

Example 41 with HttpServer

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

the class JerseyGrizzlyRunner method main.

public static void main(String[] args) throws Exception {
    System.out.println("Jersey performance test web service application");
    final String jaxRsApp = args.length > 0 ? args[0] : null;
    //noinspection unchecked
    final ResourceConfig resourceConfig = ResourceConfig.forApplicationClass((Class<? extends Application>) Class.forName(jaxRsApp));
    URI baseUri = args.length > 1 ? URI.create(args[1]) : BASE_URI;
    int selectors = args.length > 2 ? Integer.parseInt(args[2]) : DEFAULT_SELECTORS;
    int workers = args.length > 3 ? Integer.parseInt(args[3]) : DEFAULT_WORKERS;
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
    final TCPNIOTransport transport = server.getListener("grizzly").getTransport();
    transport.setSelectorRunnersCount(selectors);
    transport.setWorkerThreadPoolConfig(ThreadPoolConfig.defaultConfig().setCorePoolSize(workers).setMaxPoolSize(workers));
    server.start();
    System.out.println(String.format("Application started.\nTry out %s\nHit Ctrl-C to stop it...", baseUri));
    while (server.isStarted()) {
        Thread.sleep(600000);
    }
}
Also used : TCPNIOTransport(org.glassfish.grizzly.nio.transport.TCPNIOTransport) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) URI(java.net.URI)

Example 42 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("Feed Combiner Example App");
        URI baseUri = UriBuilder.fromUri("http://localhost/").port(8080).path("combiner").build();
        // Automatically set the SelectorRunner count value equal to Runtime.getRuntime().availableProcessors()
        HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, new MyApplication(), false);
        Runtime.getRuntime().addShutdownHook(new Thread(server::shutdownNow));
        server.start();
        System.out.println("Application started.\n" + "HTML manager: " + baseUri + "\n" + "REST API: " + baseUri + "/feeds\n" + "Stop the application using CTRL+C");
        Thread.currentThread().join();
    } catch (IOException | InterruptedException e) {
        Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, e);
    }
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) IOException(java.io.IOException) URI(java.net.URI)

Example 43 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("\"Exception Mapping\" Jersey Example App");
        final ResourceConfig resourceConfig = new ResourceConfig(ExceptionResource.class, ExceptionResource.MyResponseFilter.class, ExceptionResource.WebApplicationExceptionFilter.class, Exceptions.MyExceptionMapper.class, Exceptions.MySubExceptionMapper.class, Exceptions.WebApplicationExceptionMapper.class);
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false);
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                server.shutdownNow();
            }
        }));
        server.start();
        System.out.println(String.format("Application started.%n" + "Try out %s%s%n" + "Stop 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) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) IOException(java.io.IOException)

Example 44 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("Extended WADL web application example");
        Map<String, String> initParams = new HashMap<>();
        initParams.put(ServletProperties.JAXRS_APPLICATION_CLASS, MyApplication.class.getName());
        initParams.put(ServerProperties.WADL_GENERATOR_CONFIG, "org.glassfish.jersey.examples.extendedwadl" + ".SampleWadlGeneratorConfig");
        final HttpServer server = GrizzlyWebContainerFactory.create(BASE_URI, ServletContainer.class, initParams);
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                server.shutdownNow();
            }
        }));
        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 : HashMap(java.util.HashMap) HttpServer(org.glassfish.grizzly.http.server.HttpServer) MyApplication(org.glassfish.jersey.examples.extendedwadl.resources.MyApplication) IOException(java.io.IOException)

Example 45 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("\"Hello World\" Jersey-Spring Example App");
        final JerseyConfig resourceConfig = new JerseyConfig();
        resourceConfig.property("contextConfig", new AnnotationConfigApplicationContext(SpringAnnotationConfig.class));
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, 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 : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) 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