Search in sources :

Example 16 with HttpServer

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

the class PackageScanningTest method testSimpleResource.

@Test
public void testSimpleResource() throws Exception {
    final ResourceConfig resourceConfig = new ResourceConfig().packages(SimpleResource.class.getPackage().getName());
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
    _testScannedResources(server);
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 17 with HttpServer

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

the class SseTest method testSse.

@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();
}
Also used : EventSource(org.glassfish.jersey.media.sse.EventSource) InboundEvent(org.glassfish.jersey.media.sse.InboundEvent) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Client(javax.ws.rs.client.Client) CountDownLatch(java.util.concurrent.CountDownLatch) LinkedList(java.util.LinkedList) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Example 18 with HttpServer

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

the class JerseyApp method main.

public static void main(final String[] args) throws Exception {
    System.out.println("Jersey performance test web service application");
    final URI baseUri = args.length > 0 ? URI.create(args[0]) : BASE_URI;
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, createResourceConfig());
    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);
    }
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) URI(java.net.URI)

Example 19 with HttpServer

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

the class TestDataGeneratorApp method main.

public static void main(final String[] args) throws Exception {
    baseUri = args.length > 0 ? URI.create(args[0]) : BASE_URI;
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, createApp());
    LOG.info("Jersey performance test data generation - application started.");
    try {
        // generate text files - 1kb, 5kb, 10kb, 1MB and optionally 1GB
        generateFile("simple/text", 1024, FILE_PATH + "custom-1kb.text");
        generateFile("simple/text", 5 * 1024, FILE_PATH + "custom-5kb.text");
        generateFile("simple/text", 10 * 1024, FILE_PATH + "custom-10kb.text");
        generateFile("simple/text", 1024 * 1024, FILE_PATH + "custom-1MB.text");
        if (GENERATE_ALSO_GIGABYTE_DATASETS) {
            generateFile("text", 1024 * 1024 * 1024, FILE_PATH + "custom-1GB.text");
        }
        // generate json files - 1kb, 5kb, 10kb, 1MB and optionally 1GB
        generateFile("simple/json", 1024, FILE_PATH + "custom-1kb.json");
        generateFile("simple/json", 5 * 1024, FILE_PATH + "custom-5kb.json");
        generateFile("simple/json", 10 * 1024, FILE_PATH + "custom-10kb.json");
        generateFile("simple/json", 1024 * 1024, FILE_PATH + "custom-1MB.json");
        if (GENERATE_ALSO_GIGABYTE_DATASETS) {
            generateFile("simple/json", 1024 * 1024 * 1024, FILE_PATH + "custom-1GB.json");
        }
        // generate xml files - 1kb, 5kb, 10kb, 1MB and optionally 1GB
        generateFile("simple/xml", 1024, FILE_PATH + "custom-1kb.xml");
        generateFile("simple/xml", 5 * 1024, FILE_PATH + "custom-5kb.xml");
        generateFile("simple/xml", 10 * 1024, FILE_PATH + "custom-10kb.xml");
        generateFile("simple/xml", 1024 * 1024, FILE_PATH + "custom-1MB.xml");
        if (GENERATE_ALSO_GIGABYTE_DATASETS) {
            generateFile("simple/xml", 1024 * 1024 * 1024, FILE_PATH + "custom-1GB.json");
        }
    } catch (final IOException e) {
        LOG.log(Level.SEVERE, "An error occurred during test data generation. ", e);
    }
    server.shutdown();
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) IOException(java.io.IOException)

Example 20 with HttpServer

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

the class AbstractJsonOsgiIntegrationTest method testJson.

@Test
public void testJson() throws Exception {
    final Feature jsonProviderFeature = getJsonProviderFeature();
    final Client client = ClientBuilder.newClient();
    final ResourceConfig resourceConfig = new ResourceConfig(JsonResource.class);
    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();
        }
    }
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Client(javax.ws.rs.client.Client) Feature(javax.ws.rs.core.Feature) Test(org.junit.Test)

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