@Override public void handle(Request request, Response response) throws UnauthorizedException, ForbiddenException, InternalServerException { Boolean authenticated, authorized; String challenge; try { authenticated = getAuth() .authenticate( request.requestMethod(), request.uri(), request.headers("Authorization")); authorized = getAuth().authorize(request.requestMethod()); challenge = getAuth().challenge(); } catch (UnloadableConfigException | InvalidPropertyException | RuntimeException e) { throw new InternalServerException(e); } if (!authenticated) { response.header("WWW-Authenticate", challenge); throw new UnauthorizedException(); } if (!authorized) { throw new ForbiddenException(); } }
public static byte[] getOrigin(Request req, Response res) { res.header("Content-Type", "application/octet-stream"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int x = Integer.parseInt(req.params("x")); int y = Integer.parseInt(req.params("y").replaceFirst("\\.dat$", "")); StaticSiteRequest.PointRequest pr = staticSiteRequest.getPointRequest(x, y); StaticComputer computer = new StaticComputer(pr, network, new TaskStatistics()); try { computer.write(baos); return baos.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void header(String header, String value) { delegate.header(header, value); }
public static byte[] getTransitiveNetwork(Request req, Response res) { res.header("Content-Type", "application/json"); return transitive; }
public static byte[] getStopTrees(Request req, Response res) { res.header("Content-Type", "application/octet-stream"); return stopTrees; }
/** get a query json file */ public static byte[] getQuery(Request req, Response res) { res.header("Content-Type", "application/json"); return metadata; }