public static NanoResponse serve(String url, String method, Properties header, Properties parms, String post_body) {
    boolean hideParameters = true;
    try {
      // Jack priority for user-visible requests
      Thread.currentThread().setPriority(Thread.MAX_PRIORITY - 1);

      RequestType type = RequestType.requestType(url);
      RequestUri uri = new RequestUri(method, url);

      // Log the request
      hideParameters = maybeLogRequest(uri, header, parms);

      // For certain "special" requests that produce non-JSON payloads we require special handling.
      NanoResponse special = maybeServeSpecial(uri);
      if (special != null) return special;

      // Determine the Route corresponding to this request, and also fill in {parms} with the path parameters
      Route route = routesTree.lookup(uri, parms);

      //----- DEPRECATED API handling ------------
      // These APIs are broken, because they lead users to create invalid URLs. For example the endpoint
      //   /3/Frames/{frameid}/export/{path}/overwrite/{force}
      // is invalid, because it leads to URLs like this:
      //   /3/Frames/predictions_9bd5_GLM_model_R_1471148_36_on_RTMP_sid_afec_27/export//tmp/pred.csv/overwrite/TRUE
      // Here both the {frame_id} and {path} usually contain "/" (making them non-tokens), they may contain other
      // special characters not valid within URLs (for example if filename is not in ASCII); finally the use of strings
      // to represent booleans creates ambiguities: should I write "true", "True", "TRUE", or perhaps "1"?
      //
      // TODO These should be removed as soon as possible...
      if (url.startsWith("/3/Frames/")) {
        // /3/Frames/{frame_id}/export/{path}/overwrite/{force}
        if ((url.toLowerCase().endsWith("/overwrite/true") || url.toLowerCase().endsWith("/overwrite/false")) && url.contains("/export/")) {
          int i = url.indexOf("/export/");
          boolean force = url.toLowerCase().endsWith("true");
          parms.put("frame_id", url.substring(10, i));
          parms.put("path", url.substring(i+8, url.length()-15-(force?0:1)));
          parms.put("force", force? "true" : "false");
          route = findRouteByApiName("exportFrame_deprecated");
        }
        // /3/Frames/{frame_id}/export
        else if (url.endsWith("/export")) {
          parms.put("frame_id", url.substring(10, url.length()-7));
          route = findRouteByApiName("exportFrame");
        }
        // /3/Frames/{frame_id}/columns/{column}/summary
        else if (url.endsWith("/summary") && url.contains("/columns/")) {
          int i = url.indexOf("/columns/");
          parms.put("frame_id", url.substring(10, i));
          parms.put("column", url.substring(i+9, url.length()-8));
          route = findRouteByApiName("frameColumnSummary");
        }
        // /3/Frames/{frame_id}/columns/{column}/domain
        else if (url.endsWith("/domain") && url.contains("/columns/")) {
          int i = url.indexOf("/columns/");
          parms.put("frame_id", url.substring(10, i));
          parms.put("column", url.substring(i+9, url.length()-7));
          route = findRouteByApiName("frameColumnDomain");
        }
        // /3/Frames/{frame_id}/columns/{column}
        else if (url.contains("/columns/")) {
          int i = url.indexOf("/columns/");
          parms.put("frame_id", url.substring(10, i));
          parms.put("column", url.substring(i+9));
          route = findRouteByApiName("frameColumn");
        }
        // /3/Frames/{frame_id}/summary
        else if (url.endsWith("/summary")) {
          parms.put("frame_id", url.substring(10, url.length()-8));
          route = findRouteByApiName("frameSummary");
        }
        // /3/Frames/{frame_id}/light
        else if (url.endsWith("/light")) {
          parms.put("frame_id", url.substring(10, url.length()-"/light".length()));
          route = findRouteByApiName("lightFrame");
        }
        // /3/Frames/{frame_id}/columns
        else if (url.endsWith("/columns")) {
          parms.put("frame_id", url.substring(10, url.length()-8));
          route = findRouteByApiName("frameColumns");
        }
        // /3/Frames/{frame_id}
        else {
          parms.put("frame_id", url.substring(10));
          route = findRouteByApiName(method.equals("DELETE")? "deleteFrame" : "frame");
        }
      } else if (url.startsWith("/3/ModelMetrics/predictions_frame/")){
        route = findRouteByApiName("makeMetrics");
      }
      //------------------------------------------

      if (route == null) {
        // if the request is not known, treat as resource request, or 404 if not found
        if (uri.isGetMethod())
          return getResource(type, url);
        else
          return response404(method + " " + url, type);

      } else {
        Schema response = route._handler.handle(uri.getVersion(), route, parms, post_body);
        PojoUtils.filterFields(response, (String)parms.get("_include_fields"), (String)parms.get("_exclude_fields"));
        return serveSchema(response, type);
      }

    }
    catch (H2OFailException e) {
      H2OError error = e.toH2OError(url);
      Log.fatal("Caught exception (fatal to the cluster): " + error.toString());
      throw H2O.fail(serveError(error).toString());
    }
    catch (H2OModelBuilderIllegalArgumentException e) {
      H2OModelBuilderError error = e.toH2OError(url);
      Log.warn("Caught exception: " + error.toString());
      return serveSchema(new H2OModelBuilderErrorV3().fillFromImpl(error), RequestType.json);
    }
    catch (H2OAbstractRuntimeException e) {
      H2OError error = e.toH2OError(url);
      Log.warn("Caught exception: " + error.toString());
      return serveError(error);
    }
    catch (AssertionError e) {
      H2OError error = new H2OError(
              System.currentTimeMillis(),
              url,
              e.toString(),
              e.toString(),
              HttpResponseStatus.INTERNAL_SERVER_ERROR.getCode(),
              new IcedHashMapGeneric.IcedHashMapStringObject(),
              e);
      Log.err("Caught assertion error: " + error.toString());
      return serveError(error);
    }
    catch (Exception e) {
      // make sure that no Exception is ever thrown out from the request
      H2OError error = new H2OError(e, url);
      // some special cases for which we return 400 because it's likely a problem with the client request:
      if (e instanceof IllegalArgumentException || e instanceof FileNotFoundException || e instanceof MalformedURLException)
        error._http_status = HttpResponseStatus.BAD_REQUEST.getCode();
      String parmsInfo = hideParameters ? "<hidden>" : String.valueOf(parms);
      Log.err("Caught exception: " + error.toString() + ";parms=" + parmsInfo);
      return serveError(error);
    }
  }
