Index: ../../../dev/grizzly2_git/modules/config/src/main/java/org/glassfish/grizzly/config/GenericGrizzlyListener.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP <+>/*\n * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.\n *\n * Copyright (c) 2007-2012 Oracle and/or its affiliates. All rights reserved.\n *\n * The contents of this file are subject to the terms of either the GNU\n * General Public License Version 2 only (\"GPL\") or the Common Development\n * and Distribution License(\"CDDL\") (collectively, the \"License\"). You\n * may not use this file except in compliance with the License. You can\n * obtain a copy of the License at\n * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html\n * or packager/legal/LICENSE.txt. See the License for the specific\n * language governing permissions and limitations under the License.\n *\n * When distributing the software, include this License Header Notice in each\n * file and include the License file at packager/legal/LICENSE.txt.\n *\n * GPL Classpath Exception:\n * Oracle designates this particular file as subject to the \"Classpath\"\n * exception as provided by Oracle in the GPL Version 2 section of the License\n * file that accompanied this code.\n *\n * Modifications:\n * If applicable, add the following below the License Header, with the fields\n * enclosed by brackets [] replaced by your own identifying information:\n * \"Portions Copyright [year] [name of copyright owner]\"\n *\n * Contributor(s):\n * If you wish your version of this file to be governed by only the CDDL or\n * only the GPL Version 2, indicate your decision by adding \"[Contributor]\n * elects to include this software in this distribution under the [CDDL or GPL\n * Version 2] license.\" If you don't indicate a single choice of license, a\n * recipient has the option to distribute your version of this file under\n * either the CDDL, the GPL Version 2 or to extend the choice of license to\n * its licensees as provided above. However, if you add GPL Version 2 code\n * and therefore, elected the GPL Version 2 license, then the option applies\n * only if the new code is made subject to such option by the copyright\n * holder.\n */\npackage org.glassfish.grizzly.config;\n\nimport java.beans.PropertyChangeEvent;\nimport java.io.IOException;\nimport java.lang.reflect.Method;\nimport java.net.InetAddress;\nimport java.net.InetSocketAddress;\nimport java.text.MessageFormat;\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Set;\nimport java.util.concurrent.ExecutorService;\nimport java.util.concurrent.Executors;\nimport java.util.concurrent.ThreadFactory;\nimport java.util.concurrent.TimeUnit;\nimport java.util.concurrent.atomic.AtomicInteger;\nimport java.util.logging.Level;\nimport java.util.logging.Logger;\nimport org.glassfish.grizzly.IOStrategy;\n\nimport org.glassfish.grizzly.SocketBinder;\nimport org.glassfish.grizzly.config.dom.Http;\nimport org.glassfish.grizzly.config.dom.NetworkListener;\nimport org.glassfish.grizzly.config.dom.PortUnification;\nimport org.glassfish.grizzly.config.dom.Protocol;\nimport org.glassfish.grizzly.config.dom.ProtocolChain;\nimport org.glassfish.grizzly.config.dom.ProtocolChainInstanceHandler;\nimport org.glassfish.grizzly.config.dom.ProtocolFilter;\nimport org.glassfish.grizzly.config.dom.Ssl;\nimport org.glassfish.grizzly.config.dom.ThreadPool;\nimport org.glassfish.grizzly.config.dom.Transport;\nimport org.glassfish.grizzly.config.portunif.HttpRedirectFilter;\nimport org.glassfish.grizzly.filterchain.Filter;\nimport org.glassfish.grizzly.filterchain.FilterChain;\nimport org.glassfish.grizzly.filterchain.FilterChainBuilder;\nimport org.glassfish.grizzly.filterchain.TransportFilter;\nimport org.glassfish.grizzly.http.ContentEncoding;\nimport org.glassfish.grizzly.http.GZipContentEncoding;\nimport org.glassfish.grizzly.http.KeepAlive;\nimport org.glassfish.grizzly.http.LZMAContentEncoding;\nimport org.glassfish.grizzly.http.server.AddOn;\nimport org.glassfish.grizzly.http.server.CompressionEncodingFilter;\nimport org.glassfish.grizzly.http.server.CompressionLevel;\nimport org.glassfish.grizzly.http.server.FileCacheFilter;\nimport org.glassfish.grizzly.http.server.HttpHandler;\nimport org.glassfish.grizzly.http.server.HttpServerFilter;\nimport org.glassfish.grizzly.http.server.ServerFilterConfiguration;\nimport org.glassfish.grizzly.http.server.StaticHttpHandler;\nimport org.glassfish.grizzly.http.server.filecache.FileCache;\nimport org.glassfish.grizzly.nio.NIOTransport;\nimport org.glassfish.grizzly.nio.transport.TCPNIOTransport;\nimport org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder;\nimport org.glassfish.grizzly.nio.transport.UDPNIOTransport;\nimport org.glassfish.grizzly.nio.transport.UDPNIOTransportBuilder;\nimport org.glassfish.grizzly.portunif.PUFilter;\nimport org.glassfish.grizzly.portunif.PUProtocol;\nimport org.glassfish.grizzly.portunif.ProtocolFinder;\nimport org.glassfish.grizzly.portunif.finders.SSLProtocolFinder;\nimport org.glassfish.grizzly.rcm.ResourceAllocationFilter;\nimport org.glassfish.grizzly.ssl.SSLEngineConfigurator;\nimport org.glassfish.grizzly.ssl.SSLFilter;\nimport org.glassfish.grizzly.strategies.WorkerThreadIOStrategy;\nimport org.glassfish.grizzly.threadpool.DefaultWorkerThread;\nimport org.glassfish.grizzly.threadpool.GrizzlyExecutorService;\nimport org.glassfish.grizzly.threadpool.ThreadPoolConfig;\nimport org.glassfish.grizzly.utils.DelayedExecutor;\nimport org.glassfish.grizzly.utils.IdleTimeoutFilter;\nimport org.jvnet.hk2.component.Habitat;\nimport org.jvnet.hk2.config.ConfigBeanProxy;\n\n/**\n * Generic {@link GrizzlyListener} implementation, which is not HTTP dependent, and can support any Transport\n * configuration, based on {@link FilterChain}.\n *\n * @author Alexey Stashok\n */\npublic class GenericGrizzlyListener implements GrizzlyListener {\n /**\n * The logger to use for logging messages.\n */\n static final Logger logger = Logger.getLogger(GrizzlyListener.class.getName());\n protected volatile String name;\n protected volatile InetAddress address;\n protected volatile int port;\n protected NIOTransport transport;\n protected FilterChain rootFilterChain;\n private volatile ExecutorService auxExecutorService;\n private volatile DelayedExecutor delayedExecutor;\n private volatile long transactionTimeoutMillis = -1;\n\n @Override\n public String getName() {\n return name;\n }\n\n protected final void setName(String name) {\n this.name = name;\n }\n\n @Override\n public InetAddress getAddress() {\n return address;\n }\n\n protected final void setAddress(InetAddress inetAddress) {\n address = inetAddress;\n }\n\n @Override\n public int getPort() {\n return port;\n }\n\n protected void setPort(int port) {\n this.port = port;\n }\n\n @Override\n public void start() throws IOException {\n delayedExecutor.start();\n ((SocketBinder) transport).bind(new InetSocketAddress(address, port));\n transport.start();\n }\n\n @Override\n public void stop() throws IOException {\n stopDelayedExecutor();\n transport.stop();\n transport = null;\n rootFilterChain = null;\n }\n\n @Override\n public void destroy() {\n }\n\n @Override\n public void processDynamicConfigurationChange(Habitat habitat,\n PropertyChangeEvent[] events) {\n }\n\n @Override\n public T getAdapter(Class adapterClass) {\n return null;\n }\n\n public List getFilters(Class clazz) {\n return getFilters(clazz, rootFilterChain, new ArrayList(2));\n }\n\n public org.glassfish.grizzly.Transport getTransport() {\n return transport;\n }\n \n @SuppressWarnings({\"unchecked\"})\n public static List getFilters(Class clazz,\n FilterChain filterChain, List filters) {\n for (final Filter filter : filterChain) {\n if (clazz.isAssignableFrom(filter.getClass())) {\n filters.add((E) filter);\n }\n if (PUFilter.class.isAssignableFrom(filter.getClass())) {\n final Set puProtocols = ((PUFilter) filter).getProtocols();\n for (PUProtocol puProtocol : puProtocols) {\n getFilters(clazz, puProtocol.getFilterChain(), filters);\n }\n }\n }\n return filters;\n }\n\n /*\n * Configures the given grizzlyListener.\n *\n * @param networkListener The NetworkListener to configure\n */\n // TODO: Must get the information from domain.xml Config objects.\n // TODO: Pending Grizzly issue 54\n @Override\n public void configure(final Habitat habitat,\n final NetworkListener networkListener) throws IOException {\n setName(networkListener.getName());\n setAddress(InetAddress.getByName(networkListener.getAddress()));\n setPort(Integer.parseInt(networkListener.getPort()));\n configureDelayedExecutor(habitat);\n\n final FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();\n \n configureTransport(habitat, networkListener,\n networkListener.findTransport(), filterChainBuilder);\n\n configureProtocol(habitat, networkListener,\n networkListener.findProtocol(), filterChainBuilder);\n\n configureThreadPool(habitat, networkListener,\n networkListener.findThreadPool());\n\n rootFilterChain = filterChainBuilder.build();\n transport.setProcessor(rootFilterChain);\n }\n\n protected void configureTransport(final Habitat habitat,\n final NetworkListener networkListener,\n final Transport transportConfig,\n final FilterChainBuilder filterChainBuilder) {\n \n final String transportClassName = transportConfig.getClassname();\n if (TCPNIOTransport.class.getName().equals(transportClassName)) {\n transport = configureTCPTransport(habitat, networkListener, transportConfig);\n } else if (UDPNIOTransport.class.getName().equals(transportClassName)) {\n transport = configureUDPTransport(habitat, networkListener, transportConfig);\n } else {\n throw new GrizzlyConfigException(\"Unsupported transport type \" + transportConfig.getName());\n }\n transport.setSelectorRunnersCount(Integer.parseInt(transportConfig.getAcceptorThreads()));\n transport.setReadBufferSize(Integer.parseInt(transportConfig.getBufferSizeBytes()));\n transport.getKernelThreadPoolConfig().setPoolName(networkListener.getName() + \"-kernel\");\n transport.setIOStrategy(loadIOStrategy(transportConfig.getIOStrategy()));\n \n filterChainBuilder.add(new TransportFilter());\n }\n\n protected NIOTransport configureTCPTransport(final Habitat habitat,\n final NetworkListener networkListener,\n final Transport transportConfig) {\n \n final TCPNIOTransport tcpTransport = TCPNIOTransportBuilder.newInstance().build();\n tcpTransport.setTcpNoDelay(Boolean.parseBoolean(transportConfig.getTcpNoDelay()));\n tcpTransport.setLinger(Integer.parseInt(transportConfig.getLinger()));\n tcpTransport.setKeepAlive(Boolean.parseBoolean(transportConfig.getKeepAlive()));\n tcpTransport.setServerConnectionBackLog(Integer.parseInt(transportConfig.getMaxConnectionsCount()));\n return tcpTransport;\n }\n\n protected NIOTransport configureUDPTransport(final Habitat habitat,\n final NetworkListener networkListener,\n final Transport transportConfig) {\n return UDPNIOTransportBuilder.newInstance().build();\n }\n\n protected void configureProtocol(final Habitat habitat,\n final NetworkListener networkListener,\n final Protocol protocol,\n final FilterChainBuilder filterChainBuilder) {\n \n if (Boolean.valueOf(protocol.getSecurityEnabled())) {\n configureSsl(habitat, \n networkListener, \n getSsl(protocol),\n filterChainBuilder);\n }\n configureSubProtocol(habitat, networkListener, protocol,\n filterChainBuilder);\n }\n\n protected void configureSubProtocol(final Habitat habitat,\n final NetworkListener networkListener,\n final Protocol protocol,\n final FilterChainBuilder filterChainBuilder) {\n \n if (protocol.getHttp() != null) {\n final Http http = protocol.getHttp();\n configureHttpProtocol(habitat, networkListener, http, filterChainBuilder);\n\n } else if (protocol.getPortUnification() != null) {\n // Port unification\n final PortUnification pu = protocol.getPortUnification();\n final String puFilterClassname = pu.getClassname();\n PUFilter puFilter = null;\n if (puFilterClassname != null) {\n try {\n puFilter = Utils.newInstance(habitat,\n PUFilter.class, puFilterClassname, puFilterClassname);\n configureElement(habitat, networkListener, pu, puFilter);\n } catch (Exception e) {\n logger.log(Level.WARNING,\n \"Can not initialize port unification filter: \"\n + puFilterClassname + \" default filter will be used instead\", e);\n }\n }\n if (puFilter == null) {\n puFilter = new PUFilter();\n }\n List findersConfig = pu.getProtocolFinder();\n for (org.glassfish.grizzly.config.dom.ProtocolFinder finderConfig : findersConfig) {\n final String finderClassname = finderConfig.getClassname();\n try {\n final ProtocolFinder protocolFinder = Utils.newInstance(habitat,\n ProtocolFinder.class, finderClassname, finderClassname);\n configureElement(habitat, networkListener, finderConfig, protocolFinder);\n final Protocol subProtocol = finderConfig.findProtocol();\n final FilterChainBuilder subProtocolFilterChainBuilder =\n puFilter.getPUFilterChainBuilder();\n // If subprotocol is secured - we need to wrap it under SSLProtocolFinder\n if (Boolean.valueOf(subProtocol.getSecurityEnabled())) {\n final PUFilter extraSslPUFilter = new PUFilter();\n \n configureSsl(habitat, networkListener,\n getSsl(subProtocol), subProtocolFilterChainBuilder);\n \n subProtocolFilterChainBuilder.add(extraSslPUFilter);\n final FilterChainBuilder extraSslPUFilterChainBuilder =\n extraSslPUFilter.getPUFilterChainBuilder();\n configureSubProtocol(habitat, networkListener,\n subProtocol, extraSslPUFilterChainBuilder);\n extraSslPUFilter.register(protocolFinder,\n extraSslPUFilterChainBuilder.build());\n \n puFilter.register(new SSLProtocolFinder(\n new SSLConfigurator(habitat, subProtocol.getSsl())),\n subProtocolFilterChainBuilder.build());\n } else {\n configureSubProtocol(habitat, networkListener,\n subProtocol, subProtocolFilterChainBuilder);\n puFilter.register(protocolFinder, subProtocolFilterChainBuilder.build());\n }\n } catch (Exception e) {\n logger.log(Level.WARNING, \"Can not initialize sub protocol. Finder: \"\n + finderClassname, e);\n }\n }\n filterChainBuilder.add(puFilter);\n } else if (protocol.getHttpRedirect() != null) {\n filterChainBuilder.add(new org.glassfish.grizzly.http.HttpServerFilter());\n final HttpRedirectFilter filter = new HttpRedirectFilter();\n filter.configure(habitat, networkListener, protocol.getHttpRedirect());\n filterChainBuilder.add(filter);\n } else {\n ProtocolChainInstanceHandler pcihConfig = protocol.getProtocolChainInstanceHandler();\n if (pcihConfig == null) {\n logger.log(Level.WARNING, \"Empty protocol declaration\");\n return;\n }\n ProtocolChain filterChainConfig = pcihConfig.getProtocolChain();\n for (ProtocolFilter filterConfig : filterChainConfig.getProtocolFilter()) {\n final String filterClassname = filterConfig.getClassname();\n try {\n final Filter filter = (Filter) Utils.newInstance(filterClassname);\n configureElement(habitat, networkListener, filterConfig, filter);\n filterChainBuilder.add(filter);\n } catch (Exception e) {\n logger.log(Level.WARNING, \"Can not initialize protocol filter: \"\n + filterClassname, e);\n throw new IllegalStateException(\"Can not initialize protocol filter: \"\n + filterClassname);\n }\n }\n }\n }\n\n protected static void configureSsl(final Habitat habitat,\n final NetworkListener networkListener, final Ssl ssl,\n final FilterChainBuilder filterChainBuilder) {\n final SSLEngineConfigurator serverConfig = new SSLConfigurator(habitat, ssl);\n final SSLEngineConfigurator clientConfig = new SSLConfigurator(habitat, ssl);\n clientConfig.setClientMode(true);\n\n filterChainBuilder.add(new SSLFilter(serverConfig,\n clientConfig,\n isRenegotiateOnClientAuthWant(ssl)));\n }\n\n private static boolean isRenegotiateOnClientAuthWant(final Ssl ssl) {\n return ssl == null || Boolean.parseBoolean(ssl.getRenegotiateOnClientAuthWant());\n }\n\n @SuppressWarnings({\"unchecked\"})\n private static boolean configureElement(Habitat habitat,\n NetworkListener networkListener, ConfigBeanProxy configuration,\n Object instance) {\n \n if (instance instanceof ConfigAwareElement) {\n ((ConfigAwareElement) instance).configure(habitat, networkListener,\n configuration);\n \n return true;\n }\n \n return false;\n }\n\n protected void configureThreadPool(final Habitat habitat,\n final NetworkListener networkListener,\n final ThreadPool threadPool) {\n \n final String classname = threadPool.getClassname();\n if (classname != null) {\n // Use custom thread pool\n try {\n final ExecutorService customThreadPool =\n Utils.newInstance(habitat,\n ExecutorService.class, classname, classname);\n \n if (customThreadPool != null) {\n if (!configureElement(habitat, networkListener,\n threadPool, customThreadPool)) {\n logger.log(Level.INFO,\n \"The ThreadPool configuration bean can not be \"\n + \"passed to the custom thread-pool: {0}\" +\n \" instance, because it's not {1}.\",\n new Object[] {\n classname, ConfigAwareElement.class.getName()});\n }\n \n transport.setWorkerThreadPool(customThreadPool);\n return;\n }\n \n logger.log(Level.WARNING,\n \"Can not initalize custom thread pool: {0}\", classname);\n \n } catch (Throwable t) {\n logger.log(Level.WARNING,\n \"Can not initalize custom thread pool: \" + classname, t);\n }\n }\n \n try {\n // Use standard Grizzly thread pool\n transport.setWorkerThreadPool(GrizzlyExecutorService.createInstance(\n configureThreadPoolConfig(habitat, networkListener, threadPool)));\n } catch (NumberFormatException ex) {\n logger.log(Level.WARNING, \"Invalid thread-pool attribute\", ex);\n }\n }\n\n protected ThreadPoolConfig configureThreadPoolConfig(final Habitat habitat,\n final NetworkListener networkListener,\n final ThreadPool threadPool) {\n\n final int maxQueueSize = threadPool.getMaxQueueSize() == null ? Integer.MAX_VALUE\n : Integer.parseInt(threadPool.getMaxQueueSize());\n final int minThreads = Integer.parseInt(threadPool.getMinThreadPoolSize());\n final int maxThreads = Integer.parseInt(threadPool.getMaxThreadPoolSize());\n final int timeout = Integer.parseInt(threadPool.getIdleThreadTimeoutSeconds());\n final ThreadPoolConfig poolConfig = ThreadPoolConfig.newConfig();\n poolConfig.setPoolName(networkListener.getName());\n poolConfig.setCorePoolSize(minThreads);\n poolConfig.setMaxPoolSize(maxThreads);\n poolConfig.setQueueLimit(maxQueueSize);\n poolConfig.setKeepAliveTime(timeout < 0 ? Long.MAX_VALUE : timeout, TimeUnit.SECONDS);\n if (transactionTimeoutMillis > 0 && !Utils.isDebugVM()) {\n poolConfig.setTransactionTimeout(delayedExecutor,\n transactionTimeoutMillis, TimeUnit.MILLISECONDS);\n }\n \n return poolConfig;\n }\n\n protected void configureDelayedExecutor(Habitat habitat) {\n final AtomicInteger threadCounter = new AtomicInteger();\n auxExecutorService = Executors.newCachedThreadPool(\n new ThreadFactory() {\n @Override\n public Thread newThread(Runnable r) {\n final Thread newThread = new DefaultWorkerThread(\n transport.getAttributeBuilder(),\n getName() + '-' + threadCounter.getAndIncrement(),\n null,\n r);\n newThread.setDaemon(true);\n return newThread;\n }\n });\n delayedExecutor = new DelayedExecutor(auxExecutorService);\n }\n\n protected void stopDelayedExecutor() {\n final DelayedExecutor localDelayedExecutor = delayedExecutor;\n delayedExecutor = null;\n if (localDelayedExecutor != null) {\n localDelayedExecutor.stop();\n }\n final ExecutorService localThreadPool = auxExecutorService;\n auxExecutorService = null;\n if (localThreadPool != null) {\n localThreadPool.shutdownNow();\n }\n }\n\n @SuppressWarnings({\"deprecation\"})\n protected void configureHttpProtocol(final Habitat habitat,\n final NetworkListener networkListener,\n final Http http, final FilterChainBuilder filterChainBuilder) {\n transactionTimeoutMillis = Integer.parseInt(http.getRequestTimeoutSeconds()) * 1000;\n filterChainBuilder.add(new IdleTimeoutFilter(delayedExecutor, Integer.parseInt(http.getTimeoutSeconds()),\n TimeUnit.SECONDS));\n final org.glassfish.grizzly.http.HttpServerFilter httpServerFilter =\n new org.glassfish.grizzly.http.HttpServerFilter(\n Boolean.parseBoolean(http.getChunkingEnabled()),\n Integer.parseInt(http.getHeaderBufferLengthBytes()),\n http.getForcedResponseType(),\n configureKeepAlive(habitat, http),\n delayedExecutor);\n final Set contentEncodings =\n configureContentEncodings(habitat, http);\n for (ContentEncoding contentEncoding : contentEncodings) {\n httpServerFilter.addContentEncoding(contentEncoding);\n }\n //httpServerFilter.addContentEncoding(new GZipContentEncoding());\n final boolean isRcmSupportEnabled = Boolean.parseBoolean(http.getRcmSupportEnabled());\n if (isRcmSupportEnabled) {\n filterChainBuilder.add(new ResourceAllocationFilter());\n }\n// httpServerFilter.getMonitoringConfig().addProbes(\n// serverConfig.getMonitoringConfig().getHttpConfig().getProbes());\n filterChainBuilder.add(httpServerFilter);\n final FileCache fileCache = configureHttpFileCache(habitat, http.getFileCache());\n fileCache.initialize(transport.getMemoryManager(), delayedExecutor);\n final FileCacheFilter fileCacheFilter = new FileCacheFilter(fileCache);\n// fileCache.getMonitoringConfig().addProbes(\n// serverConfig.getMonitoringConfig().getFileCacheConfig().getProbes());\n filterChainBuilder.add(fileCacheFilter);\n final HttpServerFilter webServerFilter = new HttpServerFilter(getHttpServerFilterConfiguration(http),\n delayedExecutor);\n\n final HttpHandler httpHandler = getHttpHandler(http);\n httpHandler.setAllowEncodedSlash(GrizzlyConfig.toBoolean(http.getEncodedSlashEnabled()));\n webServerFilter.setHttpHandler(httpHandler);\n// webServerFilter.getMonitoringConfig().addProbes(\n// serverConfig.getMonitoringConfig().getWebServerConfig().getProbes());\n filterChainBuilder.add(webServerFilter);\n\n configureCometSupport(habitat, networkListener, http, filterChainBuilder);\n\n configureWebSocketSupport(habitat, networkListener, http, filterChainBuilder);\n\n configureAjpSupport(habitat, networkListener, http, filterChainBuilder);\n }\n\n protected void configureCometSupport(final Habitat habitat,\n final NetworkListener networkListener,\n final Http http, final FilterChainBuilder filterChainBuilder) {\n\n if(GrizzlyConfig.toBoolean(http.getCometSupportEnabled())) {\n final AddOn cometAddOn = loadAddOn(habitat, \"comet\",\n \"org.glassfish.grizzly.comet.CometAddOn\");\n if (cometAddOn != null) {\n configureElement(habitat, networkListener, http, cometAddOn);\n cometAddOn.setup(null, filterChainBuilder);\n }\n }\n }\n\n protected void configureWebSocketSupport(final Habitat habitat,\n final NetworkListener networkListener,\n final Http http, final FilterChainBuilder filterChainBuilder) {\n final boolean websocketsSupportEnabled = Boolean.parseBoolean(http.getWebsocketsSupportEnabled());\n if (websocketsSupportEnabled) {\n final long timeoutSeconds = Integer.parseInt(http.getWebsocketsTimeoutSeconds());\n Filter f;\n if (timeoutSeconds != Http.WEBSOCKETS_TIMEOUT) {\n f = loadFilter(habitat,\n \"websockets\",\n \"org.glassfish.grizzly.websockets.WebSocketFilter\",\n new Class[] { Integer.TYPE },\n new Object[] { timeoutSeconds });\n \n } else {\n f = loadFilter(habitat, \"websockets\", \"org.glassfish.grizzly.websockets.WebSocketFilter\");\n }\n final int httpServerFilterIdx = filterChainBuilder.indexOfType(HttpServerFilter.class);\n\n if (httpServerFilterIdx >= 0) {\n // Insert the WebSocketFilter right after HttpCodecFilter\n filterChainBuilder.add(httpServerFilterIdx, f);\n }\n }\n }\n\n protected void configureAjpSupport(final Habitat habitat,\n final NetworkListener networkListener,\n final Http http, final FilterChainBuilder filterChainBuilder) {\n\n final boolean jkSupportEnabled = http.getJkEnabled() != null ?\n Boolean.parseBoolean(http.getJkEnabled()) :\n Boolean.parseBoolean(networkListener.getJkEnabled());\n\n if (jkSupportEnabled) {\n final AddOn ajpAddOn = loadAddOn(habitat, \"ajp\",\n \"org.glassfish.grizzly.http.ajp.AjpAddOn\");\n if (ajpAddOn != null) {\n configureElement(habitat, networkListener, http, ajpAddOn);\n ajpAddOn.setup(null, filterChainBuilder);\n }\n }\n }\n\n \n /**\n * Load {@link AddOn} with the specific service name and classname.\n */\n private AddOn loadAddOn(Habitat habitat, String name, String addOnClassName) {\n return Utils.newInstance(habitat, AddOn.class, name, addOnClassName);\n }\n\n /**\n * Load {@link Filter} with the specific service name and classname.\n */\n private Filter loadFilter(Habitat habitat, String name, String filterClassName) {\n return Utils.newInstance(habitat, Filter.class, name, filterClassName);\n }\n \n private Filter loadFilter(Habitat habitat,\n String name, \n String filterClassName, \n Class[] ctorArgTypes, \n Object[] ctorArgs) {\n return Utils.newInstance(habitat, Filter.class, name, filterClassName, ctorArgTypes, ctorArgs);\n }\n\n protected ServerFilterConfiguration getHttpServerFilterConfiguration(Http http) {\n final ServerFilterConfiguration serverFilterConfiguration =\n new ServerFilterConfiguration();\n serverFilterConfiguration.setScheme(http.getScheme());\n serverFilterConfiguration.setPassTraceRequest(true);\n return serverFilterConfiguration;\n }\n\n protected HttpHandler getHttpHandler(Http http) {\n return new StaticHttpHandler(\".\");\n }\n\n /**\n * Configure the Grizzly HTTP FileCache mechanism\n */\n protected FileCache configureHttpFileCache(Habitat habitat,\n org.glassfish.grizzly.config.dom.FileCache cache) {\n final FileCache fileCache = new FileCache();\n if (cache != null) {\n fileCache.setEnabled(GrizzlyConfig.toBoolean(cache.getEnabled()));\n fileCache.setSecondsMaxAge(Integer.parseInt(cache.getMaxAgeSeconds()));\n fileCache.setMaxCacheEntries(Integer.parseInt(cache.getMaxFilesCount()));\n fileCache.setMaxLargeFileCacheSize(Integer.parseInt(cache.getMaxCacheSizeBytes()));\n } else {\n fileCache.setEnabled(false);\n }\n return fileCache;\n }\n\n protected KeepAlive configureKeepAlive(Habitat habitat, Http http) {\n int timeoutInSeconds = 60;\n int maxConnections = 256;\n if (http != null) {\n try {\n timeoutInSeconds = Integer.parseInt(http.getTimeoutSeconds());\n } catch (NumberFormatException ex) {\n// String msg = _rb.getString(\"pewebcontainer.invalidKeepAliveTimeout\");\n String msg = \"pewebcontainer.invalidKeepAliveTimeout\";\n msg = MessageFormat.format(msg, http.getTimeoutSeconds(), Integer.toString(timeoutInSeconds));\n logger.log(Level.WARNING, msg, ex);\n }\n try {\n maxConnections = Integer.parseInt(http.getMaxConnections());\n } catch (NumberFormatException ex) {\n// String msg = _rb.getString(\"pewebcontainer.invalidKeepAliveMaxConnections\");\n String msg = \"pewebcontainer.invalidKeepAliveMaxConnections\";\n msg = MessageFormat.format(msg, http.getMaxConnections(), Integer.toString(maxConnections));\n logger.log(Level.WARNING, msg, ex);\n }\n }\n final KeepAlive keepAlive = new KeepAlive();\n keepAlive.setIdleTimeoutInSeconds(timeoutInSeconds);\n keepAlive.setMaxRequestsCount(maxConnections);\n return keepAlive;\n }\n\n protected Set configureContentEncodings(\n Habitat habitat, Http http) {\n return configureCompressionEncodings(habitat, http);\n }\n\n protected Set configureCompressionEncodings(Habitat habitat, Http http) {\n final String mode = http.getCompression();\n int compressionMinSize = Integer.parseInt(http.getCompressionMinSizeBytes());\n CompressionLevel compressionLevel;\n try {\n compressionLevel = CompressionLevel.getCompressionLevel(mode);\n } catch (IllegalArgumentException e) {\n try {\n // Try to parse compression as an int, which would give the\n // minimum compression size\n compressionLevel = CompressionLevel.ON;\n compressionMinSize = Integer.parseInt(mode);\n } catch (Exception ignore) {\n compressionLevel = CompressionLevel.OFF;\n }\n }\n final String compressableMimeTypesString = http.getCompressableMimeType();\n final String noCompressionUserAgentsString = http.getNoCompressionUserAgents();\n final String[] compressableMimeTypes = \n ((compressableMimeTypesString != null) \n ? compressableMimeTypesString.split(\",\") \n : new String[0]);\n final String[] noCompressionUserAgents = \n ((noCompressionUserAgentsString != null) \n ? noCompressionUserAgentsString.split(\",\") \n : new String[0]);\n final ContentEncoding gzipContentEncoding = new GZipContentEncoding(\n GZipContentEncoding.DEFAULT_IN_BUFFER_SIZE,\n GZipContentEncoding.DEFAULT_OUT_BUFFER_SIZE,\n new CompressionEncodingFilter(compressionLevel, compressionMinSize,\n compressableMimeTypes,\n noCompressionUserAgents,\n GZipContentEncoding.getGzipAliases()));\n final ContentEncoding lzmaEncoding = new LZMAContentEncoding(new CompressionEncodingFilter(compressionLevel, compressionMinSize,\n compressableMimeTypes,\n noCompressionUserAgents,\n LZMAContentEncoding.getLzmaAliases()));\n final Set set = new HashSet(2);\n set.add(gzipContentEncoding);\n set.add(lzmaEncoding);\n return set;\n }\n\n @SuppressWarnings(\"unchecked\")\n private static IOStrategy loadIOStrategy(final String classname) {\n Class strategy;\n if (classname == null) {\n strategy = WorkerThreadIOStrategy.class;\n } else {\n try {\n strategy = Utils.loadClass(classname);\n } catch (Exception e) {\n strategy = WorkerThreadIOStrategy.class;\n }\n }\n \n try {\n final Method m = strategy.getMethod(\"getInstance\");\n return (IOStrategy) m.invoke(null);\n } catch (Exception e) {\n throw new IllegalStateException(\"Can not initialize IOStrategy: \" + strategy + \". Error: \" + e);\n }\n }\n\n private static Ssl getSsl(Protocol protocol) {\n Ssl ssl = protocol.getSsl();\n if (ssl == null) {\n ssl = (Ssl) DefaultProxy.createDummyProxy(protocol, Ssl.class);\n }\n return ssl;\n }\n}\n =================================================================== --- ../../../dev/grizzly2_git/modules/config/src/main/java/org/glassfish/grizzly/config/GenericGrizzlyListener.java (revision 51afab3a2cd4a91584be3d23a8f6d7c4d14dd6c5) +++ ../../../dev/grizzly2_git/modules/config/src/main/java/org/glassfish/grizzly/config/GenericGrizzlyListener.java (revision ) @@ -601,7 +601,7 @@ } final int httpServerFilterIdx = filterChainBuilder.indexOfType(HttpServerFilter.class); - if (httpServerFilterIdx >= 0) { + if (httpServerFilterIdx >= 0 && f != null) { // Insert the WebSocketFilter right after HttpCodecFilter filterChainBuilder.add(httpServerFilterIdx, f); }