Package com.sun.jersey.spi.container

Examples of com.sun.jersey.spi.container.ContainerRequest


    headers.add(HttpHeaders.USER_AGENT, "curl/7.20.0 (x86_64-pc-linux-gnu) libcurl/7.20.0 OpenSSL/1.0.0a zlib/1.2.3");
    headers.add(HmacUtils.X_HMAC_DATE, "Sat, 01 Jan 2000 12:34:57 GMT");
    headers.add(HmacUtils.X_HMAC_NONCE, "Thohn2Mohd2zugo");

    // Mock request
    ContainerRequest containerRequest = mock(ContainerRequest.class);
    when(containerRequest.getRequestHeaders()).thenReturn(headers);
    when(containerRequest.getMethod()).thenReturn("GET");
    when(containerRequest.getRequestUri()).thenReturn(URI.create(baseUri + resourcePath + queryParameters));

    String representation = HmacUtils.createCanonicalRepresentation(containerRequest);

    FixtureAsserts.assertStringMatchesStringFixture("GET all fields canonical representation", representation, "/fixtures/hmac/expected-canonical-get.txt");
View Full Code Here


    headers.add(HttpHeaders.USER_AGENT, "curl/7.20.0 (x86_64-pc-linux-gnu) libcurl/7.20.0 OpenSSL/1.0.0a zlib/1.2.3");
    headers.add(HmacUtils.X_HMAC_DATE, "Sat, 01 Jan 2000 12:34:57 GMT");
    headers.add(HmacUtils.X_HMAC_NONCE, "Thohn2Mohd2zugo");

    // Mock request
    ContainerRequest containerRequest = mock(ContainerRequest.class);
    when(containerRequest.getRequestHeaders()).thenReturn(headers);
    when(containerRequest.getMethod()).thenReturn("POST");
    when(containerRequest.getRequestUri()).thenReturn(URI.create(baseUri + resourcePath + queryParameters));

    // Simulate a user wrapped in HAL
    ByteArrayInputStream bais = new ByteArrayInputStream("{\"_links\":{\"self\":{\"href\":\"http://example.org/user\"}}}".getBytes());
    when(containerRequest.getEntityInputStream()).thenReturn(bais);

    String actualCanonicalRepresentation = HmacUtils.createCanonicalRepresentation(containerRequest);

    FixtureAsserts.assertStringMatchesStringFixture("POST all fields canonical representation", actualCanonicalRepresentation, "/fixtures/hmac/expected-canonical-post.txt");
View Full Code Here

          throw new WebApplicationException(Response.Status.BAD_REQUEST);
        }

        final String apiKey = authTokens[1];
        final String signature = authTokens[2];
        final ContainerRequest containerRequest = (ContainerRequest) httpContext.getRequest();

        // Build the canonical representation for the server side
        final String canonicalRepresentation = HmacUtils.createCanonicalRepresentation(containerRequest);
        log.debug("Server side canonical representation: '{}'", canonicalRepresentation);
View Full Code Here

            scheme = endpointUri.getScheme();
        }

        URI baseUri = getBaseUri(endpointUri, scheme, host, contextPath);
        URI completeUri = getCompleteUri(endpointUri, scheme, host, path, query);
        ContainerRequest req = new ContainerRequest(application, method, baseUri, completeUri, headers,
            getInputStream(message));
        if (logger.isDebugEnabled())
        {
            logger.debug("Base URI: " + baseUri);
            logger.debug("Complete URI: " + completeUri);
View Full Code Here

    }

    @Test
    public void testGetMatchedURIs_0args() {
        WebApplicationContext instance = new WebApplicationContext(wa,
                new ContainerRequest(wa, "GET", UriBuilder.fromPath("http://localhost/").build(),
                    UriBuilder.fromPath("http://localhost/one%20two/three%20four").build(), new InBoundHeaders(), null)
                , null);
        instance.pushRightHandPathLength(12);
        assertEquals(instance.getMatchedURIs(true).get(0), instance.getMatchedURIs().get(0));
        assertNotSame(instance.getMatchedURIs(false).get(0), instance.getMatchedURIs().get(0));
View Full Code Here

    }

    @Test
    public void testGetMatchedURIs_boolean() {
        WebApplicationContext instance = new WebApplicationContext(wa,
                new ContainerRequest(wa, "GET", UriBuilder.fromPath("http://localhost/").build(),
                    UriBuilder.fromPath("http://localhost/one%20two/three%20four").build(), new InBoundHeaders(), null)
                , null);
        instance.pushRightHandPathLength(12);
        assertEquals("one%20two/", instance.getMatchedURIs(false).get(0));
        assertEquals("one two/", instance.getMatchedURIs(true).get(0));
View Full Code Here

        // Copy the application field to local instance to ensure that the
        // currently loaded web application is used to process
        // request
        final WebApplication _application = application;

        final ContainerRequest cRequest = createRequest(
                _application,
                request,
                baseUri,
                requestUri);

        cRequest.setSecurityContext(new SecurityContext() {
            public Principal getUserPrincipal() {
                return request.getUserPrincipal();
            }

            public boolean isUserInRole(String role) {
View Full Code Here

     * @return the request container
     * @throws IOException if any error occurs when getting the input stream
     */
    protected ContainerRequest createRequest(WebApplication app,
                                             HttpServletRequest request, URI baseUri, URI requestUri) throws IOException {
        return new ContainerRequest(
                app,
                request.getMethod(),
                baseUri,
                requestUri,
                getHeaders(request),
View Full Code Here

    private Object invokeSubLocator(final Object resource, final UriRuleContext context) {
        // Push the response filters
        context.pushContainerResponseFilters(responseFilters);

        ContainerRequest containerRequest = context.getContainerRequest();

        // Process the request filter
        if (!requestFilters.isEmpty()) {
            for (ContainerRequestFilter f : requestFilters) {
                containerRequest = f.filter(containerRequest);
                context.setContainerRequest(containerRequest);
            }
        }

        // Invoke the sub-locator method
        dispatchingListener.onSubResourceLocator(Thread.currentThread().getId(), locator);

        SecurityContext sc = containerRequest.getSecurityContext();
        if (sc instanceof SubjectSecurityContext) {
            return ((SubjectSecurityContext) sc).doAsSubject(new PrivilegedAction() {
                @Override
                public Object run() {
                    return dispatch(resource, context);
View Full Code Here

            }

            // Push the response filters
            context.pushContainerResponseFilters(method.getResponseFilters());

            ContainerRequest containerRequest = context.getContainerRequest();

            // Process the request filter
            if (!method.getRequestFilters().isEmpty()) {
                for (ContainerRequestFilter f : method.getRequestFilters()) {
                    containerRequest = f.filter(containerRequest);
                    context.setContainerRequest(containerRequest);
                }
            }

            context.pushMethod(method.getAbstractResourceMethod());

            // Dispatch to the resource method
            try {
                dispatchingListener.onResourceMethod(Thread.currentThread().getId(), method.getAbstractResourceMethod());

                SecurityContext sc = containerRequest.getSecurityContext();
                if (sc instanceof SubjectSecurityContext) {
                    ((SubjectSecurityContext) sc).doAsSubject(new PrivilegedAction() {
                        @Override
                        public Object run() {
                            method.getDispatcher().dispatch(resource, context);
View Full Code Here

TOP

Related Classes of com.sun.jersey.spi.container.ContainerRequest

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.