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

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


                Port port = entry.getValue();
                port.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

                Port port = entry.getValue();
                port.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

                    port.getConnector().stop();
                    port.getEngine().stop();
                    ports.remove(entry.getKey());
                }
            } catch (Exception e) {
                throw new ServletMappingException(e);
            }
        }
    }
View Full Code Here

                        return null;
                    }
                });
            } catch (PrivilegedActionException e) {
                // throw (LifecycleException)e.getException();
                throw new ServletMappingException(e);
            }
            Connector connector;
            // Allow privileged access to read properties. Requires PropertiesPermission read in
            // security policy.
            try {
                final String protocol = scheme;
                connector = AccessController.doPrivileged(new PrivilegedExceptionAction<CustomConnector>() {
                    public CustomConnector run() throws Exception {
                        CustomConnector customConnector = new CustomConnector();
                        customConnector.setPort(portNumber);
                        customConnector.setContainer(engine);

                        if ("https".equalsIgnoreCase(protocol)) {
                            configureSSL(customConnector);
                            ((Http11Protocol) customConnector.getProtocolHandler()).setSSLEnabled(true);
                        }
                        customConnector.initialize();
                        customConnector.start();
                        return customConnector;
                    }

                    private void configureSSL(CustomConnector customConnector) {
                        String trustStore = System.getProperty("javax.net.ssl.trustStore");
                        String trustStorePass = System.getProperty("javax.net.ssl.trustStorePassword");
                        String keyStore = System.getProperty("javax.net.ssl.keyStore");
                        String keyStorePass = System.getProperty("javax.net.ssl.keyStorePassword");

                        customConnector.setProperty("protocol", "TLS");

                        customConnector.setProperty("keystore", keyStore);
                        customConnector.setProperty("keypass", keyStorePass);
                        String keyStoreType =
                            System.getProperty("javax.net.ssl.keyStoreType", KeyStore.getDefaultType());
                        String trustStoreType =
                            System.getProperty("javax.net.ssl.trustStoreType", KeyStore.getDefaultType());
                        customConnector.setProperty("keytype", keyStoreType);
                        customConnector.setProperty("trusttype", trustStoreType);
                        customConnector.setProperty("truststore", trustStore);
                        customConnector.setProperty("trustpass", trustStorePass);

                        customConnector.setProperty("clientauth", "false");
                        customConnector.setProtocol("HTTP/1.1");
                        customConnector.setScheme(protocol);
                        customConnector.setProperty("backlog", "10");
                        customConnector.setSecure(true);
                    }
                });
            } catch (Exception e) {
                throw new ServletMappingException(e);
            }
            // Keep track of the running server
            port = new Port(engine, host, connector);
            ports.put(portNumber, port);
        }

        // Register the Servlet mapping
        String path = uri.getPath();

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

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

        ServletWrapper wrapper;
        if (servlet instanceof DefaultResourceServlet) {
            String defaultServletPath = path;

            // Optimize the handling of resource requests, use the Tomcat default Servlet
            // instead of our default resource Servlet
            if (defaultServletPath.endsWith("*")) {
                defaultServletPath = defaultServletPath.substring(0, defaultServletPath.length() - 1);
            }
            if (defaultServletPath.endsWith("/")) {
                defaultServletPath = defaultServletPath.substring(0, defaultServletPath.length() - 1);
            }
            DefaultResourceServlet resourceServlet = (DefaultResourceServlet)servlet;
            TomcatDefaultServlet defaultServlet =
                new TomcatDefaultServlet(defaultServletPath, resourceServlet.getDocumentRoot());
            wrapper = new ServletWrapper(defaultServlet);

        } else {
            wrapper = new ServletWrapper(servlet);
        }
        Context context = port.getHost().map(path);
        wrapper.setName(path);
        wrapper.addMapping(path);
        context.addChild(wrapper);
        context.addServletMapping(path, path);
        port.getConnector().getMapper().addWrapper("localhost", "", path, wrapper);

        // Initialize the Servlet
        try {
            wrapper.initServlet();
        } catch (ServletException e) {
            throw new ServletMappingException(e);
        }

        // 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

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.