Package com.sun.grizzly.config

Examples of com.sun.grizzly.config.GrizzlyEmbeddedHttp


            public void logVersion(){}  
        }, networkListener.getName());
        grizzlyListener.configure(networkListener, grizzlyService.habitat);

        if(!grizzlyListener.isGenericListener()) {
            final GrizzlyEmbeddedHttp embeddedHttp = grizzlyListener.getEmbeddedHttp();
            final Protocol httpProtocol = networkListener.findHttpProtocol();

            if (httpProtocol != null) {
                final V3Mapper mapper = new V3Mapper(logger);
                mapper.setPort(portNumber);
                mapper.setId(networkListener.getName());

                final ContainerMapper adapter = new ContainerMapper(grizzlyService, embeddedHttp);
                adapter.setMapper(mapper);
                adapter.setDefaultHost(grizzlyListener.getDefaultVirtualServer());
                adapter.configureMapper();
                embeddedHttp.setAdapter(adapter);

                String ct = httpProtocol.getHttp().getDefaultResponseType();
                adapter.setDefaultContentType(ct);
                final Collection<VirtualServer> list = grizzlyService.getHabitat().getAllByContract(VirtualServer.class);
                final String vsName = httpProtocol.getHttp().getDefaultVirtualServer();
                for (VirtualServer virtualServer : list) {
                    if (virtualServer.getId().equals(vsName)) {
                        vs = virtualServer;
                        embeddedHttp.setWebAppRootPath(vs.getDocroot());

                        if (!grizzlyService.hasMapperUpdateListener() &&
                                vs.getProperty() != null && !vs.getProperty().isEmpty()) {
                            for (Property p: vs.getProperty()){
                                String name = p.getName();
                                if (name.startsWith("alternatedocroot")){
                                    String value = p.getValue();
                                    String[] mapping = value.split(" ");

                                    if (mapping.length != 2){
                                        logger.log(Level.WARNING, "Invalid alternate_docroot " + value);
                                        continue;
                                    }

                                    String docBase = mapping[1].substring("dir=".length());
                                    String urlPattern = mapping[0].substring("from=".length());
                                    try {
                                        StaticResourcesAdapter a = new StaticResourcesAdapter();
                                        a.addRootFolder(docBase);
                                        ArrayList<String> al = toArray(vs.getHosts(),";");
                                        al.add(grizzlyListener.getDefaultVirtualServer());
                                        registerEndpoint(urlPattern,al , a, null);
                                    } catch (EndpointRegistrationException ex) {
                                        logger.log(Level.SEVERE, "Unable to set alternate_docroot", ex);
                                    }

                                }
                            }
                        }
                        break;
                    }
                }

                adapter.addRootFolder(embeddedHttp.getWebAppRootPath());
               
                Inhabitant<Mapper> onePortMapper = new ExistingSingletonInhabitant<Mapper>(mapper);
                grizzlyService.getHabitat().addIndex(onePortMapper,
                        Mapper.class.getName(), (networkListener.getAddress() + networkListener.getPort()));
                grizzlyService.notifyMapperUpdateListeners(networkListener, mapper);
            }
           
            boolean autoConfigure = false;
            // Avoid overriding the default with false
            if (System.getProperty(AUTO_CONFIGURE) != null){
                autoConfigure = true;
            }
            embeddedHttp.getController().setAutoConfigure(autoConfigure);

            boolean leaderFollower = false;
            // Avoid overriding the default with false
            if (System.getProperty(LEADER_FOLLOWER) != null){
                leaderFollower = true;
            }
            embeddedHttp.getController().useLeaderFollowerStrategy(leaderFollower);
        }
    }
View Full Code Here


        }

        grizzlyListener.configure(networkListener, grizzlyService.habitat);

        if(!grizzlyListener.isGenericListener()) {
            final GrizzlyEmbeddedHttp embeddedHttp = grizzlyListener.getEmbeddedHttp();

            if (httpProtocol != null) {
                final ContainerMapper adapter = new ContainerMapper(grizzlyService, embeddedHttp);
                adapter.setMapper(mapper);
                adapter.setDefaultHost(grizzlyListener.getDefaultVirtualServer());
                adapter.configureMapper();
                embeddedHttp.setAdapter(adapter);

                String ct = httpProtocol.getHttp().getDefaultResponseType();
                adapter.setDefaultContentType(ct);
                final Collection<VirtualServer> list = grizzlyService.getHabitat().getAllByContract(VirtualServer.class);
                final String vsName = httpProtocol.getHttp().getDefaultVirtualServer();
                for (VirtualServer virtualServer : list) {
                    if (virtualServer.getId().equals(vsName)) {
                        vs = virtualServer;
                        embeddedHttp.setWebAppRootPath(vs.getDocroot());

                        if (!grizzlyService.hasMapperUpdateListener() &&
                                vs.getProperty() != null && !vs.getProperty().isEmpty()) {
                            for (Property p: vs.getProperty()){
                                String name = p.getName();
                                if (name.startsWith("alternatedocroot")){
                                    String value = p.getValue();
                                    String[] mapping = value.split(" ");

                                    if (mapping.length != 2){
                                        logger.log(Level.WARNING, "Invalid alternate_docroot " + value);
                                        continue;
                                    }

                                    String docBase = mapping[1].substring("dir=".length());
                                    String urlPattern = mapping[0].substring("from=".length());
                                    try {
                                        StaticResourcesAdapter a = new StaticResourcesAdapter();
                                        a.addRootFolder(docBase);
                                        ArrayList<String> al = toArray(vs.getHosts(),";");
                                        al.add(grizzlyListener.getDefaultVirtualServer());
                                        registerEndpoint(urlPattern,al , a, null);
                                    } catch (EndpointRegistrationException ex) {
                                        logger.log(Level.SEVERE, "Unable to set alternate_docroot", ex);
                                    }

                                }
                            }
                        }
                        break;
                    }
                }

                adapter.addRootFolder(embeddedHttp.getWebAppRootPath());
                grizzlyService.notifyMapperUpdateListeners(networkListener, mapper);
            }
           
            boolean autoConfigure = false;
            // Avoid overriding the default with false
            if (System.getProperty(AUTO_CONFIGURE) != null){
                autoConfigure = true;
            }
            embeddedHttp.getController().setAutoConfigure(autoConfigure);

            boolean leaderFollower = false;
            // Avoid overriding the default with false
            if (System.getProperty(LEADER_FOLLOWER) != null){
                leaderFollower = true;
            }
            embeddedHttp.getController().useLeaderFollowerStrategy(leaderFollower);
        }
    }
View Full Code Here

TOP

Related Classes of com.sun.grizzly.config.GrizzlyEmbeddedHttp

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.