Package com.sun.jersey.spi.container

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


*/
public class WebApplicationImplTest {

    @Test
    public void testInstantiatesWebApplicationImpl() {
        WebApplication app = new WebApplicationImpl();
        assertFalse(app.isInitiated());
    }
View Full Code Here


     */
    @SuppressWarnings("unchecked")
    public static <A> A createContainer(Class<A> type, ResourceConfig resourceConfig,
            IoCComponentProviderFactory factory)
    throws ContainerException, IllegalArgumentException {
        WebApplication wa = WebApplicationFactory.createWebApplication();
       
        // Reverse the order so that applications may override
        LinkedList<ContainerProvider> cps = new LinkedList<ContainerProvider>();
        for (ContainerProvider cp : ServiceFinder.find(ContainerProvider.class, true))
            cps.addFirst(cp);
       
        for (ContainerProvider<A> cp : cps) {
            A c = cp.createContainer(type, resourceConfig, wa);
            if (c != null) {
                // Initiate the web application
                if (!wa.isInitiated()) {
                    wa.initiate(resourceConfig, factory);
                }

                // Register a container listener
                Object o = resourceConfig.getProperties().get(
                        ResourceConfig.PROPERTY_CONTAINER_NOTIFIER);
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 = createRequest(
                _application,
                request,
                baseUri,
                requestUri);

        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(useSetStatusOn404, 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

     * <p/>
     * If this method is called when there are pending requests then such
     * requests will be processed using the previously loaded web application.
     */
    public void onReload() {
        WebApplication oldApplication = application;
        WebApplication newApplication = create();
        initiate(resourceConfig, newApplication);
        application = newApplication;

        if (resourceConfig instanceof ReloadListener)
            ((ReloadListener) resourceConfig).onReload();
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();

        if (application.getFeaturesAndProperties() instanceof ReloadListener)
            ((ReloadListener) application.getFeaturesAndProperties()).onReload();

        oldApplication.destroy();
    }
View Full Code Here

                webApp.destroy();
            }
        }

        private WebApplication initiateWebApplication(ResourceConfig rc) {
            WebApplication webapp = WebApplicationFactory.createWebApplication();
            return webapp;
        }
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 = createRequest(
                _application,
                request,
                baseUri,
                requestUri);

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

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

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

            @Override
      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(useSetStatusOn404, 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.