Search in sources :

Example 86 with ResourceConfig

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

the class App method createProgrammaticClipboardApp.

/**
     * Create example application resource configuration.
     *
     * @return initialized resource configuration of the example application.
     */
public static ResourceConfig createProgrammaticClipboardApp() {
    final Resource.Builder resourceBuilder = Resource.builder(ROOT_PATH);
    final Clipboard clipboard = new Clipboard();
    resourceBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext data) {
            final String content = clipboard.content();
            if (content.isEmpty()) {
                return Response.noContent().build();
            }
            return Response.ok(content).build();
        }
    });
    resourceBuilder.addMethod("PUT").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext data) {
            if (data != null) {
                clipboard.setContent(((ContainerRequest) data).readEntity(String.class));
            }
            return Response.noContent().build();
        }
    });
    resourceBuilder.addMethod("POST").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext data) {
            String newContent = (data != null) ? clipboard.append(((ContainerRequest) data).readEntity(String.class)) : "";
            return Response.ok(newContent).build();
        }
    });
    resourceBuilder.addMethod("DELETE").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext data) {
            clipboard.clear();
            return Response.noContent().build();
        }
    });
    return new ResourceConfig().registerResources(resourceBuilder.build());
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Resource(org.glassfish.jersey.server.model.Resource) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 87 with ResourceConfig

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

the class MonitoringFeatureTest method testOnlyMBeansEnabled2.

@Test
public void testOnlyMBeansEnabled2() {
    final ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.property(ServerProperties.MONITORING_STATISTICS_MBEANS_ENABLED, true);
    resourceConfig.property(ServerProperties.MONITORING_STATISTICS_ENABLED, false);
    final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    final ResourceConfig config = applicationHandler.getConfiguration();
    Assert.assertTrue(config.isRegistered(ApplicationInfoListener.class));
    Assert.assertTrue(config.isRegistered(MonitoringEventListener.class));
    Assert.assertTrue(config.isRegistered(MBeanExposer.class));
}
Also used : ApplicationInfoListener(org.glassfish.jersey.server.internal.monitoring.ApplicationInfoListener) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) MonitoringEventListener(org.glassfish.jersey.server.internal.monitoring.MonitoringEventListener) MBeanExposer(org.glassfish.jersey.server.internal.monitoring.jmx.MBeanExposer) Test(org.junit.Test)

Example 88 with ResourceConfig

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

the class MonitoringFeatureTest method testStatisticsEnabled.

@Test
public void testStatisticsEnabled() {
    final ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.register(MonitoringFeature.class);
    final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    final ResourceConfig config = applicationHandler.getConfiguration();
    Assert.assertTrue(config.isRegistered(ApplicationInfoListener.class));
    Assert.assertTrue(config.isRegistered(MonitoringEventListener.class));
    Assert.assertFalse(config.isRegistered(MBeanExposer.class));
}
Also used : ApplicationInfoListener(org.glassfish.jersey.server.internal.monitoring.ApplicationInfoListener) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) MonitoringEventListener(org.glassfish.jersey.server.internal.monitoring.MonitoringEventListener) MBeanExposer(org.glassfish.jersey.server.internal.monitoring.jmx.MBeanExposer) Test(org.junit.Test)

Example 89 with ResourceConfig

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

the class MonitoringFeatureTest method testOnlyMBeansEnabled3.

@Test
public void testOnlyMBeansEnabled3() {
    final ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.property(ServerProperties.MONITORING_STATISTICS_MBEANS_ENABLED, true);
    resourceConfig.property(ServerProperties.MONITORING_STATISTICS_ENABLED, false);
    resourceConfig.register(new MonitoringFeature());
    final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    final ResourceConfig config = applicationHandler.getConfiguration();
    Assert.assertTrue(config.isRegistered(ApplicationInfoListener.class));
    Assert.assertTrue(config.isRegistered(MonitoringEventListener.class));
    Assert.assertTrue(config.isRegistered(MBeanExposer.class));
}
Also used : MonitoringFeature(org.glassfish.jersey.server.internal.monitoring.MonitoringFeature) ApplicationInfoListener(org.glassfish.jersey.server.internal.monitoring.ApplicationInfoListener) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) MonitoringEventListener(org.glassfish.jersey.server.internal.monitoring.MonitoringEventListener) MBeanExposer(org.glassfish.jersey.server.internal.monitoring.jmx.MBeanExposer) Test(org.junit.Test)

Example 90 with ResourceConfig

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

the class MonitoringFeatureTest method testMonitoringEnabledByAutodiscovery.

@Test
public void testMonitoringEnabledByAutodiscovery() {
    final ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.property(ServerProperties.MONITORING_ENABLED, true);
    final ApplicationHandler applicationHandler = new ApplicationHandler(resourceConfig);
    final ResourceConfig config = applicationHandler.getConfiguration();
    Assert.assertTrue(config.isRegistered(ApplicationInfoListener.class));
    Assert.assertTrue(config.isRegistered(MonitoringEventListener.class));
    Assert.assertFalse(config.isRegistered(MBeanExposer.class));
}
Also used : ApplicationInfoListener(org.glassfish.jersey.server.internal.monitoring.ApplicationInfoListener) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) MonitoringEventListener(org.glassfish.jersey.server.internal.monitoring.MonitoringEventListener) MBeanExposer(org.glassfish.jersey.server.internal.monitoring.jmx.MBeanExposer) Test(org.junit.Test)

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