Search in sources :

Example 36 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("\"Async resources\" Jersey Example App");
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, create(), false);
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                server.shutdownNow();
            }
        }));
        server.start();
        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" + "Stop the application using CTRL+C", BASE_URI, ASYNC_MESSAGING_FIRE_N_FORGET_PATH, BASE_URI, ASYNC_MESSAGING_BLOCKING_PATH, BASE_URI, ASYNC_LONG_RUNNING_OP_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) IOException(java.io.IOException)

Example 37 with HttpServer

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

the class PackageScanningTest method testSimpleResourceInitParameters.

@Test
public void testSimpleResourceInitParameters() throws Exception {
    Map<String, String> initParams = new HashMap<String, String>();
    initParams.put(ServerProperties.PROVIDER_PACKAGES, SimpleResource.class.getPackage().getName());
    // 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);
    }
    // END of workaround - when grizzly updated to more recent version, only the inner line of try clause should remain:
    _testScannedResources(server);
}
Also used : HashMap(java.util.HashMap) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) HttpServer(org.glassfish.grizzly.http.server.HttpServer) Test(org.junit.Test)

Example 38 with HttpServer

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

the class ApacheOsgiIntegrationTest method testSimpleResource.

@Test
public void testSimpleResource() throws Exception {
    final ResourceConfig resourceConfig = new ResourceConfig(ApacheOsgiTestResource.class);
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.connectorProvider(new ApacheConnectorProvider());
    final Client c = ClientBuilder.newClient(clientConfig);
    final Response response = c.target(baseUri).path("/apacheOsgiTest").request().buildGet().invoke();
    final String result = response.readEntity(String.class);
    assertEquals("OK", result);
    server.shutdownNow();
}
Also used : Response(javax.ws.rs.core.Response) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ApacheConnectorProvider(org.glassfish.jersey.apache.connector.ApacheConnectorProvider) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 39 with HttpServer

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

the class BasicOsgiIntegrationTest method testSimpleResource.

@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();
}
Also used : Response(javax.ws.rs.core.Response) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 40 with HttpServer

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

the class BeanValidationTest method _test.

protected void _test(final int expectedResponseCode, final boolean registerFeature, final boolean disableMetainfServicesLookup) {
    final ResourceConfig resourceConfig = new ResourceConfig(BeanValidationResource.class);
    if (registerFeature) {
        resourceConfig.register(ValidationFeature.class);
    }
    if (disableMetainfServicesLookup) {
        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();
}
Also used : Response(javax.ws.rs.core.Response) Form(javax.ws.rs.core.Form) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Client(javax.ws.rs.client.Client)

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