Package org.glassfish.grizzly.servlet

Examples of org.glassfish.grizzly.servlet.WebappContext


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

        WebappContext context = new WebappContext("GrizzlyContext", path);
        ServletRegistration registration = context.addServlet(c.getName(), c);
        registration.addMapping("");
        if (initParams == null) {
            registration.setInitParameter(ClasspathResourceConfig.PROPERTY_CLASSPATH,
                    System.getProperty("java.class.path").replace(File.pathSeparatorChar, ';'));
        } else {
            registration.setInitParameters(initParams);
        }

        HttpServer server = GrizzlyServerFactory.createHttpServer(u);
        context.deploy(server);
        return server;
    }
View Full Code Here


* so that its service method is invoked whenever a request maps to this Adapter
*/
public class EjbWSAdapter extends ServletHandler {

    public EjbWSAdapter() {
        super(new EjbWSServletConfig(new WebappContext("EjbWSAdapter")));
        this.setServletInstance(new EjbWebServiceServlet());
        try {
            this.servletInstance.init(getServletConfig());
        } catch (Exception ignored) {
        }
View Full Code Here

    }

    protected static void startServer() {

        // add Jersey resource servlet
        WebappContext context = new WebappContext("context");
        ServletRegistration registration =
                context.addServlet("ServletContainer", ServletContainer.class);
        registration.setInitParameter("com.sun.jersey.config.property.packages",
                "com.sun.jersey.samples.https_grizzly.resource;com.sun.jersey.samples.https_grizzly.auth");

        // add security filter (which handles http basic authentication)
        registration.setInitParameter(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
                SecurityFilter.class.getName());

        // Grizzly ssl configuration
        SSLContextConfigurator sslContext = new SSLContextConfigurator();
       
        // set up security context
        sslContext.setKeyStoreFile("./keystore_server"); // contains server keypair
        sslContext.setKeyStorePass("asdfgh");
        sslContext.setTrustStoreFile("./truststore_server"); // contains client certificate
        sslContext.setTrustStorePass("asdfgh");

        try {

            webServer = GrizzlyServerFactory.createHttpServer(
                    getBaseURI(),
                    null,
                    true,
                    new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true)
            );

            // start Grizzly embedded server //
            System.out.println("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
            context.deploy(webServer);
            webServer.start();

        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
View Full Code Here

                servletPathLocal += "*";
            } else {
                servletPathLocal += "/*";
            }

            final WebappContext context = new WebappContext("TestContext", contextPathLocal);

            // servlet class and servlet instance can be both null or one of them is specified exclusively.
            final HttpServlet servletInstance = deploymentContext.getServletInstance();
            final Class<? extends HttpServlet> servletClass = deploymentContext.getServletClass();
            if (servletInstance != null || servletClass != null) {
                final ServletRegistration registration;
                if (servletInstance != null) {
                    registration = context.addServlet(servletInstance.getClass().getName(), servletInstance);
                } else {
                    registration = context.addServlet(servletClass.getName(), servletClass);
                }
                registration.setInitParameters(deploymentContext.getInitParams());
                registration.addMapping(servletPathLocal);
            }

            for (final Class<? extends EventListener> eventListener : deploymentContext.getListeners()) {
                context.addListener(eventListener);
            }

            final Map<String, String> contextParams = deploymentContext.getContextParams();
            for (final String contextParamName : contextParams.keySet()) {
                context.addContextInitParameter(contextParamName, contextParams.get(contextParamName));
            }

            // Filter support
            if (deploymentContext.getFilters() != null) {
                for (final ServletDeploymentContext.FilterDescriptor filterDescriptor : deploymentContext.getFilters()) {

                    final FilterRegistration filterRegistration =
                            context.addFilter(filterDescriptor.getFilterName(), filterDescriptor.getFilterClass());

                    filterRegistration.setInitParameters(filterDescriptor.getInitParams());
                    filterRegistration.addMappingForUrlPatterns(
                            grizzlyDispatcherTypes(filterDescriptor.getDispatcherTypes()),
                            true,
                            servletPathLocal);
                }
            }

            try {
                server = GrizzlyHttpServerFactory.createHttpServer(baseUri, (GrizzlyHttpContainer) null, false, null, false);
                context.deploy(server);
            } catch (final ProcessingException ex) {
                throw new TestContainerException(ex);
            }
        }
View Full Code Here

            throw new IllegalArgumentException("The URI path, of the URI " + u + ". must start with a '/'");
        }

        path = String.format("/%s", UriComponent.decodePath(u.getPath(), true).get(1).toString());

        WebappContext context = new WebappContext("GrizzlyContext", path);
        ServletRegistration registration;
        if (c != null) {
            registration = context.addServlet(c.getName(), c);
        } else {
            registration = context.addServlet(servlet.getClass().getName(), servlet);
        }
        registration.addMapping("/*");

        if (contextInitParams != null) {
            for (Map.Entry<String, String> e : contextInitParams.entrySet()) {
                context.setInitParameter(e.getKey(), e.getValue());
            }
        }

        if (initParams != null) {
            registration.setInitParameters(initParams);
        }

        HttpServer server = GrizzlyHttpServerFactory.createHttpServer(u);
        context.deploy(server);
        return server;
    }
