Search in sources :

Example 26 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("Simple Console Jersey Example App");
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), createApp(), 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%nStop the application using CTRL+C", BASE_URI + "/form"));
        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 27 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("System Properties 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.%n" + "Try out %s%n" + "Stop the application using CTRL+C", BASE_URI + "/properties"));
        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 28 with HttpServer

use of org.glassfish.grizzly.http.server.HttpServer in project graylog2-server by Graylog2.

the class JerseyService method setUp.

private HttpServer setUp(String namePrefix, URI listenUri, SSLEngineConfigurator sslEngineConfigurator, int threadPoolSize, int selectorRunnersCount, int maxInitialLineLength, int maxHeaderSize, boolean enableGzip, boolean enableCors, Set<Resource> additionalResources, String[] controllerPackages) throws GeneralSecurityException, IOException {
    final ResourceConfig resourceConfig = buildResourceConfig(enableCors, additionalResources, controllerPackages);
    final HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(listenUri, resourceConfig, sslEngineConfigurator != null, sslEngineConfigurator, false);
    final NetworkListener listener = httpServer.getListener("grizzly");
    listener.setMaxHttpHeaderSize(maxInitialLineLength);
    listener.setMaxRequestHeaders(maxHeaderSize);
    final ExecutorService workerThreadPoolExecutor = instrumentedExecutor(namePrefix + "-worker-executor", namePrefix + "-worker-%d", threadPoolSize);
    listener.getTransport().setWorkerThreadPool(workerThreadPoolExecutor);
    // The Grizzly default value is equal to `Runtime.getRuntime().availableProcessors()` which doesn't make
    // sense for Graylog because we are not mainly a web server.
    // See "Selector runners count" at https://grizzly.java.net/bestpractices.html for details.
    listener.getTransport().setSelectorRunnersCount(selectorRunnersCount);
    listener.setDefaultErrorPageGenerator(errorPageGenerator);
    if (enableGzip) {
        final CompressionConfig compressionConfig = listener.getCompressionConfig();
        compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON);
        compressionConfig.setCompressionMinSize(512);
    }
    return httpServer;
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) InstrumentedExecutorService(com.codahale.metrics.InstrumentedExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener) CompressionConfig(org.glassfish.grizzly.http.CompressionConfig)

Example 29 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 Example App");
        final ResourceConfig resourceConfig = new ResourceConfig(HelloWorldResource.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 : HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) IOException(java.io.IOException)

Example 30 with HttpServer

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

the class KoBrowserTest method compatibilityTests.

@Factory
public static Object[] compatibilityTests() throws Exception {
    Browser.LOG.setLevel(Level.FINE);
    Browser.LOG.addHandler(new ConsoleHandler());
    final BrowserBuilder bb = BrowserBuilder.newBrowser(new Browser("KoBrowserTest")).loadClass(KoBrowserTest.class).loadPage("empty.html").invoke("initialized");
    Executors.newSingleThreadExecutor().submit(new Runnable() {

        @Override
        public void run() {
            bb.showAndWait();
        }
    });
    List<Object> res = new ArrayList<Object>();
    Class<? extends Annotation> test = loadClass().getClassLoader().loadClass(KOTest.class.getName()).asSubclass(Annotation.class);
    Class[] arr = (Class[]) loadClass().getDeclaredMethod("tests").invoke(null);
    final HttpServer s = Browser.findServer(browserPresenter);
    ServerConfiguration conf = s.getServerConfiguration();
    conf.addHttpHandler(new DynamicHTTP(s), "/dynamic");
    for (Class c : arr) {
        for (Method m : c.getMethods()) {
            if (m.getAnnotation(test) != null) {
                res.add(new KOScript(browserPresenter, m));
            }
        }
    }
    return res.toArray();
}
Also used : ServerConfiguration(org.glassfish.grizzly.http.server.ServerConfiguration) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ConsoleHandler(java.util.logging.ConsoleHandler) BrowserBuilder(net.java.html.boot.BrowserBuilder) HttpServer(org.glassfish.grizzly.http.server.HttpServer) Factory(org.testng.annotations.Factory)

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