diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/GitBridgeServer.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/GitBridgeServer.java index e39dbb3a41..86c7e193c0 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/GitBridgeServer.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/GitBridgeServer.java @@ -129,6 +129,7 @@ public class GitBridgeServer { HandlerCollection handlers = new HandlerList(); handlers.addHandler(new StatusHandler(bridge)); + handlers.addHandler(new HealthCheckHandler(bridge)); handlers.addHandler(initResourceHandler()); handlers.addHandler(new PostbackHandler(bridge)); handlers.addHandler(new DefaultHandler()); diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/HealthCheckHandler.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/HealthCheckHandler.java new file mode 100644 index 0000000000..c7f30b3497 --- /dev/null +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/server/HealthCheckHandler.java @@ -0,0 +1,40 @@ +package uk.ac.ic.wlgitbridge.server; + +import org.eclipse.jetty.server.HttpConnection; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import uk.ac.ic.wlgitbridge.bridge.Bridge; +import uk.ac.ic.wlgitbridge.util.Log; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class HealthCheckHandler extends AbstractHandler { + + private final Bridge bridge; + + public HealthCheckHandler(Bridge bridge) { + this.bridge = bridge; + } + + @Override + public void handle( + String target, + Request baseRequest, + HttpServletRequest request, + HttpServletResponse response + ) throws IOException { + if ("GET".equals(baseRequest.getMethod()) && "/health_check".equals(target)) { + Log.info("GET <- /api/health_check"); + baseRequest.setHandled(true); + response.setContentType("text/plain"); + response.setStatus(200); + response.getWriter().println("ok"); + } + } + +}