Java 类org.eclipse.jetty.servlets.AsyncGzipFilter 实例源码

项目:Openfire    文件:HttpBindManager.java   
/**
 * Creates a Jetty context handler that can be used to expose BOSH (HTTP-Bind) functionality.
 *
 * Note that an invocation of this method will not register the handler (and thus make the related functionality
 * available to the end user). Instead, the created handler is returned by this method, and will need to be
 * registered with the embedded Jetty webserver by the caller.
 *
 * @return A Jetty context handler (never null).
 */
protected Handler createBoshHandler()
{
    final ServletContextHandler context = new ServletContextHandler( null, "/http-bind", ServletContextHandler.SESSIONS );

    // Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs).
    final List<ContainerInitializer> initializers = new ArrayList<>();
    initializers.add( new ContainerInitializer( new JasperInitializer(), null ) );
    context.setAttribute( "org.eclipse.jetty.containerInitializers", initializers );
    context.setAttribute( InstanceManager.class.getName(), new SimpleInstanceManager() );

    // Generic configuration of the context.
    context.setAllowNullPathInfo( true );

    // Add the functionality-providers.
    context.addServlet( new ServletHolder( new HttpBindServlet() ), "/*" );

    // Add compression filter when needed.
    if ( isHttpCompressionEnabled() )
    {
        final Filter gzipFilter = new AsyncGzipFilter()
        {
            @Override
            public void init( FilterConfig config ) throws ServletException
            {
                super.init( config );
                _methods.add( HttpMethod.POST.asString() );
                Log.info( "Installed response compression filter" );
            }
        };

        final FilterHolder filterHolder = new FilterHolder();
        filterHolder.setFilter( gzipFilter );
        context.addFilter( filterHolder, "/*", EnumSet.of( DispatcherType.REQUEST ) );
    }

    return context;
}