Package org.glassfish.grizzly.http.server

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


    }

    @Test
    public void testSse() throws Exception {
        final ResourceConfig resourceConfig = new ResourceConfig(SseResource.class, SseFeature.class);
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);

        Client c = ClientBuilder.newClient();
        c.register(SseFeature.class);

        final List<String> data = new LinkedList<String>();
        final CountDownLatch latch = new CountDownLatch(2);

        final EventSource eventSource = new EventSource(c.target(baseUri).path("/sse")) {

            @Override
            public void onEvent(InboundEvent event) {
                try {
                    data.add(event.readData());
                    latch.countDown();
                } catch (ProcessingException e) {
                    // ignore
                }
            }
        };

        assertTrue(latch.await(2, TimeUnit.SECONDS));

        eventSource.close();
        assertEquals(2, data.size());

        server.shutdownNow();
    }
View Full Code Here


    }

    @Test
    public void testMultiPartResource() throws Exception {
        final ResourceConfig resourceConfig = new ResourceConfig(MultiPartResource.class).register(new MultiPartFeature());
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);

        Client c = ClientBuilder.newClient(new ClientConfig().register(MultiPartFeature.class));
        final Response response = c.target(baseUri).path("/multipart-simple").request().buildGet().invoke();

        MultiPart result = response.readEntity(MultiPart.class);
        System.out.println("RESULT = " + result);

        checkEntity("This is the only segment", (BodyPartEntity) result.getBodyParts().get(0).getEntity());

        server.shutdownNow();
    }
View Full Code Here

            System.out.println("Jersey performance test web service application");

            final ResourceConfig resourceConfig =
                    new ResourceConfig(TextEntityResource.class, CustomInterceptor.class);
            URI baseUri = args.length > 0 ? URI.create(args[0]) : BASE_URI;
            final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);

            System.out.println(String.format("Application started.\nTry out %s%s\nHit Ctrl-C to stop it...",
                    baseUri, ROOT_PATH));

            while (server.isStarted()) {
                Thread.sleep(600000);
            }
    }
View Full Code Here

    @SuppressWarnings({"ResultOfMethodCallIgnored"})
    public static void main(String[] args) {
        try {
            System.out.println("JSON with JAXB Jersey Example App");

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

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

    @SuppressWarnings({"ResultOfMethodCallIgnored"})
    public static void main(String[] args) {
        try {
            System.out.println("XML with MOXy Jersey Example App");

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

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

    public static void main(String[] args) {
        try {
            System.out.println("JAXB Jersey Example App");

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

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

     *
     * @param webRootPath static content root path.
     * @return Grizzly HTTP server.
     */
    public static HttpServer startServer(String webRootPath) {
        final HttpServer server = new HttpServer();
        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 StaticContentHandler(webRootPath),
                APP_PATH);

        // add handler for serving JAX-RS resources
        config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class),
                API_PATH);

        try {
            // Start the server.
            server.start();
        } catch (Exception ex) {
            throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
        }

        return server;
View Full Code Here

    public static void main(String[] args) {
        MainWindow.main(args);

        try {
            System.out.println("\"SSE Twitter Message Aggregator\" Jersey Example App");
            final HttpServer server = startServer(args.length >= 1 ? args[0] : null);
            System.out.println(String.format("Application started.\n" +
                    "Access it at %s\n" +
                    "Hit enter to stop it...",
                    getAppUri()));
            System.in.read();
            server.shutdownNow();
        } catch (IOException ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
View Full Code Here

    public static void main(String[] args) throws Exception {
            System.out.println("Jersey performance test web service application");

            final ResourceConfig resourceConfig = new ResourceConfig(DynamicallyBoundFilterResource.class, DynamicallyBoundFilter.class);
            URI baseUri = args.length > 0 ? URI.create(args[0]) : BASE_URI;
            final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);

            System.out.println(String.format("Application started.\nTry out %s%s\nHit Ctrl-C to stop it...",
                    baseUri, ROOT_PATH));

            while (server.isStarted()) {
                Thread.sleep(600000);
            }
    }
View Full Code Here

    public static void main(String[] args) throws Exception {
            System.out.println("Jersey performance test web service application");

            final ResourceConfig resourceConfig = new ResourceConfig(MethodInjectedResource.class, FieldInjectedResource.class);
            URI baseUri = args.length > 0 ? URI.create(args[0]) : BASE_URI;
            final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);

            System.out.println(String.format("Application started.\nTry out %s\nHit Ctrl-C to stop it...", baseUri));

            while (server.isStarted()) {
                Thread.sleep(600000);
            }
    }
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.