public static List<String> extractFieldsFromHttpRequestUri(String requestUri) {
    int paramIndex = requestUri.indexOf("?");
    Optional<String> parameterString = Optional.empty();
    if (paramIndex != -1) {
      parameterString = Optional.of(requestUri.substring(paramIndex));
      requestUri = requestUri.substring(0, paramIndex);
    }

    List<String> fields = new ArrayList<>();
    String httpPrefix = "http://";
    String httpsPrefix = "https://";
    int leftIndex = 0;
    if (requestUri.startsWith(httpPrefix)) {
      leftIndex = httpPrefix.length();
    } else if (requestUri.startsWith(httpsPrefix)) {
      leftIndex = httpsPrefix.length();
    }
    // extract host and port
    int rightIndex = requestUri.indexOf("/", leftIndex);
    String hostAndPort = requestUri.substring(leftIndex, rightIndex);
    fields.add(hostAndPort);

    // begin to extract the fields
    leftIndex = rightIndex + 1;
    rightIndex = requestUri.indexOf("/", leftIndex);
    while (rightIndex != -1) {
      String field = requestUri.substring(leftIndex, rightIndex);
      fields.add(field);
      leftIndex = rightIndex + 1;
      rightIndex = requestUri.indexOf("/", leftIndex);
    }

    if (leftIndex >= requestUri.length()) {
      // no need to continue extracting since the last field has been extracted
      return fields;
    }

    // extract the last field
    String lastField = requestUri.substring(leftIndex);
    fields.add(lastField);

    if (parameterString.isPresent()) {
      // add parameters string as there are parameters
      fields.add(parameterString.get());
    }

    return fields;
  }
@Test
  public void testExtractFieldsForGetPageApi() {
    List<String> fields = HttpRequestUtil.extractFieldsFromHttpRequestUri(mRequestUri);
    HttpRequestUri httpRequestUri = HttpRequestUri.of(fields);

    Assert.assertEquals("127.0.0.1", httpRequestUri.getHost());
    Assert.assertEquals(28080, httpRequestUri.getPort());
    Assert.assertEquals("v1", httpRequestUri.getVersion());
    Assert.assertEquals("file", httpRequestUri.getMappingPath());

    Assert.assertEquals(3, httpRequestUri.getRemainingFields().size());
    Assert.assertEquals("5f2829f08879b0e89d07174cffa8d891bdf08ba9e91218e30fe39503dd42e32c",
        httpRequestUri.getRemainingFields().get(0));
    Assert.assertEquals("page", httpRequestUri.getRemainingFields().get(1));
    Assert.assertEquals("0", httpRequestUri.getRemainingFields().get(2));

    boolean hasParametersMap = false;
    if (!httpRequestUri.getParameters().isEmpty()) {
      hasParametersMap = true;
    }
    Assert.assertEquals(mHasParametersMap, hasParametersMap);

    if (mHasParametersMap) {
      if (httpRequestUri.getParameters().get("offset") != null) {
        Assert.assertEquals(mOffset, Long.parseLong(httpRequestUri.getParameters().get("offset")));
      }
      if (httpRequestUri.getParameters().get("length") != null) {
        Assert.assertEquals(mLength, Long.parseLong(httpRequestUri.getParameters().get("length")));
      }
    }
  }