Search in sources :

Example 61 with ResourceConfig

use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.

the class FilterSetMethodTest method testPreMatchingFilter.

@Test
public void testPreMatchingFilter() throws ExecutionException, InterruptedException {
    ApplicationHandler handler = new ApplicationHandler(new ResourceConfig(Resource.class, PreMatchFilter.class));
    ContainerResponse res = handler.apply(RequestContextBuilder.from("", "/resource/setMethod", "GET").build()).get();
    assertEquals(200, res.getStatus());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 62 with ResourceConfig

use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.

the class App method main.

public static void main(final String[] args) throws Exception {
    try {
        LOGGER.info("Resource Config Reload Jersey Example App");
        for (String s : args) {
            if (s.startsWith("-cp=")) {
                Compiler.classpath = s.substring(4);
            }
        }
        final ResourceConfig resourceConfig = createResourceConfig(new File(CONFIG_FILENAME));
        registerReloader(resourceConfig);
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, true);
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                server.shutdownNow();
            }
        }));
        server.start();
        System.out.println(String.format("Application started.\nTry out %s%s\nStop the application using CTRL+C", BASE_URI, ROOT_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) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) IOException(java.io.IOException) JavaFile(org.glassfish.jersey.examples.reload.compiler.JavaFile) File(java.io.File)

Example 63 with ResourceConfig

use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.

the class ReloadTest method testReload.

@Test
public void testReload() {
    // hit arrivals
    Response response = target().path("arrivals").request(MediaType.TEXT_PLAIN).get();
    assertEquals(200, response.getStatus());
    // make sure stats resource is not found
    response = target().path("stats").request(MediaType.TEXT_PLAIN).get();
    assertEquals(404, response.getStatus());
    // add stats resource
    container.reload(new ResourceConfig(ArrivalsResource.class, StatsResource.class));
    // check stats
    response = target().path("stats").request(MediaType.TEXT_PLAIN).get();
    assertEquals(200, response.getStatus());
    assertTrue("1 expected as number of arrivals hits in stats", response.readEntity(String.class).contains("1"));
    // another arrivals hit
    response = target().path("arrivals").request(MediaType.TEXT_PLAIN).get();
    assertEquals(200, response.getStatus());
    // check updated stats
    response = target().path("stats").request(MediaType.TEXT_PLAIN).get();
    assertEquals(200, response.getStatus());
    assertTrue("2 expected as number of arrivals hits in stats", response.readEntity(String.class).contains("2"));
    // remove stats
    container.reload(new ResourceConfig(ArrivalsResource.class));
    // make sure stats resource is not found
    response = target().path("stats").request(MediaType.TEXT_PLAIN).get();
    assertEquals(404, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 64 with ResourceConfig

use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.

the class App method main.

public static void main(String[] args) {
    try {
        System.out.println("\"Server-Sent Events\" Jersey Example App");
        final ResourceConfig resourceConfig = new ResourceConfig(ServerSentEventsResource.class, SseFeature.class);
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false);
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                server.shutdownNow();
            }
        }));
        server.start();
        System.out.println(String.format("Application started.\nTry out %s%s\nStop the application using CTRL+C", BASE_URI, ROOT_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) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) IOException(java.io.IOException)

Example 65 with ResourceConfig

use of org.glassfish.jersey.server.ResourceConfig in project jersey by jersey.

the class BroadcasterTest method configure.

@Override
protected Application configure() {
    final ResourceConfig rc = new ResourceConfig(SseResource.class);
    rc.property(ServerProperties.WADL_FEATURE_DISABLE, true);
    return rc;
}
Also used : ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Aggregations

ResourceConfig (org.glassfish.jersey.server.ResourceConfig)357 Test (org.junit.Test)135 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)105 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)62 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)33 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)29 Response (javax.ws.rs.core.Response)28 HttpServer (org.glassfish.grizzly.http.server.HttpServer)28 Resource (org.glassfish.jersey.server.model.Resource)24 URI (java.net.URI)23 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)23 IOException (java.io.IOException)22 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)22 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)18 Server (org.eclipse.jetty.server.Server)17 ApplicationInfoListener (org.glassfish.jersey.server.internal.monitoring.ApplicationInfoListener)17 MonitoringEventListener (org.glassfish.jersey.server.internal.monitoring.MonitoringEventListener)17 MBeanExposer (org.glassfish.jersey.server.internal.monitoring.jmx.MBeanExposer)17 MetricRegistry (com.codahale.metrics.MetricRegistry)15 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)15