Package com.sun.jersey.spi.container

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


    }
   
    // ContainerListener
   
    public void onReload() {
        WebApplication oldApplication = application;
        application = application.clone();
        oldApplication.destroy();
    }
View Full Code Here


        public void finish() throws IOException {           
        }
    }
   
    public void service(GrizzlyRequest request, GrizzlyResponse response) {
        WebApplication _application = application;
       
        final URI baseUri = getBaseUri(request);
        /*
         * request.unparsedURI() is a URI in encoded form that contains
         * the URI path and URI query components.
         */
        final URI requestUri = baseUri.resolve(
                request.getRequest().unparsedURI().toString());
       
        try {
            final ContainerRequest cRequest = new ContainerRequest(
                    _application,
                    request.getMethod(),
                    baseUri,
                    requestUri,
                    getHeaders(request),
                    request.getInputStream());
           
            _application.handleRequest(cRequest, new Writer(response));
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here

    }
   
    // ContainerListener
   
    public void onReload() {
        WebApplication oldApplication = application;
        application = application.clone();
        oldApplication.destroy();
    }   
View Full Code Here

            return contentLength;
        }
    }
   
    public void handle(HttpExchange exchange) throws IOException {
        WebApplication _application = application;
               
        /**
         * This is a URI that contains the path, query and
         * fragment components.
         */
        URI exchangeUri = exchange.getRequestURI();
       
        /**
         * The base path specified by the HTTP context of the HTTP handler.
         * It is in decoded form.
         */
        String decodedBasePath = exchange.getHttpContext().getPath();
       
        // Ensure that the base path ends with a '/'
        if (!decodedBasePath.endsWith("/")) {
            if (decodedBasePath.equals(exchangeUri.getPath())) {
                /**
                 * This is an edge case where the request path
                 * does not end in a '/' and is equal to the context
                 * path of the HTTP handler.
                 * Both the request path and base path need to end in a '/'
                 * Currently the request path is modified.
                 * TODO support redirection in accordance with resource
                 * configuration feature.
                 */
                exchangeUri = UriBuilder.fromUri(exchangeUri).
                        path("/").build();
            }
            decodedBasePath += "/";               
        }

        /*
         * The following is madness, there is no easy way to get
         * the complete URI of the HTTP request!!
         *
         * TODO this is missing the user information component, how
         * can this be obtained?
         */
        HttpServer server = exchange.getHttpContext().getServer();
        String scheme = (server instanceof HttpsServer) ? "https" : "http";
        InetSocketAddress addr = exchange.getLocalAddress();
        URI baseUri = null;
        try {
            baseUri = new URI(scheme, null, addr.getHostName(), addr.getPort(),
                    decodedBasePath, null, null);
        } catch (URISyntaxException ex) {
            throw new IllegalArgumentException(ex);
        }
           
        final URI requestUri = baseUri.resolve(exchangeUri);
                       
        final ContainerRequest cRequest = new ContainerRequest(
                _application,
                exchange.getRequestMethod(),
                baseUri,
                requestUri,
                getHeaders(exchange),
                exchange.getRequestBody()
                );
       
        try {
            _application.handleRequest(cRequest, new Writer(exchange));
        } catch (RuntimeException e) {
            e.printStackTrace();
            exchange.getResponseHeaders().clear();
            exchange.sendResponseHeaders(500, -1);
        }  
View Full Code Here

            return contentLength;
        }
    }
   
    public void handle(HttpExchange exchange) throws IOException {
        WebApplication _application = application;
               
        /**
         * This is a URI that contains the path, query and
         * fragment components.
         */
        URI exchangeUri = exchange.getRequestURI();
       
        /**
         * The base path specified by the HTTP context of the HTTP handler.
         * It is in decoded form.
         */
        String decodedBasePath = exchange.getHttpContext().getPath();
       
        // Ensure that the base path ends with a '/'
        if (!decodedBasePath.endsWith("/")) {
            if (decodedBasePath.equals(exchangeUri.getPath())) {
                /**
                 * This is an edge case where the request path
                 * does not end in a '/' and is equal to the context
                 * path of the HTTP handler.
                 * Both the request path and base path need to end in a '/'
                 * Currently the request path is modified.
                 * TODO support redirection in accordance with resource
                 * configuration feature.
                 */
                exchangeUri = UriBuilder.fromUri(exchangeUri).
                        path("/").build();
            }
            decodedBasePath += "/";               
        }

        /*
         * The following is madness, there is no easy way to get
         * the complete URI of the HTTP request!!
         *
         * TODO this is missing the user information component, how
         * can this be obtained?
         */
        String scheme = (exchange instanceof HttpsExchange) ? "https" : "http";

        URI baseUri = null;
        try {
            List<String> hostHeader = exchange.getRequestHeaders().get("Host");
            if (hostHeader != null) {
                StringBuilder sb = new StringBuilder(scheme);
                sb.append("://").append(hostHeader.get(0)).append(decodedBasePath);
                baseUri = new URI(sb.toString());
            } else {
                InetSocketAddress addr = exchange.getLocalAddress();
                baseUri = new URI(scheme, null, addr.getHostName(), addr.getPort(),
                        decodedBasePath, null, null);
            }
        } catch (URISyntaxException ex) {
            throw new IllegalArgumentException(ex);
        }
           
        final URI requestUri = baseUri.resolve(exchangeUri);
                       
        final ContainerRequest cRequest = new ContainerRequest(
                _application,
                exchange.getRequestMethod(),
                baseUri,
                requestUri,
                getHeaders(exchange),
                exchange.getRequestBody()
                );
       
        try {
            _application.handleRequest(cRequest, new Writer(exchange));
        } catch (RuntimeException e) {
            e.printStackTrace();
            exchange.getResponseHeaders().clear();
            exchange.sendResponseHeaders(500, -1);
        } catch (IOException ex) {
View Full Code Here

    }
   
    // ContainerListener
   
    public void onReload() {
        WebApplication oldApplication = application;
        application = application.clone();
        oldApplication.destroy();
    }
View Full Code Here

        public void finish() throws IOException {           
        }
    }
   
    public void service(GrizzlyRequest request, GrizzlyResponse response) {
        WebApplication _application = application;
       
        final URI baseUri = getBaseUri(request);
        /*
         * request.unparsedURI() is a URI in encoded form that contains
         * the URI path and URI query components.
         */
        final URI requestUri = baseUri.resolve(
                request.getRequest().unparsedURI().toString());

        /**
         * Check if the request URI path starts with the base URI path
         */
        if (!requestUri.getRawPath().startsWith(basePath)) {
            response.setStatus(404);
            return;
        }

        try {
            final ContainerRequest cRequest = new ContainerRequest(
                    _application,
                    request.getMethod(),
                    baseUri,
                    requestUri,
                    getHeaders(request),
                    request.getInputStream());
           
            _application.handleRequest(cRequest, new Writer(response));
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here

    }
   
    // ContainerListener
   
    public void onReload() {
        WebApplication oldApplication = application;
        application = application.clone();
        oldApplication.destroy();
    }   
View Full Code Here

            final HttpServletResponse response)
            throws ServletException, IOException {
        // 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 = new ContainerRequest(
                _application,
                request.getMethod(),
                baseUri,
                requestUri,
                getHeaders(request),
                request.getInputStream());
        cRequest.setSecurityContext(new SecurityContext() {
            public Principal getUserPrincipal() {
                return request.getUserPrincipal();
            }

            public boolean isUserInRole(String role) {
                return request.isUserInRole(role);
            }

            public boolean isSecure() {
                return request.isSecure();
            }

            public String getAuthenticationScheme() {
                return request.getAuthType();
            }
        });

        // Check if any servlet filters have consumed a request entity
        // of the media type application/x-www-form-urlencoded
        // This can happen if a filter calls request.getParameter(...)
        filterFormParameters(request, cRequest);

        try {
            UriRuleProbeProvider.requestStart(requestUri);

            requestInvoker.set(request);
            responseInvoker.set(response);

            final Writer w = new Writer(useSendError, response);
            _application.handleRequest(cRequest, w);
            return w.cResponse.getStatus();
        } catch (MappableContainerException ex) {
            traceOnException(cRequest, response);
            throw new ServletException(ex.getCause());
        } catch (ContainerException ex) {
View Full Code Here

    /**
     * Load the Web application. This will create, configure and initiate
     * the web application.
     */
    public void load() {
        WebApplication _application = create();
        configure(config, resourceConfig, _application);
        initiate(resourceConfig, _application);
        application = _application;
    }
View Full Code Here

TOP

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

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.