Java Code Examples for java.net.URI#parseServerAuthority()

The following examples show how to use java.net.URI#parseServerAuthority() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnitTestConnectionService.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a "key" {@code URI} by dropping the <i>user-info</i>, <i>path</i>, <i>query</i>, and <i>fragment</i>
 * portions of the {@code URI}.
 *
 * @param requestURI the {@code URI} for which the key is to be generated
 *
 * @return a {@code URI} instance with the <i>user-info</i>, <i>path</i>, <i>query</i>, and <i>fragment</i> discarded
 */
private static URI createKey(URI requestURI) {
  try {
    URI keyURI = requestURI.parseServerAuthority();
    return new URI(keyURI.getScheme(), null, keyURI.getHost(), keyURI.getPort(), null, null, null);
  } catch (URISyntaxException e) {
    throw new IllegalArgumentException(e);
  }
}
 
Example 2
Source File: URITest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testParseServerAuthorityInvalidPortMinus() throws Exception {
    URI uri = new URI("http://host:-2/");
    assertEquals("host:-2", uri.getAuthority());
    assertNull(uri.getHost());
    assertEquals(-1, uri.getPort());
    try {
        uri.parseServerAuthority();
        fail();
    } catch (URISyntaxException expected) {
    }
}
 
Example 3
Source File: URITest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testParseServerAuthorityInvalidPortPlus() throws Exception {
    URI uri = new URI("http://host:+2/");
    assertEquals("host:+2", uri.getAuthority());
    assertNull(uri.getHost());
    assertEquals(-1, uri.getPort());
    try {
        uri.parseServerAuthority();
        fail();
    } catch (URISyntaxException expected) {
    }
}
 
Example 4
Source File: URITest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testParseServerAuthorityInvalidPortNonASCII() throws Exception {
    URI uri = new URI("http://host:١٢٣/"); // 123 in arabic
    assertEquals("host:١٢٣", uri.getAuthority());
    assertNull(uri.getHost());
    assertEquals(-1, uri.getPort());
    try {
        uri.parseServerAuthority();
        fail();
    } catch (URISyntaxException expected) {
    }
}
 
Example 5
Source File: URITest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testParseServerAuthorityOmittedAuthority() throws Exception {
    URI uri = new URI("http:file");
    uri.parseServerAuthority(); // does nothing!
    assertNull(uri.getAuthority());
    assertNull(uri.getHost());
    assertEquals(-1, uri.getPort());
}