mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
Reject git operation when server is not ready.
This commit is contained in:
parent
4e10bbc1b6
commit
81a19f4ce3
@ -4,6 +4,7 @@ import java.io.IOException;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.inject.Provider;
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
import javax.servlet.FilterChain;
|
import javax.servlet.FilterChain;
|
||||||
@ -29,16 +30,19 @@ public class JettyPlugin extends AbstractPlugin {
|
|||||||
|
|
||||||
private ServletContextHandler contextHandler;
|
private ServletContextHandler contextHandler;
|
||||||
|
|
||||||
private final Set<ServerConfigurator> serverConfigurators;
|
private final Provider<Set<ServerConfigurator>> serverConfiguratorsProvider;
|
||||||
|
|
||||||
private final Set<ServletConfigurator> servletContextConfigurators;
|
private final Provider<Set<ServletConfigurator>> servletConfiguratorsProvider;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Inject providers here to avoid circurlar dependencies when dependency graph gets complicated
|
||||||
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public JettyPlugin(
|
public JettyPlugin(
|
||||||
Set<ServerConfigurator> serverConfigurators,
|
Provider<Set<ServerConfigurator>> serverConfiguratorsProvider,
|
||||||
Set<ServletConfigurator> servletContextConfigurators) {
|
Provider<Set<ServletConfigurator>> servletConfiguratorsProvider) {
|
||||||
this.serverConfigurators = serverConfigurators;
|
this.serverConfiguratorsProvider = serverConfiguratorsProvider;
|
||||||
this.servletContextConfigurators = servletContextConfigurators;
|
this.servletConfiguratorsProvider = servletConfiguratorsProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -80,7 +84,7 @@ public class JettyPlugin extends AbstractPlugin {
|
|||||||
|
|
||||||
contextHandler.addFilter(DisableTraceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
|
contextHandler.addFilter(DisableTraceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
|
||||||
|
|
||||||
for (ServletConfigurator configurator: servletContextConfigurators)
|
for (ServletConfigurator configurator: servletConfiguratorsProvider.get())
|
||||||
configurator.configure(contextHandler);
|
configurator.configure(contextHandler);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -92,7 +96,7 @@ public class JettyPlugin extends AbstractPlugin {
|
|||||||
|
|
||||||
server.setHandler(contextHandler);
|
server.setHandler(contextHandler);
|
||||||
|
|
||||||
for (ServerConfigurator configurator: serverConfigurators)
|
for (ServerConfigurator configurator: serverConfiguratorsProvider.get())
|
||||||
configurator.configure(server);
|
configurator.configure(server);
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
|
|||||||
@ -35,10 +35,13 @@ public class GitFilter implements Filter {
|
|||||||
|
|
||||||
private static final String INFO_REFS = "info/refs";
|
private static final String INFO_REFS = "info/refs";
|
||||||
|
|
||||||
|
private final Gitop gitop;
|
||||||
|
|
||||||
private final ProjectManager projectManager;
|
private final ProjectManager projectManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public GitFilter(ProjectManager projectManager) {
|
public GitFilter(Gitop gitop, ProjectManager projectManager) {
|
||||||
|
this.gitop = gitop;
|
||||||
this.projectManager = projectManager;
|
this.projectManager = projectManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +150,8 @@ public class GitFilter implements Filter {
|
|||||||
FilterChain chain) throws IOException, ServletException {
|
FilterChain chain) throws IOException, ServletException {
|
||||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||||
|
|
||||||
|
if (gitop.isReady()) {
|
||||||
try {
|
try {
|
||||||
if (GitSmartHttpTools.isInfoRefs(httpRequest)) {
|
if (GitSmartHttpTools.isInfoRefs(httpRequest)) {
|
||||||
processRefs(httpRequest, httpResponse);
|
processRefs(httpRequest, httpResponse);
|
||||||
@ -159,6 +164,9 @@ public class GitFilter implements Filter {
|
|||||||
logger.error("Error serving git request", e);
|
logger.error("Error serving git request", e);
|
||||||
GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
|
GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Server is not ready.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user