Package org.apache.tuscany.sca.host.http

Examples of org.apache.tuscany.sca.host.http.ServletMappingException


                server.stop();
                server.setStopAtShutdown(false);
                ports.remove(entry.getKey());
            }
        } catch (Exception e) {
            throw new ServletMappingException(e);
        } finally {
            if (jettyLogger != null) {
                Log.setLog(jettyLogger);
                jettyLogger = null;
            }
View Full Code Here


                // 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();
            } catch (UnknownHostException e) {
                host = "localhost";
            }
        }
        URL addedURL;
        try {
            addedURL = new URL(scheme, host, portNumber, path);
        } catch (MalformedURLException e) {
            throw new ServletMappingException(e);
        }
        logger.info("Added Servlet mapping: " + addedURL);
        return addedURL.toString();
    }
View Full Code Here

        URL url;
        try {
            url = new URL(scheme, host, portNumber, path);
        } catch (MalformedURLException e) {
            throw new ServletMappingException(e);
        }
        return url;
    }
View Full Code Here

        if (!servlets.values().contains(servlet)) {
            // The same servlet can be registred more than once
            try {
                servlet.init(servletConfig);
            } catch (ServletException e) {
                throw new ServletMappingException(e);
            }
        }

        // In a webapp just use the given path and ignore the host and port
        // as they are fixed by the Web container
View Full Code Here

        URL url;
        try {
            url = new URL(scheme, host, portNumber, path);
        } catch (MalformedURLException e) {
            throw new ServletMappingException(e);
        }
        return url;
    }
View Full Code Here

                for (Entry<Integer, Port> entry: entries) {
                    entry.getValue().getServer().stop();
                    ports.remove(entry.getKey());
                }
            } catch (Exception e) {
                throw new ServletMappingException(e);
            }
        }
    }
View Full Code Here

                // 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();
        } catch (UnknownHostException e) {
            host = "localhost";
        }
        URL addedURL;
        try {
            addedURL = new URL(scheme, host, portNumber, path);
        } catch (MalformedURLException e) {
            throw new ServletMappingException(e);
        }
        logger.info("Added Servlet mapping: " + addedURL);
    }
View Full Code Here

        URL url;
        try {
            url = new URL(scheme, host, portNumber, path);
        } catch (MalformedURLException e) {
            throw new ServletMappingException(e);
        }
        return url;
    }
View Full Code Here

        URL url;
        try {
            url = new URL(scheme, host, portNumber, path);
        } catch (MalformedURLException e) {
            throw new ServletMappingException(e);
        }
        return url;
    }
View Full Code Here

        URL url;
        try {
            url = new URL(scheme, host, portNumber, path);
        } catch (MalformedURLException e) {
            throw new ServletMappingException(e);
        }
        return url;
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.host.http.ServletMappingException

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.