コード例 #1
0
ファイル: URITest.java プロジェクト: llnull/platform_dalvik
  /** @tests java.net.URI(java.lang.String) */
  public void test_ConstructorLjava_lang_String() throws URISyntaxException {
    // Regression test for HARMONY-23
    try {
      new URI("%3");
      fail("Assert 0: URI constructor failed to throw exception on invalid input.");
    } catch (URISyntaxException e) {
      // Expected
      assertEquals("Assert 1: Wrong index in URISyntaxException.", 0, e.getIndex());
    }

    // Regression test for HARMONY-25
    // if port value is negative, the authority should be considered registry-based.
    URI uri = new URI("http://host:-8096/path/index.html");
    assertEquals("Assert 2: returned wrong port value,", -1, uri.getPort());
    assertNull("Assert 3: returned wrong host value,", uri.getHost());
    try {
      uri.parseServerAuthority();
      fail("Assert 4: Expected URISyntaxException");
    } catch (URISyntaxException e) {
      // Expected
    }

    uri = new URI("http", "//myhost:-8096", null);
    assertEquals("Assert 5: returned wrong port value,", -1, uri.getPort());
    assertNull("Assert 6: returned wrong host value,", uri.getHost());
    try {
      uri.parseServerAuthority();
      fail("Assert 7: Expected URISyntaxException");
    } catch (URISyntaxException e) {
      // Expected
    }
  }
コード例 #2
0
ファイル: URITest.java プロジェクト: llnull/platform_dalvik
 /** @tests java.net.URI(java.lang.String, java.lang.String, java.lang.String) */
 public void test_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_String() {
   // scheme can not be empty string
   try {
     new URI("", "//authority/path", "fragment");
     fail("Assert 0: Expected URISyntaxException with empty URI scheme");
   } catch (URISyntaxException e) {
     // Expected
     assertEquals("Assert 1: Wrong index in URISyntaxException.", 0, e.getIndex());
   }
 }
コード例 #3
0
ファイル: Href.java プロジェクト: sebing/takes
 /**
  * Parses the specified content to create the corresponding {@code URI} instance. In case of an
  * {@code URISyntaxException}, it will automatically encode the character that causes the issue
  * then it will try again if it is possible otherwise an {@code IllegalArgumentException} will be
  * thrown.
  *
  * @param txt The content to parse
  * @return The {@code URI} corresponding to the specified content.
  * @throws IllegalArgumentException in case the content could not be parsed
  * @throws IllegalStateException in case an invalid character could not be encoded properly.
  */
 private static URI createURI(final String txt) {
   URI result;
   try {
     result = new URI(txt);
   } catch (final URISyntaxException ex) {
     final int index = ex.getIndex();
     if (index == -1) {
       throw new IllegalArgumentException(ex.getMessage(), ex);
     }
     final StringBuilder value = new StringBuilder(txt);
     value.replace(index, index + 1, Href.encode(value.substring(index, index + 1)));
     result = Href.createURI(value.toString());
   }
   return result;
 }
コード例 #4
0
  private void healthCheck(Id id) {
    final HealthChecks healthChecks = conf(id).getHealthChecks();
    for (Ping ping : healthChecks.getPings()) {
      URI uri;
      if (ping.getUrl().toString().contains(CONTAINER_IP_PATTERN)) {
        try {
          uri =
              new URI(
                  ping.getUrl()
                      .toString()
                      .replace(CONTAINER_IP_PATTERN, getIPAddresses().get(id.toString())));
        } catch (URISyntaxException e) {
          throw new OrchestrationException(
              "Bad health check URI syntax: "
                  + e.getMessage()
                  + ", input: "
                  + e.getInput()
                  + ", index:"
                  + e.getIndex());
        }
      } else {
        uri = ping.getUrl();
      }
      logger.info(String.format("Pinging %s for pattern \"%s\"", uri, ping.getPattern()));

      if (!Pinger.ping(uri, ping.getPattern(), ping.getTimeout())) {
        throw new OrchestrationException(
            "timeout waiting for "
                + uri
                + " for "
                + ping.getTimeout()
                + " with pattern "
                + ping.getPattern());
      }
    }
  }