示例#1
0
文件: Get.java 项目: tanthm/h2o-2
  @Override
  public NanoHTTPD.Response serve(NanoHTTPD server, Properties args, RequestType type) {
    if (type == RequestType.json) {
      JsonObject resp = new JsonObject();
      resp.addProperty(ERROR, "This request is only provided for browser connections");
      return wrap(server, resp);
    } else if (type != RequestType.www) {
      return super.serve(server, args, type);
    }

    String query = checkArguments(args, type);
    if (query != null) return wrap(server, query, type);
    try {
      Value val = _key.value();
      Key key = val._key;
      if (!key.user_allowed()) return wrap(server, build(Response.error("Not a user key: " + key)));
      // HTML file save of Value
      NanoHTTPD.Response res =
          server.new Response(NanoHTTPD.HTTP_OK, NanoHTTPD.MIME_DEFAULT_BINARY, val.openStream());
      res.addHeader("Content-Length", Long.toString(val.length()));
      res.addHeader("Content-Disposition", "attachment; filename=" + key.toString());
      return res;
    } catch (Throwable e) {
      return wrap(server, build(Response.error(e)));
    }
  }
示例#2
0
 public NanoHTTPD.Response serve(NanoHTTPD server, Properties args, RequestType type) {
   // Needs to be done also for help to initialize or argument records
   String query = checkArguments(args, type);
   switch (type) {
     case help:
       return wrap(server, build(Response.done(serveHelp())));
     case json:
     case www:
       if (log()) {
         String log = getClass().getSimpleName();
         for (Object arg : args.keySet()) {
           String value = args.getProperty((String) arg);
           if (value != null && value.length() != 0) log += " " + arg + "=" + value;
         }
         Log.debug(Sys.HTTPD, log);
       }
       if (query != null) return wrap(server, query, type);
       long time = System.currentTimeMillis();
       Response response = serve();
       response.setTimeStart(time);
       if (type == RequestType.json) return wrap(server, response.toJson());
       return wrap(server, build(response));
     case debug:
       response = serve_debug();
       return wrap(server, build(response));
     case query:
       return wrap(server, query);
     default:
       throw new RuntimeException("Invalid request type " + type.toString());
   }
 }
示例#3
0
 @Override
 protected Response serve() {
   try {
     Log.info("Unlocking all locked keys on the cluster.");
     UnlockTask cleanup = new UnlockTask();
     cleanup.invokeOnAllNodes();
   } catch (Throwable e) {
     return Response.error(e);
   }
   return Response.done(this);
 }
示例#4
0
 public static Response redirect(Request req, Key jobkey, Key dest) {
   return Response.redirect(req, "/2/DRFProgressPage", JOB_KEY, jobkey, DEST_KEY, dest);
 }
示例#5
0
文件: GLM2.java 项目: jayfans3/h2o
 @Override
 public Response redirect() {
   String n = GridSearchProgress.class.getSimpleName();
   return Response.redirect(this, n, "job_key", job_key, "destination_key", destination_key);
 }
示例#6
0
 @Override
 public Response redirect() {
   String redirectName = new GridSearchProgress().href();
   return Response.redirect(
       this, redirectName, "job_key", job_key, "destination_key", destination_key);
 }
示例#7
0
 @Override
 protected Response jobDone(final Job job, final Key dst) {
   return Response.done(this);
 }