Package org.mortbay.jetty.servlet

Examples of org.mortbay.jetty.servlet.ServletHandler


    }

    private void setUpHttpServer() throws IOException {
        addListener(":" + port);
        HttpContext context = getContext("/jsunit");
        ServletHandler handler;
        handler = new ServletHandler();
        handler.addServlet("JsUnitResultAcceptor", "/acceptor", ResultAcceptorServlet.class.getName());
        handler.addServlet("JsUnitResultDisplayer", "/displayer", ResultDisplayerServlet.class.getName());
        handler.addServlet("JsUnitTestRunner", "/runner", TestRunnerServlet.class.getName());
        context.addHandler(handler);
        context.setResourceBase(resourceBase.toString());
        context.addHandler(new ResourceHandler());
        addContext(context);
        JsUnitServlet.setServer(this);
View Full Code Here


                //contextHandler.setContextPath(contextPath);
                contextHandler.setContextPath("/");
                server.setHandler(contextHandler);

                SessionHandler sessionHandler = new SessionHandler();
                ServletHandler servletHandler = new ServletHandler();
                sessionHandler.addHandler(servletHandler);

                contextHandler.setHandler(sessionHandler);

                server.setStopAtShutdown(true);
                server.setSendServerVersion(sendServerVersion);
                server.start();

                // Keep track of the new server and Servlet handler
                port = new Port(server, servletHandler);
                ports.put(portNumber, port);

            } catch (Exception e) {
                throw new ServletMappingException(e);
            }
        }

        // Register the Servlet mapping
        ServletHandler servletHandler = port.getServletHandler();
        ServletHolder holder;
        if (servlet instanceof DefaultResourceServlet) {

            // Optimize the handling of resource requests, use the Jetty default Servlet
            // instead of our default resource Servlet
            String servletPath = uri.getPath();
            if (servletPath.endsWith("*")) {
                servletPath = servletPath.substring(0, servletPath.length() - 1);
            }
            if (servletPath.endsWith("/")) {
                servletPath = servletPath.substring(0, servletPath.length() - 1);
            }
            if (!servletPath.startsWith("/")) {
                servletPath = '/' + servletPath;
            }

            DefaultResourceServlet resourceServlet = (DefaultResourceServlet)servlet;
            DefaultServlet defaultServlet = new JettyDefaultServlet(servletPath, resourceServlet.getDocumentRoot());
            holder = new ServletHolder(defaultServlet);

        } else {
            holder = new ServletHolder(servlet);
        }
        servletHandler.addServlet(holder);

        ServletMapping mapping = new ServletMapping();
        mapping.setServletName(holder.getName());
        String path = uri.getPath();

        if (!path.startsWith("/")) {
            path = '/' + path;
        }

        if (!path.startsWith(contextPath)) {
            path = contextPath + path;
        }

        mapping.setPathSpec(path);
        servletHandler.addServletMapping(mapping);

        // Compute the complete URL
        if (host == null) {
            try {
                host = InetAddress.getLocalHost().getHostAddress();
View Full Code Here

        if (port == null) {
            return null;
        }

        // Remove the Servlet mapping for the given Servlet
        ServletHandler servletHandler = port.getServletHandler();
        Servlet servlet = null;
        List<ServletMapping> mappings =
            new ArrayList<ServletMapping>(Arrays.asList(servletHandler.getServletMappings()));
        String path = uri.getPath();

        if (!path.startsWith("/")) {
            path = '/' + path;
        }

        if (!path.startsWith(contextPath)) {
            path = contextPath + path;
        }

        for (ServletMapping mapping : mappings) {
            if (Arrays.asList(mapping.getPathSpecs()).contains(path)) {
                try {
                    servlet = servletHandler.getServlet(mapping.getServletName()).getServlet();
                } catch (ServletException e) {
                    throw new IllegalStateException(e);
                }
                break;
            }
View Full Code Here

            logger.warning("No servlet registered at this URI: " + suri);
            return null;
        }

        // Remove the Servlet mapping for the given Servlet
        ServletHandler servletHandler = port.getServletHandler();
        Servlet removedServlet = null;
        List<ServletMapping> mappings =
            new ArrayList<ServletMapping>(Arrays.asList(servletHandler.getServletMappings()));
        String path = uri.getPath();

        if (!path.startsWith("/")) {
            path = '/' + path;
        }

        if (!path.startsWith(contextPath)) {
            path = contextPath + path;
        }

        for (ServletMapping mapping : mappings) {
            if (Arrays.asList(mapping.getPathSpecs()).contains(path)) {
                try {
                    removedServlet = servletHandler.getServlet(mapping.getServletName()).getServlet();
                } catch (ServletException e) {
                    throw new IllegalStateException(e);
                }
                mappings.remove(mapping);
                logger.info("Removed Servlet mapping: " + path);
                break;
            }
        }
        if (removedServlet != null) {
            servletHandler.setServletMappings(mappings.toArray(new ServletMapping[mappings.size()]));

            // Stop the port if there are no servlet mappings on it anymore
            if (mappings.size() == 0) {
                try {
                    Server server = port.getServer();
View Full Code Here

                ContextHandler contextHandler = new ContextHandler();
                contextHandler.setContextPath(ROOT);
                server.setHandler(contextHandler);

                SessionHandler sessionHandler = new SessionHandler();
                servletHandler = new ServletHandler();
                sessionHandler.addHandler(servletHandler);

                contextHandler.setHandler(sessionHandler);

                server.setStopAtShutdown(true);
View Full Code Here

                //contextHandler.setContextPath(contextPath);
                contextHandler.setContextPath("/");
                server.setHandler(contextHandler);
   
                SessionHandler sessionHandler = new SessionHandler();
                ServletHandler servletHandler = new ServletHandler();
                sessionHandler.addHandler(servletHandler);
   
                contextHandler.setHandler(sessionHandler);
   
                server.setStopAtShutdown(true);
                server.setSendServerVersion(sendServerVersion);
                server.start();
               
                // Keep track of the new server and Servlet handler
                port = new Port(server, servletHandler);
                ports.put(portNumber, port);
               
            } catch (Exception e) {
                throw new ServletMappingException(e);
            }
        }

        // Register the Servlet mapping
        ServletHandler servletHandler = port.getServletHandler();
        ServletHolder holder;
        if (servlet instanceof DefaultResourceServlet) {
           
            // Optimize the handling of resource requests, use the Jetty default Servlet
            // instead of our default resource Servlet
            String servletPath = uri.getPath();
            if (servletPath.endsWith("*")) {
                servletPath = servletPath.substring(0, servletPath.length()-1);
            }
            if (servletPath.endsWith("/")) {
                servletPath = servletPath.substring(0, servletPath.length()-1);
            }         
            if (!servletPath.startsWith("/")) {
                servletPath = '/' + servletPath;
            }    
      
            DefaultResourceServlet resourceServlet = (DefaultResourceServlet)servlet;
            DefaultServlet defaultServlet = new JettyDefaultServlet(servletPath, resourceServlet.getDocumentRoot());
            holder = new ServletHolder(defaultServlet);
           
        } else {
            holder = new ServletHolder(servlet);
        }
        servletHandler.addServlet(holder);
       
        ServletMapping mapping = new ServletMapping();
        mapping.setServletName(holder.getName());
        String path = uri.getPath();
       
        if (!path.startsWith("/")) {
            path = '/' + path;
        }
       
        if (!path.startsWith(contextPath)) {
            path = contextPath + path;
       
               
        mapping.setPathSpec(path);
        servletHandler.addServletMapping(mapping);
       
        // Compute the complete URL
        String host;
        try {
            host = InetAddress.getLocalHost().getHostName();
View Full Code Here

        if (port == null) {
            return null;
        }
       
        // Remove the Servlet mapping for the given Servlet
        ServletHandler servletHandler = port.getServletHandler();
        Servlet servlet = null;
        List<ServletMapping> mappings =
            new ArrayList<ServletMapping>(Arrays.asList(servletHandler.getServletMappings()));
        String path = uri.getPath();
       
        if (!path.startsWith("/")) {
            path = '/' + path;
        }
       
        if (!path.startsWith(contextPath)) {
            path = contextPath + path;
        }
       
        for (ServletMapping mapping : mappings) {
            if (Arrays.asList(mapping.getPathSpecs()).contains(path)) {
                try {
                    servlet = servletHandler.getServlet(mapping.getServletName()).getServlet();
                } catch (ServletException e) {
                    throw new IllegalStateException(e);
                }
                break;
            }
View Full Code Here

        if (port == null) {
            throw new IllegalStateException("No servlet registered at this URI: " + suri);
        }
       
        // Remove the Servlet mapping for the given Servlet
        ServletHandler servletHandler = port.getServletHandler();
        Servlet removedServlet = null;
        List<ServletMapping> mappings =
            new ArrayList<ServletMapping>(Arrays.asList(servletHandler.getServletMappings()));
        String path = uri.getPath();
       
        if (!path.startsWith("/")) {
            path = '/' + path;
        }
       
        if (!path.startsWith(contextPath)) {
            path = contextPath + path;
        }
       
        for (ServletMapping mapping : mappings) {
            if (Arrays.asList(mapping.getPathSpecs()).contains(path)) {
                try {
                    removedServlet = servletHandler.getServlet(mapping.getServletName()).getServlet();
                } catch (ServletException e) {
                    throw new IllegalStateException(e);
                }
                mappings.remove(mapping);
                //logger.info("Removed Servlet mapping: " + path);
                break;
            }
        }
        if (removedServlet != null) {
            servletHandler.setServletMappings(mappings.toArray(new ServletMapping[mappings.size()]));
           
            // Stop the port if there are no servlet mappings on it anymore
            if (mappings.size() == 0) {
                try {
                    port.getServer().stop();
View Full Code Here

        server.setHandler(context_handler);

        SessionHandler session_handler = new SessionHandler();
        context_handler.setHandler(session_handler);
       
        ServletHandler servlet_handler = new ServletHandler();
        session_handler.setHandler(servlet_handler);

        ServletHolder holder = new ServletHolder();
        holder.setName("httpTunnel");
        holder.setClassName(HttpTunnelServlet.class.getName());
        servlet_handler.setServlets(new ServletHolder[] { holder });

        ServletMapping mapping = new ServletMapping();
        mapping.setServletName("httpTunnel");
        mapping.setPathSpec("/*");
        servlet_handler.setServletMappings(new ServletMapping[] { mapping });

        context_handler.setAttribute("acceptListener", getAcceptListener());
        context_handler.setAttribute("wireFormat", getWireFormat());
        server.start();
    }
View Full Code Here

        ContextHandler context = new ContextHandler();
        context.setContextPath( snapshots.context );
        context.setAttribute( "dirAllowed", true );
        context.setAttribute( "maxCacheSize", 0 );
        context.setResourceBase( snapshots.root.getAbsolutePath() );
        ServletHandler servlet = new ServletHandler();
        servlet.addServletWithMapping( DefaultServlet.class.getName(), "/" );
        context.setHandler( servlet );
        contexts.addHandler( context );

        snapshots.server.start();
View Full Code Here

TOP

Related Classes of org.mortbay.jetty.servlet.ServletHandler

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.