Search in sources :

Example 11 with URI

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

the class AvroComponent method createEndpoint.

/**
     * A factory method allowing derived components to create a new endpoint
     * from the given URI, remaining path and optional parameters
     *
     * @param uri        the full URI of the endpoint
     * @param remaining  the remaining part of the URI without the query
     *                   parameters or component prefix
     * @param parameters the optional parameters passed in
     * @return a newly created endpoint or null if the endpoint cannot be
     *         created based on the inputs
     */
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    AvroConfiguration config;
    if (configuration != null) {
        config = configuration.copy();
    } else {
        config = new AvroConfiguration();
    }
    URI endpointUri = new URI(URISupport.normalizeUri(remaining));
    applyToConfiguration(config, endpointUri, parameters);
    if (AvroConstants.AVRO_NETTY_TRANSPORT.equals(endpointUri.getScheme())) {
        return new AvroNettyEndpoint(remaining, this, config);
    } else if (AvroConstants.AVRO_HTTP_TRANSPORT.equals(endpointUri.getScheme())) {
        return new AvroHttpEndpoint(remaining, this, config);
    } else {
        throw new IllegalArgumentException("Unknown avro scheme. Should use either netty or http.");
    }
}
Also used : URI(java.net.URI)

Example 12 with URI

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

the class QueueServiceUtil method createQueueClient.

public static CloudQueue createQueueClient(QueueServiceConfiguration cfg) throws Exception {
    CloudQueue client = (CloudQueue) getConfiguredClient(cfg);
    if (client == null) {
        URI uri = prepareStorageQueueUri(cfg);
        StorageCredentials creds = getAccountCredentials(cfg);
        client = new CloudQueue(uri, creds);
    }
    return client;
}
Also used : StorageCredentials(com.microsoft.azure.storage.StorageCredentials) URI(java.net.URI) CloudQueue(com.microsoft.azure.storage.queue.CloudQueue)

Example 13 with URI

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

the class QueueServiceUtilTest method testPrepareUri.

@Test
public void testPrepareUri() throws Exception {
    registerCredentials();
    QueueServiceComponent component = new QueueServiceComponent(context);
    QueueServiceEndpoint endpoint = (QueueServiceEndpoint) component.createEndpoint("azure-queue://camelazure/testqueue?credentials=#creds");
    URI uri = QueueServiceUtil.prepareStorageQueueUri(endpoint.getConfiguration());
    assertEquals("https://camelazure.queue.core.windows.net/testqueue/messages", uri.toString());
}
Also used : URI(java.net.URI) Test(org.junit.Test)

Example 14 with URI

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

the class BlobServiceUtil method createBlobContainerClient.

public static CloudBlobContainer createBlobContainerClient(BlobServiceConfiguration cfg) throws Exception {
    URI uri = prepareStorageBlobUri(cfg, false);
    StorageCredentials creds = getAccountCredentials(cfg);
    return new CloudBlobContainer(uri, creds);
}
Also used : StorageCredentials(com.microsoft.azure.storage.StorageCredentials) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) URI(java.net.URI)

Example 15 with URI

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

the class DefaultPackageScanClassResolver method find.

protected void find(PackageScanFilter test, String packageName, ClassLoader loader, Set<Class<?>> classes) {
    if (log.isTraceEnabled()) {
        log.trace("Searching for: {} in package: {} using classloader: {}", new Object[] { test, packageName, loader.getClass().getName() });
    }
    Enumeration<URL> urls;
    try {
        urls = getResources(loader, packageName);
        if (!urls.hasMoreElements()) {
            log.trace("No URLs returned by classloader");
        }
    } catch (IOException ioe) {
        log.warn("Cannot read package: " + packageName, ioe);
        return;
    }
    while (urls.hasMoreElements()) {
        URL url = null;
        try {
            url = urls.nextElement();
            log.trace("URL from classloader: {}", url);
            url = customResourceLocator(url);
            String urlPath = url.getFile();
            urlPath = URLDecoder.decode(urlPath, "UTF-8");
            if (log.isTraceEnabled()) {
                log.trace("Decoded urlPath: {} with protocol: {}", urlPath, url.getProtocol());
            }
            // If it's a file in a directory, trim the stupid file: spec
            if (urlPath.startsWith("file:")) {
                // to remedy this then create new path without using the URLDecoder
                try {
                    urlPath = new URI(url.getFile()).getPath();
                } catch (URISyntaxException e) {
                // fallback to use as it was given from the URLDecoder
                // this allows us to work on Windows if users have spaces in paths
                }
                if (urlPath.startsWith("file:")) {
                    urlPath = urlPath.substring(5);
                }
            }
            // osgi bundles should be skipped
            if (url.toString().startsWith("bundle:") || urlPath.startsWith("bundle:")) {
                log.trace("Skipping OSGi bundle: {}", url);
                continue;
            }
            // bundle resource should be skipped
            if (url.toString().startsWith("bundleresource:") || urlPath.startsWith("bundleresource:")) {
                log.trace("Skipping bundleresource: {}", url);
                continue;
            }
            // Else it's in a JAR, grab the path to the jar
            if (urlPath.indexOf('!') > 0) {
                urlPath = urlPath.substring(0, urlPath.indexOf('!'));
            }
            log.trace("Scanning for classes in: {} matching criteria: {}", urlPath, test);
            File file = new File(urlPath);
            if (file.isDirectory()) {
                log.trace("Loading from directory using file: {}", file);
                loadImplementationsInDirectory(test, packageName, file, classes);
            } else {
                InputStream stream;
                if (urlPath.startsWith("http:") || urlPath.startsWith("https:") || urlPath.startsWith("sonicfs:") || isAcceptableScheme(urlPath)) {
                    // load resources using http/https, sonicfs and other acceptable scheme
                    // sonic ESB requires to be loaded using a regular URLConnection
                    log.trace("Loading from jar using url: {}", urlPath);
                    URL urlStream = new URL(urlPath);
                    URLConnection con = urlStream.openConnection();
                    // disable cache mainly to avoid jar file locking on Windows
                    con.setUseCaches(false);
                    stream = con.getInputStream();
                } else {
                    log.trace("Loading from jar using file: {}", file);
                    stream = new FileInputStream(file);
                }
                loadImplementationsInJar(test, packageName, stream, urlPath, classes, jarCache);
            }
        } catch (IOException e) {
            // use debug logging to avoid being to noisy in logs
            log.debug("Cannot read entries in url: " + url, e);
        }
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) URL(java.net.URL) URLConnection(java.net.URLConnection) FileInputStream(java.io.FileInputStream)

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