Search in sources :

Example 81 with URI

use of java.net.URI in project hadoop by apache.

the class TestDefaultUri method tetGetDefaultUriTrailingSlash.

@Test
public void tetGetDefaultUriTrailingSlash() {
    conf.set(FS_DEFAULT_NAME_KEY, "hdfs://nn_host/");
    URI uri = FileSystem.getDefaultUri(conf);
    assertThat(uri.getScheme(), is("hdfs"));
    assertThat(uri.getAuthority(), is("nn_host"));
}
Also used : URI(java.net.URI) Test(org.junit.Test)

Example 82 with URI

use of java.net.URI in project hadoop by apache.

the class TestDelegateToFsCheckPath method testCheckPathWithoutDefaultPort.

@Test
public void testCheckPathWithoutDefaultPort() throws URISyntaxException, IOException {
    URI uri = new URI("dummy://dummy-host");
    AbstractFileSystem afs = new DummyDelegateToFileSystem(uri, new UnOverrideDefaultPortFileSystem());
    afs.checkPath(new Path("dummy://dummy-host"));
}
Also used : URI(java.net.URI) Test(org.junit.Test)

Example 83 with URI

use of java.net.URI in project hadoop by apache.

the class TestDelegateToFsCheckPath method testCheckPathWithDefaultPort.

@Test
public void testCheckPathWithDefaultPort() throws URISyntaxException, IOException {
    URI uri = new URI(String.format("dummy://dummy-host:%d", OverrideDefaultPortFileSystem.DEFAULT_PORT));
    AbstractFileSystem afs = new DummyDelegateToFileSystem(uri, new OverrideDefaultPortFileSystem());
    afs.checkPath(new Path("dummy://dummy-host/user/john/test"));
}
Also used : URI(java.net.URI) Test(org.junit.Test)

Example 84 with URI

use of java.net.URI in project groovy by apache.

the class AbstractHttpServlet method generateNamePrefixOnce.

protected void generateNamePrefixOnce() {
    URI uri = null;
    String realPath = servletContext.getRealPath("/");
    //prevent NPE if in .war
    if (realPath != null) {
        uri = new File(realPath).toURI();
    }
    try {
        URL res = servletContext.getResource("/");
        if (res != null) {
            uri = res.toURI();
        }
    } catch (MalformedURLException ignore) {
    } catch (URISyntaxException ignore) {
    }
    if (uri != null) {
        try {
            namePrefix = uri.toURL().toExternalForm();
            return;
        } catch (MalformedURLException e) {
            log("generateNamePrefixOnce [ERROR] Malformed URL for base path / == '" + uri + '\'', e);
        }
    }
    namePrefix = "";
}
Also used : MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Example 85 with URI

use of java.net.URI in project hadoop by apache.

the class NetUtils method createSocketAddr.

/**
   * Create an InetSocketAddress from the given target string and
   * default port. If the string cannot be parsed correctly, the
   * <code>configName</code> parameter is used as part of the
   * exception message, allowing the user to better diagnose
   * the misconfiguration.
   *
   * @param target a string of either "host" or "host:port"
   * @param defaultPort the default port if <code>target</code> does not
   *                    include a port number
   * @param configName the name of the configuration from which
   *                   <code>target</code> was loaded. This is used in the
   *                   exception message in the case that parsing fails. 
   */
public static InetSocketAddress createSocketAddr(String target, int defaultPort, String configName) {
    String helpText = "";
    if (configName != null) {
        helpText = " (configuration property '" + configName + "')";
    }
    if (target == null) {
        throw new IllegalArgumentException("Target address cannot be null." + helpText);
    }
    target = target.trim();
    boolean hasScheme = target.contains("://");
    URI uri = null;
    try {
        uri = hasScheme ? URI.create(target) : URI.create("dummyscheme://" + target);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Does not contain a valid host:port authority: " + target + helpText);
    }
    String host = uri.getHost();
    int port = uri.getPort();
    if (port == -1) {
        port = defaultPort;
    }
    String path = uri.getPath();
    if ((host == null) || (port < 0) || (!hasScheme && path != null && !path.isEmpty())) {
        throw new IllegalArgumentException("Does not contain a valid host:port authority: " + target + helpText);
    }
    return createSocketAddrForHost(host, port);
}
Also used : URI(java.net.URI)

Aggregations

URI (java.net.URI)5680 Test (org.junit.Test)1852 URISyntaxException (java.net.URISyntaxException)1016 IOException (java.io.IOException)749 File (java.io.File)531 HashMap (java.util.HashMap)458 ArrayList (java.util.ArrayList)452 Test (org.testng.annotations.Test)394 Configuration (org.apache.hadoop.conf.Configuration)321 Path (org.apache.hadoop.fs.Path)267 URL (java.net.URL)266 Map (java.util.Map)262 Response (javax.ws.rs.core.Response)218 List (java.util.List)184 InputStream (java.io.InputStream)154 HashSet (java.util.HashSet)136 FileSystem (org.apache.hadoop.fs.FileSystem)135 RequestContext (com.linkedin.r2.message.RequestContext)129 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)128 RestRequest (com.linkedin.r2.message.rest.RestRequest)112