use of java.util.ServiceConfigurationError in project Payara by payara.
the class GlassFishRuntime method getRuntimeBuilder.
private static RuntimeBuilder getRuntimeBuilder(BootstrapProperties bootstrapProperties, ClassLoader cl) throws GlassFishException {
// StringBuilder sb = new StringBuilder("Launcher Class Loader = " + cl);
// if (cl instanceof URLClassLoader) {
// sb.append("has following Class Path: ");
// for (URL url : URLClassLoader.class.cast(cl).getURLs()) {
// sb.append(url).append(", ");
// }
// }
// System.out.println(sb);
Iterator<RuntimeBuilder> runtimeBuilders = ServiceLoader.load(RuntimeBuilder.class, cl).iterator();
while (runtimeBuilders.hasNext()) {
try {
RuntimeBuilder builder = runtimeBuilders.next();
logger.logp(Level.FINE, "GlassFishRuntime", "getRuntimeBuilder", "builder = {0}", new Object[] { builder });
if (builder.handles(bootstrapProperties)) {
return builder;
}
} catch (ServiceConfigurationError sce) {
// Ignore the exception and move ahead to the next builder.
logger.logp(Level.FINE, "GlassFishRuntime", "getRuntimeBuilder", "Ignoring", sce);
} catch (NoClassDefFoundError ncdfe) {
// On IBM JDK, we seem to be getting NoClassDefFoundError instead of ServiceConfigurationError
// when OSgiRuntimeBuilder is not able to be loaded in non-OSGi mode because of absence of
// OSGi classes in classpath. So, we need to catch it and ignore.
logger.logp(Level.FINE, "GlassFishRuntime", "getRuntimeBuilder", "Ignoring", ncdfe);
}
}
throw new GlassFishException("No runtime builder available for this configuration: " + bootstrapProperties.getProperties(), null);
}
use of java.util.ServiceConfigurationError in project hadoop by apache.
the class Cluster method initProviderList.
private void initProviderList() {
if (providerList == null) {
synchronized (frameworkLoader) {
if (providerList == null) {
List<ClientProtocolProvider> localProviderList = new ArrayList<ClientProtocolProvider>();
try {
for (ClientProtocolProvider provider : frameworkLoader) {
localProviderList.add(provider);
}
} catch (ServiceConfigurationError e) {
LOG.info("Failed to instantiate ClientProtocolProvider, please " + "check the /META-INF/services/org.apache." + "hadoop.mapreduce.protocol.ClientProtocolProvider " + "files on the classpath", e);
}
providerList = localProviderList;
}
}
}
}
use of java.util.ServiceConfigurationError in project hadoop by apache.
the class TestFileSystemInitialization method testMissingLibraries.
@Test
public void testMissingLibraries() {
try {
Configuration conf = new Configuration();
Class<? extends FileSystem> fs = FileSystem.getFileSystemClass("s3a", conf);
fail("Expected an exception, got a filesystem: " + fs);
} catch (Exception | ServiceConfigurationError expected) {
}
}
use of java.util.ServiceConfigurationError in project aries by apache.
the class AriesRepositoryGenerator method startFramework.
/**
* Start OSGi framework and install the necessary bundles
* @return
* @throws BundleException
*/
public BundleContext startFramework() throws BundleException {
ServiceLoader<FrameworkFactory> factoryLoader = ServiceLoader.load(FrameworkFactory.class, getClass().getClassLoader());
Iterator<FrameworkFactory> factoryIterator = factoryLoader.iterator();
//Map<String, String> osgiPropertyMap = new HashMap<String, String>();
if (!!!factoryIterator.hasNext()) {
System.out.println("Unable to locate the osgi jar");
}
try {
FrameworkFactory frameworkFactory = factoryIterator.next();
framework = frameworkFactory.newFramework(Collections.EMPTY_MAP);
} catch (ServiceConfigurationError sce) {
sce.printStackTrace();
}
framework.init();
framework.start();
// install the bundles in the current directory
Collection<Bundle> installedBundles = new ArrayList<Bundle>();
File bundleDir = new File(".");
File[] jars = bundleDir.listFiles();
try {
for (File jar : jars) {
if (jar.isFile() && (jar.getName().endsWith(".jar"))) {
String location = URLDecoder.decode(jar.toURI().toURL().toExternalForm(), "UTF-8");
if (shouldInstall(location, getIgnoreList())) {
installedBundles.add(framework.getBundleContext().installBundle("reference:" + location));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
ServiceReference paRef = framework.getBundleContext().getServiceReference(PackageAdmin.class.getCanonicalName());
if (paRef != null) {
try {
PackageAdmin admin = (PackageAdmin) framework.getBundleContext().getService(paRef);
admin.resolveBundles(installedBundles.toArray(new Bundle[installedBundles.size()]));
} finally {
framework.getBundleContext().ungetService(paRef);
}
} else {
System.out.println("Unable to find the service reference for package admin");
}
//loop through the list of installed bundles to start them
for (Bundle bundle : installedBundles) {
try {
if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
//start the bundle using its activiation policy
bundle.start(Bundle.START_ACTIVATION_POLICY);
} else {
//nothing to start, we have got a fragment
}
} catch (BundleException e) {
e.printStackTrace();
continue;
}
}
return framework.getBundleContext();
}
use of java.util.ServiceConfigurationError in project lucene-solr by apache.
the class SPIClassIterator method loadNextProfile.
private boolean loadNextProfile() {
ArrayList<String> lines = null;
while (profilesEnum.hasMoreElements()) {
if (lines != null) {
lines.clear();
} else {
lines = new ArrayList<>();
}
final URL url = profilesEnum.nextElement();
try {
final InputStream in = url.openStream();
boolean success = false;
try {
final BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
String line;
while ((line = reader.readLine()) != null) {
final int pos = line.indexOf('#');
if (pos >= 0) {
line = line.substring(0, pos);
}
line = line.trim();
if (line.length() > 0) {
lines.add(line);
}
}
success = true;
} finally {
if (success) {
IOUtils.close(in);
} else {
IOUtils.closeWhileHandlingException(in);
}
}
} catch (IOException ioe) {
throw new ServiceConfigurationError("Error loading SPI class list from URL: " + url, ioe);
}
if (!lines.isEmpty()) {
this.linesIterator = lines.iterator();
return true;
}
}
return false;
}
Aggregations