Merge branch 'stable-2.7'

* stable-2.7:
  Fix Gerrit plugins under Tomcat by avoiding Guice static filter
This commit is contained in:
Shawn Pearce 2013-08-12 11:57:28 -07:00
commit dc24a4102c
2 changed files with 22 additions and 10 deletions

View File

@ -63,6 +63,7 @@ import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Provider;
import com.google.inject.name.Names;
import com.google.inject.servlet.GuiceFilter;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.spi.Message;
@ -71,16 +72,24 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
/** Configures the web application environment for Gerrit Code Review. */
public class WebAppInitializer extends GuiceServletContextListener {
public class WebAppInitializer extends GuiceServletContextListener
implements Filter {
private static final Logger log =
LoggerFactory.getLogger(WebAppInitializer.class);
@ -91,6 +100,13 @@ public class WebAppInitializer extends GuiceServletContextListener {
private Injector webInjector;
private Injector sshInjector;
private LifecycleManager manager;
private GuiceFilter filter;
@Override
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
filter.doFilter(req, res, chain);
}
private synchronized void init() {
if (manager == null) {
@ -143,6 +159,7 @@ public class WebAppInitializer extends GuiceServletContextListener {
.setHttpServletRequest(
webInjector.getProvider(HttpServletRequest.class));
filter = webInjector.getInstance(GuiceFilter.class);
manager = new LifecycleManager();
manager.add(dbInjector);
manager.add(cfgInjector);
@ -303,18 +320,17 @@ public class WebAppInitializer extends GuiceServletContextListener {
}
@Override
public void contextInitialized(final ServletContextEvent event) {
super.contextInitialized(event);
public void init(FilterConfig cfg) throws ServletException {
contextInitialized(new ServletContextEvent(cfg.getServletContext()));
init();
manager.start();
}
@Override
public void contextDestroyed(final ServletContextEvent event) {
public void destroy() {
if (manager != null) {
manager.stop();
manager = null;
}
super.contextDestroyed(event);
}
}

View File

@ -8,14 +8,10 @@
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
<filter-class>com.google.gerrit.httpd.WebAppInitializer</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.google.gerrit.httpd.WebAppInitializer</listener-class>
</listener>
</web-app>