Package org.glassfish.jersey.server

Examples of org.glassfish.jersey.server.ContainerResponse


    @Test
    public void testGetOnChild() throws ExecutionException, InterruptedException {
        ResourceConfig resourceConfig = new ResourceConfig(ResourceA.class, ResourceB.class, ResourceQ.class);
        ApplicationHandler app = new ApplicationHandler(resourceConfig);
        final ContainerResponse containerResponse = app.apply(RequestContextBuilder.from("/resq/a", "GET").build()).get();
        Assert.assertEquals(200, containerResponse.getStatus());
        Assert.assertEquals("getA", containerResponse.getEntity());
    }
View Full Code Here


    @Test
    public void testSubResourceDynamic() throws Exception {
        app = createApplication(Parent.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", "GET").accept("text/plain").build()).get();
        assertEquals("child", response.getEntity());
    }
View Full Code Here

    @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());
    }
View Full Code Here

    @Test
    public void testSubResourceCapturingGroups() throws Exception {
        app = createApplication(SubResourceExplicitRegexCapturingGroups.class);

        ContainerResponse response;

        response = app.apply(RequestContextBuilder.from("/123-456-789/d", "GET").accept("text/plain").build()).get();
        assertEquals("d", response.getEntity());
    }
View Full Code Here

    }


    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());
    }
View Full Code Here

    @Test
    public void testStringPost() throws ExecutionException, InterruptedException {
        initiateWebApplication(ResourceString.class);

        final ContainerResponse responseContext = apply(
                RequestContextBuilder.
                        from("/", "POST").
                        cookie(new Cookie("arg1", "a")).
                        cookie(new Cookie("arg2", "b")).
                        cookie(new Cookie("arg3", "c")).
                        entity("content").build()
        );

        assertEquals("content", responseContext.getEntity());
    }
View Full Code Here

    @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.
        }
    }
View Full Code Here

    @Test
    public void testBadStringConstructorValue() throws ExecutionException, InterruptedException {
        initiateWebApplication(ResourceString.class);

        final ContainerResponse responseContext = apply(
                RequestContextBuilder.from("/", "GET").
                        header("arg1", "ABCDEF").
                        header("arg2", "3145").
                        header("arg3", "http://test").
                        build()
        );

        assertEquals(400, responseContext.getStatus());
    }
View Full Code Here

        _testSetDefault("double", "3.14159265358979");
    }

    @Test
    public void testBadPrimitiveSetValue() throws ExecutionException, InterruptedException {
        final ContainerResponse response = super.getResponseContext("/Set?int=abcdef&int=abcdef", "application/int");

        assertEquals(404, response.getStatus());
    }
View Full Code Here

        @GET
        @Produces("text/plain")
        public void get(final ContainerRequest context) throws IOException {
            assertThat(context.getMethod(), is("GET"));

            final ContainerResponse response = new ContainerResponse(context, Response.ok().build());
            final OutputStream os = context.getResponseWriter()
                    .writeResponseStatusAndHeaders("RESOURCE".getBytes().length, response);
            os.write("RESOURCE".getBytes());
            os.close();
        }
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.server.ContainerResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.