Merge branch 'stable-2.7'
* stable-2.7: Fix Gerrit plugins under Tomcat by avoiding Guice static filter
This commit is contained in:
commit
dc24a4102c
@ -63,6 +63,7 @@ import com.google.inject.Key;
|
|||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.name.Names;
|
import com.google.inject.name.Names;
|
||||||
|
import com.google.inject.servlet.GuiceFilter;
|
||||||
import com.google.inject.servlet.GuiceServletContextListener;
|
import com.google.inject.servlet.GuiceServletContextListener;
|
||||||
import com.google.inject.spi.Message;
|
import com.google.inject.spi.Message;
|
||||||
|
|
||||||
@ -71,16 +72,24 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.FilterConfig;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
/** Configures the web application environment for Gerrit Code Review. */
|
/** 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 =
|
private static final Logger log =
|
||||||
LoggerFactory.getLogger(WebAppInitializer.class);
|
LoggerFactory.getLogger(WebAppInitializer.class);
|
||||||
|
|
||||||
@ -91,6 +100,13 @@ public class WebAppInitializer extends GuiceServletContextListener {
|
|||||||
private Injector webInjector;
|
private Injector webInjector;
|
||||||
private Injector sshInjector;
|
private Injector sshInjector;
|
||||||
private LifecycleManager manager;
|
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() {
|
private synchronized void init() {
|
||||||
if (manager == null) {
|
if (manager == null) {
|
||||||
@ -143,6 +159,7 @@ public class WebAppInitializer extends GuiceServletContextListener {
|
|||||||
.setHttpServletRequest(
|
.setHttpServletRequest(
|
||||||
webInjector.getProvider(HttpServletRequest.class));
|
webInjector.getProvider(HttpServletRequest.class));
|
||||||
|
|
||||||
|
filter = webInjector.getInstance(GuiceFilter.class);
|
||||||
manager = new LifecycleManager();
|
manager = new LifecycleManager();
|
||||||
manager.add(dbInjector);
|
manager.add(dbInjector);
|
||||||
manager.add(cfgInjector);
|
manager.add(cfgInjector);
|
||||||
@ -303,18 +320,17 @@ public class WebAppInitializer extends GuiceServletContextListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(final ServletContextEvent event) {
|
public void init(FilterConfig cfg) throws ServletException {
|
||||||
super.contextInitialized(event);
|
contextInitialized(new ServletContextEvent(cfg.getServletContext()));
|
||||||
init();
|
init();
|
||||||
manager.start();
|
manager.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(final ServletContextEvent event) {
|
public void destroy() {
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
manager.stop();
|
manager.stop();
|
||||||
manager = null;
|
manager = null;
|
||||||
}
|
}
|
||||||
super.contextDestroyed(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,10 @@
|
|||||||
|
|
||||||
<filter>
|
<filter>
|
||||||
<filter-name>guiceFilter</filter-name>
|
<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>
|
||||||
<filter-mapping>
|
<filter-mapping>
|
||||||
<filter-name>guiceFilter</filter-name>
|
<filter-name>guiceFilter</filter-name>
|
||||||
<url-pattern>/*</url-pattern>
|
<url-pattern>/*</url-pattern>
|
||||||
</filter-mapping>
|
</filter-mapping>
|
||||||
|
|
||||||
<listener>
|
|
||||||
<listener-class>com.google.gerrit.httpd.WebAppInitializer</listener-class>
|
|
||||||
</listener>
|
|
||||||
</web-app>
|
</web-app>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user