[java-identity-provider] branch main updated: IDP-2416 - Capture more output of failed command line invocations

Codeberg noreply at shibboleth.net
Wed Jan 7 15:24:33 UTC 2026


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

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

View the commit online:
https://codeberg.org/Shibboleth/java-identity-provider/commit/80d2978789a7c3a83ac6041faf5b64c993f74c04

The following commit(s) were added to refs/heads/main by this push:
     new 80d297878 IDP-2416 - Capture more output of failed command line invocations
80d297878 is described below

commit 80d2978789a7c3a83ac6041faf5b64c993f74c04
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Jan 7 10:24:17 2026 -0500

    IDP-2416 - Capture more output of failed command line invocations
    
    https://shibboleth.atlassian.net/browse/IDP-2416
    
    Experimental addition that dumps error stream from URLConnection.
---
 .../src/main/java/net/shibboleth/idp/cli/CLI.java  | 61 +++++++++++++++-------
 1 file changed, 42 insertions(+), 19 deletions(-)

diff --git a/idp-cli/src/main/java/net/shibboleth/idp/cli/CLI.java b/idp-cli/src/main/java/net/shibboleth/idp/cli/CLI.java
index 28124d7b9..bd9e52512 100644
--- a/idp-cli/src/main/java/net/shibboleth/idp/cli/CLI.java
+++ b/idp-cli/src/main/java/net/shibboleth/idp/cli/CLI.java
@@ -19,6 +19,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.PrintStream;
 import java.lang.reflect.Constructor;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
@@ -27,6 +28,7 @@ import java.net.URL;
 import java.util.Map;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import com.beust.jcommander.JCommander;
 
@@ -60,7 +62,7 @@ public final class CLI {
         // Get name of parameter class to load using system property.
         final String argType = System.getProperty(ARGS_PROPERTY);
         if (argType == null) {
-            errorAndExit(ARGS_PROPERTY + " system property not set");
+            errorAndExit(ARGS_PROPERTY + " system property not set", null);
         }
 
         CommandLineArguments argObject = null;
@@ -69,7 +71,7 @@ public final class CLI {
             final Constructor<?> construct = Class.forName(argType).getConstructor();
             final Object obj = construct.newInstance();
             if (!(obj instanceof CommandLineArguments)) {
-                errorAndExit("Argument class was not of the correct type");
+                errorAndExit("Argument class was not of the correct type", null);
             }
             argObject = (CommandLineArguments) obj;
             final JCommander jc = new JCommander(argObject);
@@ -79,11 +81,11 @@ public final class CLI {
                 return;
             }
         } catch (final ClassNotFoundException e) {
-            errorAndExit("Argument class " + argType + " not found ");
+            errorAndExit("Argument class " + argType + " not found ", null);
         } catch (final InstantiationException | IllegalAccessException e) {
             final String msg = e.getMessage();
             assert msg != null;
-            errorAndExit(msg);
+            errorAndExit(msg, null);
         }
         assert argObject != null;
         
@@ -92,7 +94,7 @@ public final class CLI {
         } catch (final IllegalArgumentException e) {
             final String msg = e.getMessage();
             assert msg != null;
-            errorAndExit(msg);
+            errorAndExit(msg, null);
         }
         
         doRequest(argObject);
@@ -105,9 +107,10 @@ public final class CLI {
      */
     private static void doRequest(@Nonnull final CommandLineArguments args) {
         URL url = null;
+        HttpURLConnection connection = null;
         try {
             url = args.buildURL();
-            final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+            connection = (HttpURLConnection) url.openConnection();
             
             if (args.getMethod() != null) {
                 connection.setRequestMethod(args.getMethod());
@@ -126,33 +129,53 @@ public final class CLI {
             }
             
             try (final InputStream stream = connection.getInputStream()) {
-                try (final InputStreamReader reader = new InputStreamReader(stream)) {
-                    try (final BufferedReader in = new BufferedReader(reader)) {
-                        String line;
-                        while((line = in.readLine()) != null) {
-                            System.out.println(line);
-                        }
-                    }
-                }
+                outputStream(stream, System.out);
             }
         } catch (final MalformedURLException|ProtocolException e) {
             final String msg = e.getMessage();
             assert msg != null;
-            errorAndExit(msg);
+            errorAndExit(msg, null);
         } catch (final FileNotFoundException e) {
-            errorAndExit(e.getMessage() + " returned File Not Found error (check IDP_BASE_URL?)");
+            errorAndExit(e.getMessage() + " returned File Not Found error", connection);
         } catch (final IOException e) {
-            errorAndExit((url != null ? "(" + url.toString() + ") " : "") + e.getMessage());
+            errorAndExit((url != null ? "(" + url.toString() + ") " : "") + e.getMessage(), connection);
+        }
+    }
+    
+    /**
+     * Dump contents of stream to an output sink.
+     * 
+     * @param source input stream to dump
+     * @param sink output stream to write to
+     * 
+     * @throws IOException if an error occurs
+     */
+    private static void outputStream(@Nonnull final InputStream source, @Nonnull final PrintStream sink)
+            throws IOException {
+        try (final InputStreamReader reader = new InputStreamReader(source)) {
+            try (final BufferedReader in = new BufferedReader(reader)) {
+                String line;
+                while((line = in.readLine()) != null) {
+                    sink.println(line);
+                }
+            }
         }
     }
     
     /**
-     * Logs, as an error, the error message and exits the program.
+     * Logs, as an error, the error message, any error stream content from the connection, and exits the program.
      * 
      * @param errorMessage error message
+     * @param conn connection to get error information from
      */
-    private static void errorAndExit(@Nonnull final String errorMessage) {
+    private static void errorAndExit(@Nonnull final String errorMessage, @Nullable final HttpURLConnection conn) {
         System.err.println(errorMessage);
+        if (conn != null) {
+            try (final InputStream err = conn.getErrorStream()) {
+                outputStream(err, System.err);
+            } catch (final IOException e) {
+            }
+        }
         System.exit(1);
     }
     

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


More information about the commits mailing list