Search in sources :

Example 86 with URISyntaxException

use of java.net.URISyntaxException in project flink by apache.

the class BlobCacheSuccessTest method uploadFileGetTest.

private void uploadFileGetTest(final Configuration config, boolean cacheWorksWithoutServer, boolean cacheHasAccessToFs) {
    // First create two BLOBs and upload them to BLOB server
    final byte[] buf = new byte[128];
    final List<BlobKey> blobKeys = new ArrayList<BlobKey>(2);
    BlobServer blobServer = null;
    BlobCache blobCache = null;
    try {
        // Start the BLOB server
        blobServer = new BlobServer(config);
        final InetSocketAddress serverAddress = new InetSocketAddress(blobServer.getPort());
        // Upload BLOBs
        BlobClient blobClient = null;
        try {
            blobClient = new BlobClient(serverAddress, config);
            blobKeys.add(blobClient.put(buf));
            // Make sure the BLOB key changes
            buf[0] = 1;
            blobKeys.add(blobClient.put(buf));
        } finally {
            if (blobClient != null) {
                blobClient.close();
            }
        }
        if (cacheWorksWithoutServer) {
            // Now, shut down the BLOB server, the BLOBs must still be accessible through the cache.
            blobServer.shutdown();
            blobServer = null;
        }
        final Configuration cacheConfig;
        if (cacheHasAccessToFs) {
            cacheConfig = config;
        } else {
            // just in case parameters are still read from the server,
            // create a separate configuration object for the cache
            cacheConfig = new Configuration(config);
            cacheConfig.setString(HighAvailabilityOptions.HA_STORAGE_PATH, temporaryFolder.getRoot().getPath() + "/does-not-exist");
        }
        blobCache = new BlobCache(serverAddress, cacheConfig);
        for (BlobKey blobKey : blobKeys) {
            blobCache.getURL(blobKey);
        }
        if (blobServer != null) {
            // Now, shut down the BLOB server, the BLOBs must still be accessible through the cache.
            blobServer.shutdown();
            blobServer = null;
        }
        final URL[] urls = new URL[blobKeys.size()];
        for (int i = 0; i < blobKeys.size(); i++) {
            urls[i] = blobCache.getURL(blobKeys.get(i));
        }
        // Verify the result
        assertEquals(blobKeys.size(), urls.length);
        for (final URL url : urls) {
            assertNotNull(url);
            try {
                final File cachedFile = new File(url.toURI());
                assertTrue(cachedFile.exists());
                assertEquals(buf.length, cachedFile.length());
            } catch (URISyntaxException e) {
                fail(e.getMessage());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        if (blobServer != null) {
            blobServer.shutdown();
        }
        if (blobCache != null) {
            blobCache.shutdown();
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) File(java.io.File)

Example 87 with URISyntaxException

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

the class HarFileSystem method decodeHarURI.

/**
   * decode the raw URI to get the underlying URI
   * @param rawURI raw Har URI
   * @return filtered URI of the underlying fileSystem
   */
private URI decodeHarURI(URI rawURI, Configuration conf) throws IOException {
    String tmpAuth = rawURI.getAuthority();
    //return it
    if (tmpAuth == null) {
        //create a path 
        return FileSystem.getDefaultUri(conf);
    }
    String authority = rawURI.getAuthority();
    int i = authority.indexOf('-');
    if (i < 0) {
        throw new IOException("URI: " + rawURI + " is an invalid Har URI since '-' not found." + "  Expecting har://<scheme>-<host>/<path>.");
    }
    if (rawURI.getQuery() != null) {
        // query component not allowed
        throw new IOException("query component in Path not supported  " + rawURI);
    }
    URI tmp;
    try {
        // convert <scheme>-<host> to <scheme>://<host>
        URI baseUri = new URI(authority.replaceFirst("-", "://"));
        tmp = new URI(baseUri.getScheme(), baseUri.getAuthority(), rawURI.getPath(), rawURI.getQuery(), rawURI.getFragment());
    } catch (URISyntaxException e) {
        throw new IOException("URI: " + rawURI + " is an invalid Har URI. Expecting har://<scheme>-<host>/<path>.");
    }
    return tmp;
}
Also used : IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 88 with URISyntaxException

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

the class Path method makeQualified.

/**
   * Returns a qualified path object.
   *
   * @param defaultUri if this path is missing the scheme or authority
   * components, borrow them from this URI
   * @param workingDir if this path isn't absolute, treat it as relative to this
   * working directory
   * @return this path if it contains a scheme and authority and is absolute, or
   * a new path that includes a path and authority and is fully qualified
   */
@InterfaceAudience.LimitedPrivate({ "HDFS", "MapReduce" })
public Path makeQualified(URI defaultUri, Path workingDir) {
    Path path = this;
    if (!isAbsolute()) {
        path = new Path(workingDir, this);
    }
    URI pathUri = path.toUri();
    String scheme = pathUri.getScheme();
    String authority = pathUri.getAuthority();
    String fragment = pathUri.getFragment();
    if (scheme != null && (authority != null || defaultUri.getAuthority() == null))
        return path;
    if (scheme == null) {
        scheme = defaultUri.getScheme();
    }
    if (authority == null) {
        authority = defaultUri.getAuthority();
        if (authority == null) {
            authority = "";
        }
    }
    URI newUri = null;
    try {
        newUri = new URI(scheme, authority, normalizePath(scheme, pathUri.getPath()), null, fragment);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
    return new Path(newUri);
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException)

Example 89 with URISyntaxException

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

the class FsUrlConnection method connect.

@Override
public void connect() throws IOException {
    try {
        FileSystem fs = FileSystem.get(url.toURI(), conf);
        is = fs.open(new Path(url.getPath()));
    } catch (URISyntaxException e) {
        throw new IOException(e.toString());
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 90 with URISyntaxException

use of java.net.URISyntaxException in project camel by apache.

the class HttpsAsyncRouteTest method configureSslContextFactory.

protected void configureSslContextFactory(SslContextFactory sslContextFactory) {
    sslContextFactory.setKeyManagerPassword(pwd);
    sslContextFactory.setKeyStorePassword(pwd);
    URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
    try {
        sslContextFactory.setKeyStorePath(keyStoreUrl.toURI().getPath());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    sslContextFactory.setTrustStoreType("JKS");
}
Also used : URISyntaxException(java.net.URISyntaxException) URL(java.net.URL)

Aggregations

URISyntaxException (java.net.URISyntaxException)1633 URI (java.net.URI)1080 IOException (java.io.IOException)451 URL (java.net.URL)287 File (java.io.File)280 ArrayList (java.util.ArrayList)146 MalformedURLException (java.net.MalformedURLException)102 InputStream (java.io.InputStream)93 HashMap (java.util.HashMap)91 Test (org.testng.annotations.Test)88 Response (javax.ws.rs.core.Response)87 Builder (javax.ws.rs.client.Invocation.Builder)84 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)84 Parameters (org.testng.annotations.Parameters)84 BaseTest (org.xdi.oxauth.BaseTest)84 ResponseType (org.xdi.oxauth.model.common.ResponseType)84 AuthorizationRequest (org.xdi.oxauth.client.AuthorizationRequest)78 Test (org.junit.Test)75 REGISTRATION_CLIENT_URI (org.xdi.oxauth.model.register.RegisterResponseParam.REGISTRATION_CLIENT_URI)72 Intent (android.content.Intent)63