Package org.glassfish.grizzly.http.server

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


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

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

            System.out.println(String.format(
                    "Application started.\n"
                    + "To test simple, non-blocking asynchronous messaging resource, try %s%s\n"
                    + "To test blocking version of asynchronous messaging resource, try %s%s\n"
                    + "To test long-running asynchronous operation resource, try %s%s\n"
                    + "Hit enter to stop it...",
                    BASE_URI, ASYNC_MESSAGING_FIRE_N_FORGET_PATH,
                    BASE_URI, ASYNC_MESSAGING_BLOCKING_PATH,
                    BASE_URI, ASYNC_LONG_RUNNING_OP_PATH));
            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("\"Hello World\" Jersey Example App");

            final ResourceConfig resourceConfig = new ResourceConfig(HelloWorldResource.class);
            final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig);

            System.out.println(String.format("Application started.\nTry out %s%s\nHit enter to stop it...",
                    BASE_URI, ROOT_PATH));
            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("Simple Console Jersey Example App");

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

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

            resourceConfig.property(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, Boolean.TRUE);

            resourceConfig.register(org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainerProvider.class);
        }

        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);

        final Form form = new Form();
        final String formValue = "formValue";
        form.asMap().add("formParam", formValue);

        final Client client = ClientBuilder.newClient();
        final String entity = client.
                target(baseUri).
                path("/bean-validation").
                request().
                post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class);

        assertEquals(formValue, entity);

        final Response response = client.
                target(baseUri).
                path("/bean-validation").
                request().
                post(Entity.entity(new Form(), MediaType.APPLICATION_FORM_URLENCODED_TYPE));

        assertEquals(expectedResponseCode, response.getStatus());

        server.shutdownNow();
    }
View Full Code Here

    }

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

        Client c = ClientBuilder.newClient();
        final Response response = c.target(baseUri).path("/super-simple").request().buildGet().invoke();

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

        assertEquals("OK", result);

        server.shutdownNow();
    }
View Full Code Here

    }

    @Test
    public void testJsonObject() throws Exception {
        final ResourceConfig resourceConfig = new ResourceConfig(Resource.class);
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
        final JsonObject jsonObject = Json.createObjectBuilder().add("foo", "bar").build();

        final Client client = ClientBuilder.newClient();
        final JsonObject entity = client.
                target(baseUri).
                request(MediaType.APPLICATION_JSON_TYPE).
                post(Entity.json(jsonObject), JsonObject.class);

        System.out.println("RESULT = " + entity);
        assertEquals(jsonObject, entity);

        server.shutdownNow();
    }
View Full Code Here

    }

    @Test
    public void testSimpleResource() throws Exception {
        final ResourceConfig resourceConfig = new ResourceConfig().packages(SimpleResource.class.getPackage().getName());
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);

        _testSimpleResource(server);
    }
View Full Code Here

        // TODO - temporary workaround
        // This is a workaround related to issue JERSEY-2093; grizzly (1.9.5) needs to have the correct context
        // classloader set
        ClassLoader myClassLoader = getClass().getClassLoader();
        ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
        HttpServer server = null;
        try {
            Thread.currentThread().setContextClassLoader(myClassLoader);
            server = GrizzlyWebContainerFactory.create(baseUri, ServletContainer.class, initParams);
        } finally {
            Thread.currentThread().setContextClassLoader(originalContextClassLoader);
View Full Code Here

    }

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

        final Client client = ClientBuilder.newClient();
        final String response = client.target(baseUri).path("/simple").request().get(String.class);

        System.out.println("RESULT = " + response);
        assertEquals("OK", response);

        server.shutdownNow();
    }
View Full Code Here

        if (jsonProviderFeature != null) {
            client.register(jsonProviderFeature);
            resourceConfig.register(jsonProviderFeature);
        }

        HttpServer server = null;
        try {
            server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);

            final String result = client.target(baseUri).path("/json").request(MediaType.APPLICATION_JSON).get(String.class);

            System.out.println("RESULT = " + result);
            assertThat(result, containsString("Jim"));
        } finally {
            if (server != null) {
                server.shutdownNow();
            }
        }
    }
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.