Ejemplo n.º 1
0
  @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();
    }
  }
Ejemplo n.º 2
0
 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);
   }
 }
Ejemplo n.º 3
0
 @Override
 public void header(String header, String value) {
   delegate.header(header, value);
 }
Ejemplo n.º 4
0
 public static byte[] getTransitiveNetwork(Request req, Response res) {
   res.header("Content-Type", "application/json");
   return transitive;
 }
Ejemplo n.º 5
0
 public static byte[] getStopTrees(Request req, Response res) {
   res.header("Content-Type", "application/octet-stream");
   return stopTrees;
 }
Ejemplo n.º 6
0
 /** get a query json file */
 public static byte[] getQuery(Request req, Response res) {
   res.header("Content-Type", "application/json");
   return metadata;
 }