wip: status handler

This commit is contained in:
Shane Kilkelly 2020-06-17 16:05:53 +01:00
parent cb3508223f
commit eba6c907e9
2 changed files with 41 additions and 0 deletions

View file

@ -128,6 +128,7 @@ public class GitBridgeServer {
api.setContextPath("/api");
HandlerCollection handlers = new HandlerList();
handlers.addHandler(new StatusHandler(bridge));
handlers.addHandler(initResourceHandler());
handlers.addHandler(new PostbackHandler(bridge));
handlers.addHandler(new DefaultHandler());

View file

@ -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 StatusHandler extends AbstractHandler {
private final Bridge bridge;
public StatusHandler(Bridge bridge) {
this.bridge = bridge;
}
@Override
public void handle(
String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response
) throws IOException {
if ("GET".equals(baseRequest.getMethod()) && "/status".equals(target)) {
Log.info("GET <- /api/status");
baseRequest.setHandled(true);
response.setContentType("text/plain");
response.setStatus(200);
response.getWriter().println("ok");
}
}
}