View Full Code Here

            throw new IllegalArgumentException("The URI path, of the URI " + u + ". must start with a '/'");
        }

        path = String.format("/%s", UriComponent.decodePath(u.getPath(), true).get(1).toString());

        WebappContext context = new WebappContext("GrizzlyContext", path);
        ServletRegistration registration = context.addServlet(c.getName(), c);
        registration.addMapping("");
        if (initParams == null) {
//            registration.setInitParameter(ClassPathResourceConfig.PROPERTY_CLASSPATH,
//                    System.getProperty("java.class.path").replace(File.pathSeparatorChar, ';'));
        } else {
            registration.setInitParameters(initParams);
        }

        HttpServer server = GrizzlyHttpServerFactory.createHttpServer(u);
        context.deploy(server);
        return server;
    }
View Full Code Here

    HttpServer ws = new HttpServer();
    ws.getHttpHandler().setAllowEncodedSlash(true);
    ws.addListener(new NetworkListener("web",listenInterface,port));
    DovetaildbServlet ddbServlet = new DovetaildbServlet();
   
    WebappContext webappContext = new WebappContext("webapp", "/");
    ServletRegistration reg = webappContext.addServlet("dovetaildb", ddbServlet);
    reg.setInitParameter("headerFile", headerFile.getAbsolutePath());
    reg.setInitParameter("logLevel", logLevel.getName());
    reg.addMapping("/*");
    reg.setLoadOnStartup(1);
    webappContext.deploy(ws);

    System.out.println();
    System.out.println("  .:::::::::.");
    System.out.println("   ::::::::: ");
    System.out.println("  .   ...   .    DovetailDB");
View Full Code Here

                }
            } else {
                servletPathLocal = "/*";
            }

            WebappContext context =
                    new WebappContext("TestContext", contextPathLocal);

            if (servletClass != null) {
                ServletRegistration registration =
                        context.addServlet(servletClass.getName(), servletClass);
                for(String initParamName : initParams.keySet()) {
                    registration.setInitParameter(initParamName, initParams.get(initParamName));
                }


                registration.addMapping(servletPathLocal);
            } else {
                ServletRegistration registration =
                        context.addServlet("default", new HttpServlet() {
                            @Override
                            protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
                                resp.setStatus(404);
                            }
                        });
                registration.addMapping("");
            }

            for(Class<? extends EventListener> eventListener : eventListeners) {
                context.addListener(eventListener);
            }

            for(String contextParamName : contextParams.keySet()) {
                context.addContextInitParameter(contextParamName, contextParams.get(contextParamName));
            }

            // Filter support
            if ( filters!=null ) {
                for (WebAppDescriptor.FilterDescriptor d : this.filters) {
                    FilterRegistration freg = context.addFilter(d.getFilterName(), d.getFilterClass());
                    freg.setInitParameters(d.getInitParams());
                    freg.addMappingForUrlPatterns(null, servletPathLocal);
                }
            }

            try {
                httpServer = GrizzlyServerFactory.createHttpServer(baseUri, (HttpHandler) null);
                context.deploy(httpServer);
            } catch(IOException ioe) {
                throw new TestContainerException(ioe);
            }
        }
View Full Code Here

        return defaultPort;
    }

    protected static void startServer() {
      // add CXF resource servlet
        WebappContext context = new WebappContext("context");
        ServletRegistration registration =
            context.addServlet("ServletContainer", CXFServlet.class);
        context.addListener("org.springframework.web.context.ContextLoaderListener");
        context.addContextInitParameter("contextConfigLocation", "beans.xml");

        // Grizzly ssl configuration
        SSLContextConfigurator sslContext = new SSLContextConfigurator();
       
        // set up security context
        sslContext.setKeyStoreFile("./keystore_server"); // contains server keypair
        sslContext.setKeyStorePass("asdfgh");
        sslContext.setTrustStoreFile("./truststore_server"); // contains client certificate
        sslContext.setTrustStorePass("asdfgh");

        try {

            webServer = new HttpServer();
            NetworkListener listener = new NetworkListener("grizzly",
                getBaseURI().getHost(),
                getBaseURI().getPort());
            listener.setSecure(true);
            listener.setSSLEngineConfig(
                new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true));
            webServer.addListener(listener);
           
//            ServerConfiguration config = webServer.getServerConfiguration();
//            config.addHttpHandler(cxfAdapter, getBaseURI().getPath());           
           
            // start Grizzly embedded server //
            System.out.println("CXF app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
            context.deploy(webServer);
            webServer.start();

        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
View Full Code Here

        metricRegistry.remove(MetricRegistry.name("http", "core", metricGroup, jmxAttributeName));
    }

    private void deployRestApi(final RexsterApplication application) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        if (hasAnythingChanged()) {
            wacJersey = new WebappContext("jersey", "");

            // explicitly load resources so that the "RexsterApplicationProvider" class is not loaded
            final ResourceConfig rc = constructResourceConfig();

            // constructs an injectable for the RexsterApplication instance.  This get constructed externally
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.servlet.WebappContext

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.