use of java.net.URISyntaxException in project camel by apache.
the class HttpsRouteTest 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");
}
use of java.net.URISyntaxException in project camel by apache.
the class RestDefinition method asRouteApiDefinition.
/**
* Transforms the rest api configuration into a {@link org.apache.camel.model.RouteDefinition} which
* Camel routing engine uses to service the rest api docs.
*/
public static RouteDefinition asRouteApiDefinition(CamelContext camelContext, RestConfiguration configuration) {
RouteDefinition answer = new RouteDefinition();
// create the from endpoint uri which is using the rest-api component
String from = "rest-api:" + configuration.getApiContextPath();
// append options
Map<String, Object> options = new HashMap<String, Object>();
String routeId = configuration.getApiContextRouteId();
if (routeId == null) {
routeId = answer.idOrCreate(camelContext.getNodeIdFactory());
}
options.put("routeId", routeId);
if (configuration.getComponent() != null && !configuration.getComponent().isEmpty()) {
options.put("componentName", configuration.getComponent());
}
if (configuration.getApiContextIdPattern() != null) {
options.put("contextIdPattern", configuration.getApiContextIdPattern());
}
if (!options.isEmpty()) {
String query;
try {
query = URISupport.createQueryString(options);
} catch (URISyntaxException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
from = from + "?" + query;
}
// we use the same uri as the producer (so we have a little route for the rest api)
String to = from;
answer.fromRest(from);
answer.id(routeId);
answer.to(to);
return answer;
}
use of java.net.URISyntaxException 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);
}
}
}
use of java.net.URISyntaxException in project camel by apache.
the class HttpHelper method createMethod.
/**
* Creates the HttpMethod to use to call the remote server, often either its GET or POST.
*
* @param exchange the exchange
* @return the created method
* @throws URISyntaxException
*/
public static HttpMethods createMethod(Exchange exchange, HttpCommonEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
// is a query string provided in the endpoint URI or in a header (header overrules endpoint)
String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
// We need also check the HTTP_URI header query part
String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
// resolve placeholders in uriString
try {
uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
}
if (uriString != null) {
// in case the URI string contains unsafe characters
uriString = UnsafeUriCharactersEncoder.encodeHttpURI(uriString);
URI uri = new URI(uriString);
queryString = uri.getQuery();
}
if (queryString == null) {
queryString = endpoint.getHttpUri().getRawQuery();
}
HttpMethods answer;
if (endpoint.getHttpMethod() != null) {
// endpoint configured take precedence
answer = endpoint.getHttpMethod();
} else {
// compute what method to use either GET or POST (header take precedence)
HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
if (m != null) {
// always use what end-user provides in a header
answer = m;
} else if (queryString != null) {
// if a query string is provided then use GET
answer = HttpMethods.GET;
} else {
// fallback to POST if we have payload, otherwise GET
answer = hasPayload ? HttpMethods.POST : HttpMethods.GET;
}
}
return answer;
}
use of java.net.URISyntaxException in project camel by apache.
the class HttpMethodHelper method createMethod.
/**
* Creates the HttpMethod to use to call the remote server, often either its GET or POST.
*
* @param exchange the exchange
* @return the created method
* @throws URISyntaxException
*/
public static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
// is a query string provided in the endpoint URI or in a header (header
// overrules endpoint)
String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
// We need also check the HTTP_URI header query part
String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
// resolve placeholders in uriString
try {
uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
} catch (Exception e) {
throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
}
if (uriString != null) {
// in case the URI string contains unsafe characters
uriString = UnsafeUriCharactersEncoder.encodeHttpURI(uriString);
URI uri = new URI(uriString);
queryString = uri.getQuery();
}
if (queryString == null) {
queryString = endpoint.getHttpUri().getRawQuery();
}
// compute what method to use either GET or POST
HttpMethods answer;
if (endpoint.getHttpMethod() != null) {
// endpoint configured take precedence
answer = HttpMethods.valueOf(endpoint.getHttpMethod().name());
} else {
// compute what method to use either GET or POST (header take precedence)
HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
if (m != null) {
// always use what end-user provides in a header
answer = m;
} else if (queryString != null) {
// if a query string is provided then use GET
answer = HttpMethods.GET;
} else {
// fallback to POST if we have payload, otherwise GET
answer = hasPayload ? HttpMethods.POST : HttpMethods.GET;
}
}
return answer;
}
Aggregations