Search in sources :

Example 6 with GuiceFilter

use of com.google.inject.servlet.GuiceFilter in project gerrit by GerritCodeReview.

the class LfsPluginServlet method load.

private GuiceFilter load(Plugin plugin) {
    if (plugin.getHttpInjector() != null) {
        final String name = plugin.getName();
        final GuiceFilter guiceFilter;
        try {
            guiceFilter = plugin.getHttpInjector().getInstance(GuiceFilter.class);
        } catch (RuntimeException e) {
            log.warn(String.format("Plugin %s cannot load GuiceFilter", name), e);
            return null;
        }
        try {
            ServletContext ctx = PluginServletContext.create(plugin, "/");
            guiceFilter.init(new WrappedFilterConfig(ctx));
        } catch (ServletException e) {
            log.warn(String.format("Plugin %s failed to initialize HTTP", name), e);
            return null;
        }
        plugin.add(new RegistrationHandle() {

            @Override
            public void remove() {
                guiceFilter.destroy();
            }
        });
        return guiceFilter;
    }
    return null;
}
Also used : ServletException(javax.servlet.ServletException) RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle) GuiceFilter(com.google.inject.servlet.GuiceFilter) ServletContext(javax.servlet.ServletContext)

Aggregations

GuiceFilter (com.google.inject.servlet.GuiceFilter)6 RegistrationHandle (com.google.gerrit.extensions.registration.RegistrationHandle)4 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 Injector (com.google.inject.Injector)1 GuiceServletContextListener (com.google.inject.servlet.GuiceServletContextListener)1 DispatcherType (javax.servlet.DispatcherType)1 Filter (javax.servlet.Filter)1 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)1 Server (org.eclipse.jetty.server.Server)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 HandlerList (org.eclipse.jetty.server.handler.HandlerList)1 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)1 GzipHandler (org.eclipse.jetty.server.handler.gzip.GzipHandler)1 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)1