Search in sources :

Example 81 with ResourceConfig

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

the class WadlGeneratorConfigurationLoaderTest method testLoadConfigClass.

@Test
public void testLoadConfigClass() throws URISyntaxException {
    final ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.property(ServerProperties.WADL_GENERATOR_CONFIG, MyWadlGeneratorConfig.class.getName());
    final InjectionManager locator = InjectionManagerFactory.createInjectionManager(resourceConfig.getProperties());
    final WadlGenerator wadlGenerator = WadlGeneratorConfigLoader.loadWadlGeneratorsFromConfig(resourceConfig.getProperties()).createWadlGenerator(locator);
    Assert.assertEquals(MyWadlGenerator.class, wadlGenerator.getClass());
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 82 with ResourceConfig

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

the class SubResourceProgrammaticTest method testComplex.

@Test
public void testComplex() throws ExecutionException, InterruptedException {
    ApplicationHandler handler = new ApplicationHandler(new ResourceConfig(RootResource.class));
    int singletonCounter = 0;
    _test(handler, "/root/complex/", "inflector");
    _test(handler, "/root/complex/singleton", "singleton:" + singletonCounter++);
    _test(handler, "/root/complex/singleton/iteration", "singleton:" + singletonCounter++);
    _test(handler, "/root/complex/singleton/iteration/iteration", "singleton:" + singletonCounter++);
    _test(handler, "/root/complex/singleton/iteration-class", "singleton:" + singletonCounter++);
    _test(handler, "/root/complex/singleton/iteration-instance", "singleton:0");
    _test(handler, "/root/complex/standard", "standard:0");
    _test(handler, "/root/complex/standard/iteration", "standard:0");
    _test(handler, "/root/complex/singleton-method/", "singleton:" + singletonCounter++);
    _test(handler, "/root/complex/singleton/iteration/iteration-standard", "standard:0");
    _test(handler, "/root/complex/standard/iteration/iteration-singleton", "singleton:" + singletonCounter++);
    _test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard", "standard:0");
    _test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard/iteration", "standard:0");
    _test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard/iteration" + "/iteration-singleton/iteration-class", "singleton:" + singletonCounter++);
    _test(handler, "/root/complex/standard/iteration/iteration-singleton/iteration/iteration-standard/iteration" + "/iteration-singleton/iteration-class/iteration-instance", "singleton:0");
    _test(handler, "/root/complex/standard/iteration/iteration-singleton", "singleton:" + singletonCounter++);
    _test(handler, "/root/complex/singleton-method/", "singleton:" + singletonCounter++);
    _test(handler, "/root/complex/singleton", "singleton:" + singletonCounter++);
    _test(handler, "/root/complex", "inflector");
}
Also used : ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 83 with ResourceConfig

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

the class SubResourceProgrammaticTest method testInvalidSubResource.

@Test
public void testInvalidSubResource() throws ExecutionException, InterruptedException {
    ApplicationHandler handler = new ApplicationHandler(new ResourceConfig(WrongResource.class));
    _test(handler, "/wrong", "ok");
    try {
        final ContainerResponse response = handler.apply(RequestContextBuilder.from("/wrong/locator", "GET").build()).get();
        assertEquals(500, response.getStatus());
        fail("Should throw exception caused by validation errors of Sub Resource.");
    } catch (Throwable e) {
    // ok - Should throw exception caused by validation errors of Sub Resource.
    }
}
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 84 with ResourceConfig

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

the class ValidatorTest method testDisableFailOnErrors.

@Test
public void testDisableFailOnErrors() throws ExecutionException, InterruptedException {
    final ResourceConfig rc = new ResourceConfig(AmbiguousLocatorResource1.class, AmbiguousLocatorResource2.class, AmbiguousParameterResource.class, AmbiguousResource1.class, AmbiguousResource2.class, ConcreteGenericArrayResource.class, ConcreteParameterizedTypeResource.class, EmptyResource.class, GenericArrayResource.class, MethodAndLocatorResource.class, MethodAndLocatorResource2.class, MyBeanParam.class, ParameterizedTypeResource.class, PercentEncodedCaseSensitiveTest.class, PercentEncodedTest.class, ResourceAsProvider.class, ResourceMethodWithVoidReturnType.class, ResourceRoot.class, ResourceRootNotUnique.class, ResourceSubPathRoot.class, ResourceWithMultipleScopes.class, TestAmbiguousParams.class, TestAsyncGetRMReturningVoid.class, TestEmptyPathSegment.class, TestEntityParamOnSRL.class, TestGetRMConsumingEntity.class, TestGetRMConsumingFormParam.class, TestGetRMReturningVoid.class, TestGetSRMConsumingEntity.class, TestGetSRMConsumingFormParam.class, TestGetSRMReturningVoid.class, TestMoreThanOneEntity.class, TestMultipleHttpMethodDesignatorsRM.class, TestMultipleHttpMethodDesignatorsSRM.class, TestNonConflictingHttpMethodDelete.class, TestNonPublicRM.class, TestRelaxedProducesConsumesParserRules.class, TestRootResourceNonAmbigCtors.class, TestSRLReturningVoid.class, TwoLocatorsResource.class, TypeVariableResource.class, UniqueResource.class, // we should still be able to invoke a GET on this one.
    TestDisableValidationFailOnErrorResource.class);
    rc.property(ServerProperties.RESOURCE_VALIDATION_IGNORE_ERRORS, true);
    ApplicationHandler ah = new ApplicationHandler(rc);
    final ContainerRequest request = RequestContextBuilder.from("/test-disable-validation-fail-on-error", "GET").build();
    ContainerResponse response = ah.apply(request).get();
    assertEquals(200, response.getStatus());
    assertEquals("PASSED", response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 85 with ResourceConfig

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

the class ChildResourceTest method createApplication.

private ApplicationHandler createApplication() {
    final Resource.Builder rootBuilder = Resource.builder("root");
    rootBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() {

        @Override
        public String apply(ContainerRequestContext requestContext) {
            return "root-get";
        }
    });
    rootBuilder.addChildResource("child").addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() {

        @Override
        public String apply(ContainerRequestContext requestContext) {
            return "sub-get";
        }
    }).build();
    Resource.Builder anotherChildBuilder = Resource.builder("another-child");
    anotherChildBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, String>() {

        @Override
        public String apply(ContainerRequestContext requestContext) {
            return "another-child-get";
        }
    });
    rootBuilder.addChildResource(anotherChildBuilder.build());
    Resource resource = rootBuilder.build();
    ResourceConfig resourceConfig = new ResourceConfig().registerResources(resource);
    return new ApplicationHandler(resourceConfig);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Inflector(org.glassfish.jersey.process.Inflector) Resource(org.glassfish.jersey.server.model.Resource) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) 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