Package org.glassfish.grizzly.http.server

Examples of org.glassfish.grizzly.http.server.HttpServer


   
    public static void main(String[] args) throws Exception {
        final int port = args.length > 0
                ? Integer.parseInt(args[0]) : 8080;
       
        final HttpServer httpServer = new HttpServer();
        final NetworkListener networkListener = new NetworkListener(
                "http-listener", "0.0.0.0", port);
        final TCPNIOTransport transport = networkListener.getTransport();
       
        // force to not initialize worker thread pool
        transport.setWorkerThreadPoolConfig(null);
        transport.setSelectorRunnersCount(Runtime.getRuntime().availableProcessors() * 2);
       
        // set PooledMemoryManager
        transport.setMemoryManager(new PooledMemoryManager());
       
        // always keep-alive
        networkListener.getKeepAlive().setIdleTimeoutInSeconds(-1);
        networkListener.getKeepAlive().setMaxRequestsCount(-1);
       
        // disable transaction timeout
        networkListener.setTransactionTimeout(-1);
       
        // remove the features we don't need
        networkListener.registerAddOn(new SimplifyAddOn());
        // add HTTP pipeline optimization
        networkListener.registerAddOn(new HttpPipelineOptAddOn());
       
        // disable file-cache
        networkListener.getFileCache().setEnabled(false);
       
        httpServer.addListener(networkListener);
       
        httpServer.getServerConfiguration().addHttpHandler(
                new RootHttpHandler(), "/");
//        httpServer.getServerConfiguration().addHttpHandler(
//                new PlainTextHttpHandler(), "/plaintext");
//        httpServer.getServerConfiguration().addHttpHandler(
//                new JsonHttpHandler(), "/json");
       
        try {
            httpServer.start();
           
            System.err.print("Server started.\n");
            synchronized (Server.class) {
    Server.class.wait();
            }
        } finally {
            httpServer.shutdown();
        }
    }
View Full Code Here


  public void run() throws Exception {
    URI baseUri = getBaseUrl(port);
    ResourceConfig rc = new PackagesResourceConfig("hello", "org.eluder.jersey.mustache");
    rc.setPropertiesAndFeatures(properties());
    rc.getContainerResponseFilters().add(new ServerResponseFilter());
    HttpServer server = GrizzlyServerFactory.createHttpServer(baseUri, rc);

    try {
        server.start();

        System.err.print("Server started.\n");
        synchronized (JerseyWebServer.class) {
            JerseyWebServer.class.wait();
        }
    } finally {
        server.stop();
    }
  }
View Full Code Here

                    System.getProperty("java.class.path").replace(File.pathSeparatorChar, ';'));
        } else {
            registration.setInitParameters(initParams);
        }

        HttpServer server = GrizzlyServerFactory.createHttpServer(u);
        context.deploy(server);
        return server;
    }
View Full Code Here

        System.out.println("Starting grizzly...");
        return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
    }

    public static void main(String[] args) throws IOException {
        HttpServer httpServer = startServer();
        System.out.println(String.format("Jersey app started with WADL at %s/application.wadl", BASE_URI));
        System.out.println("Hit return to stop...");
        System.in.read();
        httpServer.stop();
    }   
View Full Code Here

            Map<String, String> initParams = new HashMap<String, String>();
            initParams.put(
                    ServerProperties.PROVIDER_PACKAGES,
                    HelloWorldResource.class.getPackage().getName());
            final HttpServer server = GrizzlyWebContainerFactory.create(BASE_URI, ServletContainer.class, initParams);

            System.out.println(String.format("Application started.%nTry out %s%s%nHit enter to stop it...",
                    BASE_URI, ROOT_PATH));
            System.in.read();
            server.stop();
        } catch (IOException ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
View Full Code Here

        return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
    }
   
    public static void main(String[] args) throws IOException {
        System.out.println("Starting grizzly...");
        HttpServer httpServer = startServer();
        System.out.println(String.format(
                "Jersey app started with WADL available at %sapplication.wadl\n" +
                "Hit enter to stop it...", BASE_URI));
        System.in.read();
        httpServer.stop();
    }   
View Full Code Here

        ResourceConfig rc = new PackagesResourceConfig(MyResource.class.getPackage().getName());
        return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
    }

    public static void main(String[] args) throws IOException {
        HttpServer httpServer = startServer();
        System.out.println(String.format("Jersey app started with WADL available at "
                + "%sapplication.wadl\nTry out %smyresource\nHit enter to stop it...",
                BASE_URI, BASE_URI));
        System.in.read();
        httpServer.stop();
    }
View Full Code Here

            final String host = (u.getHost() == null) ? NetworkListener.DEFAULT_NETWORK_HOST
                    : u.getHost();
            final int port = (u.getPort() == -1) ? 80 : u.getPort();

            final HttpServer server = new HttpServer();
            final NetworkListener listener = new NetworkListener("grizzly", host, port);
            server.addListener(listener);

            // Map the path to the processor.
            final ServerConfiguration config = server.getServerConfiguration();
            config.addHttpHandler(handler, u.getPath());

            // Start the server.
            return server;
        }
View Full Code Here

     */
    public static void main(String[] args) {
        try {
            System.out.println("HTTP TRACE Support Jersey Example App");

            final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, create());

            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"
                            + "Hit enter to stop it...",
                    BASE_URI, ROOT_PATH_PROGRAMMATIC,
                    BASE_URI, ROOT_PATH_ANNOTATED));
            System.in.read();
            server.stop();
        } catch (IOException ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
View Full Code Here

            }

            @Override
            public void start(final String rootPath, int port) throws IOException, DeploymentException {
                contextPath = rootPath;
                server = new HttpServer();
                final ServerConfiguration config = server.getServerConfiguration();

                final NetworkListener listener =
                        new NetworkListener("grizzly",
                                "0.0.0.0",
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.http.server.HttpServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.