Search in sources :

Example 6 with ContainerResponse

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

the class ApplicationFilterTest method testFilterNotCalledOn404.

@Test
public void testFilterNotCalledOn404() throws Exception {
    // not found
    final SimpleFilter simpleFilter = new SimpleFilter();
    final ResourceConfig resourceConfig = new ResourceConfig(SimpleResource.class).register(simpleFilter);
    final ApplicationHandler application = new ApplicationHandler(resourceConfig);
    final ContainerResponse response = application.apply(RequestContextBuilder.from("/NOT-FOUND", "GET").build()).get();
    assertEquals(404, response.getStatus());
    Assert.assertFalse(simpleFilter.called);
}
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 7 with ContainerResponse

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

the class SubResourceDynamicTest method testSubResourceDynamicWithTemplates.

@Test
public void testSubResourceDynamicWithTemplates() throws Exception {
    app = createApplication(ParentWithTemplates.class);
    ContainerResponse response;
    response = app.apply(RequestContextBuilder.from("/parent", "GET").accept("text/plain").build()).get();
    assertEquals("parent", response.getEntity());
    response = app.apply(RequestContextBuilder.from("/parent/child/first", "GET").accept("text/plain").build()).get();
    assertEquals("first", response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse) Test(org.junit.Test)

Example 8 with ContainerResponse

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

the class SubResourceProgrammaticTest method _test.

private void _test(ApplicationHandler handler, String requestUri, String expected) throws InterruptedException, ExecutionException {
    final ContainerResponse response = handler.apply(RequestContextBuilder.from(requestUri, "GET").build()).get();
    assertEquals(200, response.getStatus());
    assertEquals(expected, response.getEntity());
}
Also used : ContainerResponse(org.glassfish.jersey.server.ContainerResponse)

Example 9 with ContainerResponse

use of org.glassfish.jersey.server.ContainerResponse 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 10 with ContainerResponse

use of org.glassfish.jersey.server.ContainerResponse 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)

Aggregations

ContainerResponse (org.glassfish.jersey.server.ContainerResponse)211 Test (org.junit.Test)190 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)95 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)58 MediaType (javax.ws.rs.core.MediaType)16 Form (javax.ws.rs.core.Form)14 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)14 Cookie (javax.ws.rs.core.Cookie)7 Response (javax.ws.rs.core.Response)5 Ignore (org.junit.Ignore)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)2 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)2 ContainerException (org.glassfish.jersey.server.ContainerException)2 RequestContextBuilder (org.glassfish.jersey.server.RequestContextBuilder)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1