Package org.glassfish.grizzly.servlet

Examples of org.glassfish.grizzly.servlet.ServletHandler


        /**
         * Instantiates the Grizzly 2 Web Server
         */
        private void instantiateGrizzlyWebServer() {

            final ServletHandler handler = new ServletHandler();

            Servlet servletInstance;
            if( servletClass != null) {
                try {
                    servletInstance = (Servlet) servletClass.newInstance();
                } catch (InstantiationException ex) {
                    throw new TestContainerException(ex);
                } catch (IllegalAccessException ex) {
                    throw new TestContainerException(ex);
                }
                handler.setServletInstance(servletInstance);
            }

            for(Class<? extends EventListener> eventListener : eventListeners) {
                handler.addServletListener(eventListener.getName());
            }

            for(String contextParamName : contextParams.keySet()) {
                handler.addContextParameter(contextParamName, contextParams.get(contextParamName));
            }

            for(String initParamName : initParams.keySet()) {
                handler.addInitParameter(initParamName, initParams.get(initParamName));
            }

            if(contextPath != null && contextPath.length() > 0) {
                if( !contextPath.startsWith("/") ) {
                    handler.setContextPath("/" + contextPath);
                } else {
                    handler.setContextPath(contextPath);
                }
            }

            if(servletPath != null && servletPath.length() > 0) {
                if( !servletPath.startsWith("/") ) {
                    handler.setServletPath("/" + servletPath);
                } else {
                    handler.setServletPath(servletPath);
                }
            }

            // Filter support
            if ( filters!=null ) {
                try {
                    for(WebAppDescriptor.FilterDescriptor d : this.filters) {
                        handler.addFilter(d.getFilterClass().newInstance(), d.getFilterName(), d.getInitParams());
                    }
                } catch (InstantiationException ex) {
                    throw new TestContainerException(ex);
                } catch (IllegalAccessException ex) {
                    throw new TestContainerException(ex);
View Full Code Here


    protected static void startServer() {

        // add Jersey resource servlet

        ServletHandler jerseyAdapter = new ServletHandler();
        jerseyAdapter.addInitParameter("com.sun.jersey.config.property.packages",
                "com.sun.jersey.samples.https_grizzly.resource;com.sun.jersey.samples.https_grizzly.auth");
        jerseyAdapter.setContextPath("/");
        jerseyAdapter.setServletInstance(new ServletContainer());

        // add security filter (which handles http basic authentication)

        jerseyAdapter.addInitParameter(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
                SecurityFilter.class.getName());

        // Grizzly ssl configuration

        SSLContextConfigurator sslContext = new SSLContextConfigurator();
View Full Code Here

    public static HttpServer create(URI u, Class<? extends Servlet> c,
            Map<String, String> initParams) throws IOException {
        if (u == null)
            throw new IllegalArgumentException("The URI must not be null");

        final ServletHandler handler = new ServletHandler();
        if (initParams == null) {
            handler.addInitParameter(ClasspathResourceConfig.PROPERTY_CLASSPATH,
                     System.getProperty("java.class.path").replace(File.pathSeparatorChar, ';'));
        } else {
            for (Map.Entry<String, String> e : initParams.entrySet()) {
                handler.addInitParameter(e.getKey(), e.getValue());
            }
        }

        handler.setServletInstance(getInstance(c));

        String path = u.getPath();
        if (path == null)
            throw new IllegalArgumentException("The URI path, of the URI " + u +
                    ", must be non-null");
        else if (path.length() == 0)
            throw new IllegalArgumentException("The URI path, of the URI " + u +
                    ", must be present");
        else if (path.charAt(0) != '/')
            throw new IllegalArgumentException("The URI path, of the URI " + u +
                    ". must start with a '/'");

        if (path.length() > 1) {
            if (path.endsWith("/"))
                path = path.substring(0, path.length() - 1);
            handler.setContextPath(path);
        }

        return GrizzlyServerFactory.createHttpServer(u, handler);
    }
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.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.