[java-identity-provider] 02/03: IDP-1662 Fall back to a default http client bean

Rod Widdowson rdw at steadingsoftware.com
Wed Sep 2 09:48:55 UTC 2020


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

rdw 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=5a1f1a27b4f50eb7486c7a4ccaac749d72fa7fd3

commit 5a1f1a27b4f50eb7486c7a4ccaac749d72fa7fd3
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Sep 2 10:37:34 2020 +0100

    IDP-1662 Fall back to a default http client bean
    
    https://issues.shibboleth.net/jira/browse/IDP-1662
    
    This avoids needless deprecation warnings.
---
 .../installer/plugin/PluginInstallerArguments.java | 15 +++++++++++
 .../idp/installer/plugin/PluginInstallerCLI.java   | 29 +++++++++++++---------
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
index c08ff7e47..d91982ade 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerArguments.java
@@ -26,6 +26,7 @@ import java.util.List;
 
 import javax.annotation.Nullable;
 
+import org.apache.http.client.HttpClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,6 +67,10 @@ public class PluginInstallerArguments extends AbstractCommandLineArguments {
     @Parameter(names= {"-fu", "--force-update"})
     @Nullable private String forceUpdateVersion;
 
+    /** Name for the {@link HttpClient} . */
+    @Parameter(names= {"-h", "--http-client"})
+    @Nullable private String httpClientName;
+
     /** The {@link #forceUpdateVersion} as a {@link PluginVersion}. */
     @Nullable private PluginVersion updateVersion;
 
@@ -161,6 +166,14 @@ public class PluginInstallerArguments extends AbstractCommandLineArguments {
         return operation;
     }
 
+    /**
+     * Get bean name for the httpClient (if specified).
+     * @return the name or null
+     */
+    @Nullable public String getHttpClientName() {
+        return httpClientName;
+    }
+
     /** {@inheritDoc} */
     // Checkstyle: CyclomaticComplexity OFF
     public void validate() throws IllegalArgumentException {
@@ -254,6 +267,8 @@ public class PluginInstallerArguments extends AbstractCommandLineArguments {
         out.println(String.format("  %-22s %s", "-u, --update <what>", "update (plugin id)"));
         out.println(String.format("  %-22s %s", "-fu, --force-update <version>",
                 "force version to update to (requires -u)"));
+        out.println(String.format("  %-22s %s", "-h, --http-client <bean ame>",
+                "use the named bean for http operations"));
         out.println();
     }
 
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
index 7c2ee3c9f..23b01b903 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
@@ -22,7 +22,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Set;
 import java.util.function.Predicate;
 
 import javax.annotation.Nonnull;
@@ -34,6 +33,7 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 
@@ -108,18 +108,23 @@ public final class PluginInstallerCLI extends AbstractIdPHomeAwareCommandLine<Pl
         if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
             Security.addProvider(new BouncyCastleProvider());
         }
-        final Set<Entry<String, HttpClient>> clients =
-                getApplicationContext().getBeansOfType(HttpClient.class).entrySet();
-        if (clients.isEmpty()) {
-            log.debug("No HttpClient definitions found.");
+
+        String clientName = args.getHttpClientName();
+        if (clientName == null) {
+            clientName = "shibboleth.InternalHttpClient";
+        }
+        final Object client;
+        try {
+            client = getApplicationContext().getBean(clientName);
+        } catch (final NoSuchBeanDefinitionException e) {
+            log.error("Could not locate an Http Client '{}'", clientName);
+            return RC_IO;
+        }
+        if (client instanceof HttpClient) {
+            httpClient = (HttpClient) client;
         } else {
-            final Entry<String, HttpClient> entry = clients.iterator().next();
-            httpClient = entry.getValue();
-            if (clients.size() > 1) {
-                log.warn("Multiple HttpClient beans found; Taking {}", entry.getKey());
-            } else {
-                log.debug("Selecting HttpClient: {}", entry.getKey());
-            }
+            log.error("Bean '{}' was a {}, not a {}", clientName, client.getClass(), HttpClient.class);
+            return RC_IO;
         }
 
         try {

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


More information about the commits mailing list