Ejemplo n.º 1
0
 private static boolean loadProviderFromProperty() {
   String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
   if (cn == null) return false;
   try {
     @SuppressWarnings("deprecation")
     Object o = Class.forName(cn, true, ClassLoader.getSystemClassLoader()).newInstance();
     provider = (HttpServerProvider) o;
     return true;
   } catch (ClassNotFoundException
       | IllegalAccessException
       | InstantiationException
       | SecurityException x) {
     throw new ServiceConfigurationError(null, x);
   }
 }
Ejemplo n.º 2
0
 private static boolean loadProviderAsService() {
   Iterator<HttpServerProvider> i =
       ServiceLoader.load(HttpServerProvider.class, ClassLoader.getSystemClassLoader()).iterator();
   for (; ; ) {
     try {
       if (!i.hasNext()) return false;
       provider = i.next();
       return true;
     } catch (ServiceConfigurationError sce) {
       if (sce.getCause() instanceof SecurityException) {
         // Ignore the security exception, try the next provider
         continue;
       }
       throw sce;
     }
   }
 }