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.");
}
}
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;
}
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());
}
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);
}
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);
}
}
}
Aggregations