use of java.net.URISyntaxException in project hazelcast by hazelcast.
the class ServiceLoader method findHighestReachableClassLoader.
private static ClassLoader findHighestReachableClassLoader(URL url, ClassLoader classLoader, String resourceName) {
if (classLoader.getParent() == null) {
return classLoader;
}
ClassLoader highestClassLoader = classLoader;
ClassLoader current = classLoader;
while (current.getParent() != null) {
// if we have a filtering classloader in hierarchy, we need to stop!
if (FILTERING_CLASS_LOADER.equals(current.getClass().getCanonicalName())) {
break;
}
ClassLoader parent = current.getParent();
try {
Enumeration<URL> resources = parent.getResources(resourceName);
if (resources != null) {
while (resources.hasMoreElements()) {
URL resourceURL = resources.nextElement();
if (url.toURI().equals(resourceURL.toURI())) {
highestClassLoader = parent;
}
}
}
} catch (IOException ignore) {
// we want to ignore failures and keep searching
ignore(ignore);
} catch (URISyntaxException ignore) {
// we want to ignore failures and keep searching
ignore(ignore);
}
// going on with the search upwards the hierarchy
current = current.getParent();
}
return highestClassLoader;
}
use of java.net.URISyntaxException in project hazelcast by hazelcast.
the class HazelcastServerCachingProvider method getOrCreateInstance.
@Override
protected HazelcastInstance getOrCreateInstance(URI uri, ClassLoader classLoader, Properties properties) throws URISyntaxException, IOException {
HazelcastInstance instanceItself = (HazelcastInstance) properties.get(HAZELCAST_INSTANCE_ITSELF);
// If instance itself is specified via properties, get instance through it.
if (instanceItself != null) {
return instanceItself;
}
String location = properties.getProperty(HAZELCAST_CONFIG_LOCATION);
String instanceName = properties.getProperty(HAZELCAST_INSTANCE_NAME);
// If config location is specified via properties, get instance through it.
if (location != null) {
Config config = getConfigFromLocation(location, classLoader, instanceName);
return HazelcastInstanceFactory.getOrCreateHazelcastInstance(config);
}
// If instance name is specified via properties, get instance through it.
if (instanceName != null) {
return Hazelcast.getHazelcastInstanceByName(instanceName);
}
// resolving HazelcastInstance via properties failed, try with URI as XML configuration file location
final boolean isDefaultURI = (uri == null || uri.equals(getDefaultURI()));
if (!isDefaultURI) {
try {
// try locating a Hazelcast config at CacheManager URI
Config config = getConfigFromLocation(uri, classLoader, null);
return HazelcastInstanceFactory.getOrCreateHazelcastInstance(config);
} catch (Exception e) {
if (LOGGER.isFinestEnabled()) {
LOGGER.finest("Could not get or create hazelcast instance from URI " + uri.toString(), e);
}
}
try {
// try again, this time interpreting CacheManager URI as hazelcast instance name
return Hazelcast.getHazelcastInstanceByName(uri.toString());
} catch (Exception e) {
if (LOGGER.isFinestEnabled()) {
LOGGER.finest("Could not get hazelcast instance from instance name" + uri.toString(), e);
}
}
// could not locate hazelcast instance, return null and an exception will be thrown from invoker
return null;
} else {
return getDefaultInstance();
}
}
use of java.net.URISyntaxException in project hazelcast by hazelcast.
the class HazelcastServerCachingProvider method getConfigFromLocation.
private Config getConfigFromLocation(URI location, ClassLoader classLoader, String instanceName) throws URISyntaxException, IOException {
String scheme = location.getScheme();
if (scheme == null) {
// It may be a place holder
location = new URI(System.getProperty(location.getRawSchemeSpecificPart()));
}
ClassLoader theClassLoader = classLoader == null ? getDefaultClassLoader() : classLoader;
final URL configURL;
if ("classpath".equals(scheme)) {
configURL = theClassLoader.getResource(location.getRawSchemeSpecificPart());
} else if ("file".equals(scheme) || "http".equals(scheme) || "https".equals(scheme)) {
configURL = location.toURL();
} else {
throw new URISyntaxException(location.toString(), "Unsupported protocol in configuration location URL");
}
try {
return getConfig(configURL, theClassLoader, instanceName);
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
use of java.net.URISyntaxException in project facebook-api-android-maven by avianey.
the class UrlRedirectCache method getRedirectedUri.
static URI getRedirectedUri(Context context, URI uri) {
if (uri == null) {
return null;
}
String uriString = uri.toString();
InputStreamReader reader = null;
try {
InputStream stream;
FileLruCache cache = getCache(context);
boolean redirectExists = false;
while ((stream = cache.get(uriString, REDIRECT_CONTENT_TAG)) != null) {
redirectExists = true;
// Get the redirected url
reader = new InputStreamReader(stream);
char[] buffer = new char[128];
int bufferLength;
StringBuilder urlBuilder = new StringBuilder();
while ((bufferLength = reader.read(buffer, 0, buffer.length)) > 0) {
urlBuilder.append(buffer, 0, bufferLength);
}
Utility.closeQuietly(reader);
// Iterate to the next url in the redirection
uriString = urlBuilder.toString();
}
if (redirectExists) {
return new URI(uriString);
}
} catch (URISyntaxException e) {
// caching is best effort, so ignore the exception
} catch (IOException ioe) {
} finally {
Utility.closeQuietly(reader);
}
return null;
}
use of java.net.URISyntaxException in project spring-security by spring-projects.
the class HeadersBeanDefinitionParser method parseFrameOptionsElement.
private void parseFrameOptionsElement(boolean addIfNotPresent, Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(XFrameOptionsHeaderWriter.class);
Element frameElt = element == null ? null : DomUtils.getChildElementByTagName(element, FRAME_OPTIONS_ELEMENT);
if (frameElt != null) {
String header = getAttribute(frameElt, ATT_POLICY, null);
boolean disabled = "true".equals(getAttribute(frameElt, ATT_DISABLED, "false"));
if (disabled && header != null) {
this.attrNotAllowed(parserContext, ATT_DISABLED, ATT_POLICY, frameElt);
}
if (!StringUtils.hasText(header)) {
header = "DENY";
}
if (ALLOW_FROM.equals(header)) {
String strategyRef = getAttribute(frameElt, ATT_REF, null);
String strategy = getAttribute(frameElt, ATT_STRATEGY, null);
if (StringUtils.hasText(strategy) && StringUtils.hasText(strategyRef)) {
parserContext.getReaderContext().error("Only one of 'strategy' or 'strategy-ref' can be set.", frameElt);
} else if (strategyRef != null) {
builder.addConstructorArgReference(strategyRef);
} else if (strategy != null) {
String value = getAttribute(frameElt, ATT_VALUE, null);
if (!StringUtils.hasText(value)) {
parserContext.getReaderContext().error("Strategy requires a 'value' to be set.", frameElt);
}
// static, whitelist, regexp
if ("static".equals(strategy)) {
try {
builder.addConstructorArgValue(new StaticAllowFromStrategy(new URI(value)));
} catch (URISyntaxException e) {
parserContext.getReaderContext().error("'value' attribute doesn't represent a valid URI.", frameElt, e);
}
} else {
BeanDefinitionBuilder allowFromStrategy;
if ("whitelist".equals(strategy)) {
allowFromStrategy = BeanDefinitionBuilder.rootBeanDefinition(WhiteListedAllowFromStrategy.class);
allowFromStrategy.addConstructorArgValue(StringUtils.commaDelimitedListToSet(value));
} else {
allowFromStrategy = BeanDefinitionBuilder.rootBeanDefinition(RegExpAllowFromStrategy.class);
allowFromStrategy.addConstructorArgValue(value);
}
String fromParameter = getAttribute(frameElt, ATT_FROM_PARAMETER, "from");
allowFromStrategy.addPropertyValue("allowFromParameterName", fromParameter);
builder.addConstructorArgValue(allowFromStrategy.getBeanDefinition());
}
} else {
parserContext.getReaderContext().error("One of 'strategy' and 'strategy-ref' must be set.", frameElt);
}
} else {
builder.addConstructorArgValue(header);
}
if (disabled) {
return;
}
}
if (addIfNotPresent || frameElt != null) {
headerWriters.add(builder.getBeanDefinition());
}
}
Aggregations