public static NanoResponse serve ( String url , String method , Properties header , Properties parms , String post_body ) { boolean hideParameters = true ; try { Thread . currentThread ( ) . setPriority ( Thread . MAX_PRIORITY - 1 ) ; RequestType type = RequestType . requestType ( url ) ; RequestUri uri = new RequestUri ( method , url ) ; hideParameters = maybeLogRequest ( uri , header , parms ) ; NanoResponse special = maybeServeSpecial ( uri ) ; if ( special != null ) return special ; Route route = routesTree . lookup ( uri , parms ) ; if ( url . startsWith ( "/3/Frames/" ) ) { if ( ( url . toLowerCase ( ) . endsWith ( "/overwrite/true" ) || url . toLowerCase ( ) . endsWith ( "/overwrite/false" ) ) && url . contains ( "/export/" ) ) { int i = url . indexOf ( "/export/" ) ; boolean force = url . toLowerCase ( ) . endsWith ( "true" ) ; parms . put ( "frame_id" , url . substring ( 10 , i ) ) ; parms . put ( "path" , url . substring ( i + 8 , url . length ( ) - 15 - ( force ? 0 : 1 ) ) ) ; parms . put ( "force" , force ? "true" : "false" ) ; route = findRouteByApiName ( "exportFrame_deprecated" ) ; } else if ( url . endsWith ( "/export" ) ) { parms . put ( "frame_id" , url . substring ( 10 , url . length ( ) - 7 ) ) ; route = findRouteByApiName ( "exportFrame" ) ; } else if ( url . endsWith ( "/summary" ) && url . contains ( "/columns/" ) ) { int i = url . indexOf ( "/columns/" ) ; parms . put ( "frame_id" , url . substring ( 10 , i ) ) ; parms . put ( "column" , url . substring ( i + 9 , url . length ( ) - 8 ) ) ; route = findRouteByApiName ( "frameColumnSummary" ) ; } else if ( url . endsWith ( "/domain" ) && url . contains ( "/columns/" ) ) { int i = url . indexOf ( "/columns/" ) ; parms . put ( "frame_id" , url . substring ( 10 , i ) ) ; parms . put ( "column" , url . substring ( i + 9 , url . length ( ) - 7 ) ) ; route = findRouteByApiName ( "frameColumnDomain" ) ; } else if ( url . contains ( "/columns/" ) ) { int i = url . indexOf ( "/columns/" ) ; parms . put ( "frame_id" , url . substring ( 10 , i ) ) ; parms . put ( "column" , url . substring ( i + 9 ) ) ; route = findRouteByApiName ( "frameColumn" ) ; } else if ( url . endsWith ( "/summary" ) ) { parms . put ( "frame_id" , url . substring ( 10 , url . length ( ) - 8 ) ) ; route = findRouteByApiName ( "frameSummary" ) ; } else if ( url . endsWith ( "/light" ) ) { parms . put ( "frame_id" , url . substring ( 10 , url . length ( ) - "/light" . length ( ) ) ) ; route = findRouteByApiName ( "lightFrame" ) ; } else if ( url . endsWith ( "/columns" ) ) { parms . put ( "frame_id" , url . substring ( 10 , url . length ( ) - 8 ) ) ; route = findRouteByApiName ( "frameColumns" ) ; } else { parms . put ( "frame_id" , url . substring ( 10 ) ) ; route = findRouteByApiName ( method . equals ( "DELETE" ) ? "deleteFrame" : "frame" ) ; } } else if ( url . startsWith ( "/3/ModelMetrics/predictions_frame/" ) ) { route = findRouteByApiName ( "makeMetrics" ) ; } if ( route == null ) { if ( uri . isGetMethod ( ) ) return getResource ( type , url ) ; else return response404 ( method + " " + url , type ) ; } else { Schema response = route . _handler . handle ( uri . getVersion ( ) , route , parms , post_body ) ; PojoUtils . filterFields ( response , ( String ) parms . get ( "_include_fields" ) , ( String ) parms . get ( "_exclude_fields" ) ) ; return serveSchema ( response , type ) ; } } catch ( H2OFailException e ) { H2OError error = e . toH2OError ( url ) ; Log . fatal ( "Caught exception (fatal to the cluster): " + error . toString ( ) ) ; throw H2O . fail ( serveError ( error ) . toString ( ) ) ; } catch ( H2OModelBuilderIllegalArgumentException e ) { H2OModelBuilderError error = e . toH2OError ( url ) ; Log . warn ( "Caught exception: " + error . toString ( ) ) ; return serveSchema ( new H2OModelBuilderErrorV3 ( ) . fillFromImpl ( error ) , RequestType . json ) ; } catch ( H2OAbstractRuntimeException e ) { H2OError error = e . toH2OError ( url ) ; Log . warn ( "Caught exception: " + error . toString ( ) ) ; return serveError ( error ) ; } catch ( AssertionError e ) { H2OError error = new H2OError ( System . currentTimeMillis ( ) , url , e . toString ( ) , e . toString ( ) , HttpResponseStatus . INTERNAL_SERVER_ERROR . getCode ( ) , new IcedHashMapGeneric . IcedHashMapStringObject ( ) , e ) ; Log . err ( "Caught assertion error: " + error . toString ( ) ) ; return serveError ( error ) ; } catch ( Exception e ) { H2OError error = new H2OError ( e , url ) ; if ( e instanceof IllegalArgumentException || e instanceof FileNotFoundException || e instanceof MalformedURLException ) error . _http_status = HttpResponseStatus . BAD_REQUEST . getCode ( ) ; String parmsInfo = hideParameters ? "<hidden>" : String . valueOf ( parms ) ; Log . err ( "Caught exception: " + error . toString ( ) + ";parms=" + parmsInfo ) ; return serveError ( error ) ; } }
Subsequent handling of the dispatch