[java-identity-provider] branch main updated: Add error handling when loading services.

Scott Cantor cantor.2 at osu.edu
Thu Sep 17 14:07:48 UTC 2020


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=f666510ffa6e54ac4f56a1b1aa2946557bf7a1e9

The following commit(s) were added to refs/heads/main by this push:
       new  f666510ff Add error handling when loading services.
f666510ff is described below

commit f666510ffa6e54ac4f56a1b1aa2946557bf7a1e9
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Sep 17 10:07:35 2020 -0400

    Add error handling when loading services.
---
 .../idp/module/impl/ModuleManagerCLI.java          | 122 ++++++++++++---------
 1 file changed, 69 insertions(+), 53 deletions(-)

diff --git a/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerCLI.java b/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerCLI.java
index 4ed5f4ac1..98fc6f912 100644
--- a/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerCLI.java
+++ b/idp-admin-impl/src/main/java/net/shibboleth/idp/module/impl/ModuleManagerCLI.java
@@ -22,8 +22,10 @@ import java.io.IOException;
 import java.io.PrintStream;
 import java.nio.charset.Charset;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.ServiceConfigurationError;
 import java.util.ServiceLoader;
 
 import javax.annotation.Nonnull;
@@ -118,32 +120,39 @@ public final class ModuleManagerCLI extends AbstractIdPHomeAwareCommandLine<Modu
      */
     private void doList(@Nonnull final ModuleContext moduleContext, @Nonnull final ModuleManagerArguments args) {
         
-        for (final IdPModule module : ServiceLoader.load(IdPModule.class)) {
-            if (args.getInfoModuleIds().contains(module.getId())) {
-                System.out.println();
-                System.out.println("Module: " + module.getId());
-                System.out.println("\tName: " + module.getName());
-                System.out.println("\tDesc: " + module.getDescription());
-                System.out.println("\tHelp: " + module.getURL());
-                if (module.isEnabled(moduleContext)) {
-                    System.out.println("\tStatus: " + ANSIColors.ANSI_GREEN + "ENABLED" + ANSIColors.ANSI_RESET);
-                } else {
-                    System.out.println("\tStatus: " + ANSIColors.ANSI_RED + "DISABLED" + ANSIColors.ANSI_RESET);
-                }
-                final Collection<ModuleResource> resources = module.getResources();
-                resources.forEach(r -> {
-                    System.out.println("\tResource: (" + (r.isReplace() ? "  replace" : "noreplace") + ") " +
-                            r.getDestination());
-                });
-                System.out.println();
-            } else if (args.getInfoModuleIds().isEmpty()) {
-                if (module.isEnabled(moduleContext)) {
-                    System.out.println("Module: " + module.getId() +
-                            ANSIColors.ANSI_GREEN + " [ENABLED]" + ANSIColors.ANSI_RESET);
-                } else {
-                    System.out.println("Module: " + module.getId() +
-                            ANSIColors.ANSI_RED + " [DISABLED]" + ANSIColors.ANSI_RESET);
+        final Iterator<IdPModule> modules = ServiceLoader.load(IdPModule.class).iterator();
+        
+        while (modules.hasNext()) {
+            try {
+                final IdPModule module = modules.next();
+                if (args.getInfoModuleIds().contains(module.getId())) {
+                    System.out.println();
+                    System.out.println("Module: " + module.getId());
+                    System.out.println("\tName: " + module.getName());
+                    System.out.println("\tDesc: " + module.getDescription());
+                    System.out.println("\tHelp: " + module.getURL());
+                    if (module.isEnabled(moduleContext)) {
+                        System.out.println("\tStatus: " + ANSIColors.ANSI_GREEN + "ENABLED" + ANSIColors.ANSI_RESET);
+                    } else {
+                        System.out.println("\tStatus: " + ANSIColors.ANSI_RED + "DISABLED" + ANSIColors.ANSI_RESET);
+                    }
+                    final Collection<ModuleResource> resources = module.getResources();
+                    resources.forEach(r -> {
+                        System.out.println("\tResource: (" + (r.isReplace() ? "  replace" : "noreplace") + ") " +
+                                r.getDestination());
+                    });
+                    System.out.println();
+                } else if (args.getInfoModuleIds().isEmpty()) {
+                    if (module.isEnabled(moduleContext)) {
+                        System.out.println("Module: " + module.getId() +
+                                ANSIColors.ANSI_GREEN + " [ENABLED]" + ANSIColors.ANSI_RESET);
+                    } else {
+                        System.out.println("Module: " + module.getId() +
+                                ANSIColors.ANSI_RED + " [DISABLED]" + ANSIColors.ANSI_RESET);
+                    }
                 }
+            } catch (final ServiceConfigurationError e) {
+                System.out.println("ServiceConfigurationError: " + e.getMessage());
             }
         }
     }
@@ -158,37 +167,44 @@ public final class ModuleManagerCLI extends AbstractIdPHomeAwareCommandLine<Modu
      */
     private void doManage(@Nonnull final ModuleContext moduleContext, @Nonnull final ModuleManagerArguments args)
             throws ModuleException {
-        for (final IdPModule module : ServiceLoader.load(IdPModule.class)) {
-            
-            final boolean enable;
-            if (args.getEnableModuleIds().contains(module.getId())) {
-                enable = true;
-            } else if (args.getDisableModuleIds().contains(module.getId())) {
-                enable = false;
-            } else {
-                continue;
-            }
-            
-            try (final ByteArrayOutputStream sink = new ByteArrayOutputStream()) {
-                System.out.println((enable ? "Enabling " : "Disabling ") + module.getId() + "...");
-                moduleContext.setMessageStream(new PrintStream(sink));
-                
-                final Map<ModuleResource,ResourceResult> results = enable ? module.enable(moduleContext) :
-                    module.disable(moduleContext, args.getClean());
-                results.forEach(this::doReportOperation);
-                
-                System.out.println(ANSIColors.ANSI_GREEN + "[OK]" + ANSIColors.ANSI_RESET);
-                System.out.println();
+        
+        final Iterator<IdPModule> modules = ServiceLoader.load(IdPModule.class).iterator();
+        
+        while (modules.hasNext()) {
+            try {
+                final IdPModule module = modules.next();
+                final boolean enable;
+                if (args.getEnableModuleIds().contains(module.getId())) {
+                    enable = true;
+                } else if (args.getDisableModuleIds().contains(module.getId())) {
+                    enable = false;
+                } else {
+                    continue;
+                }
                 
-                final String msg = sink.toString(Charset.forName("UTF-8"));
-                moduleContext.setMessageStream(null);
-                if (!Strings.isNullOrEmpty(msg)) {
-                    System.out.println(msg);
+                try (final ByteArrayOutputStream sink = new ByteArrayOutputStream()) {
+                    System.out.println((enable ? "Enabling " : "Disabling ") + module.getId() + "...");
+                    moduleContext.setMessageStream(new PrintStream(sink));
+                    
+                    final Map<ModuleResource,ResourceResult> results = enable ? module.enable(moduleContext) :
+                        module.disable(moduleContext, args.getClean());
+                    results.forEach(this::doReportOperation);
+                    
+                    System.out.println(ANSIColors.ANSI_GREEN + "[OK]" + ANSIColors.ANSI_RESET);
                     System.out.println();
+                    
+                    final String msg = sink.toString(Charset.forName("UTF-8"));
+                    moduleContext.setMessageStream(null);
+                    if (!Strings.isNullOrEmpty(msg)) {
+                        System.out.println(msg);
+                        System.out.println();
+                    }
+                    
+                } catch (final IOException e) {
+                    getLogger().error("I/O Error", e);
                 }
-                
-            } catch (final IOException e) {
-                getLogger().error("I/O Error", e);
+            } catch (final ServiceConfigurationError e) {
+                System.out.println("ServiceConfigurationError: " + e.getMessage());
             }
         }
     }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list