Enable retries for the /authn/validate endpoint if it fails to connect
[aaf/authz.git] / cadi / aaf / src / main / java / org / onap / aaf / cadi / aaf / v2_0 / AAFConHttp.java
index 7ccf3e6..84ef788 100644 (file)
@@ -24,6 +24,7 @@ package org.onap.aaf.cadi.aaf.v2_0;
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
+import java.util.List;
 
 import org.onap.aaf.cadi.Access;
 import org.onap.aaf.cadi.CadiException;
@@ -136,6 +137,34 @@ public class AAFConHttp extends AAFCon<HttpURLConnection> {
         }
     }
 
+    protected Rcli<HttpURLConnection> rclient(List<URI> ignoredURIs, SecuritySetter<HttpURLConnection> ss) throws CadiException {
+        if (hman.loc==null) {
+            throw new CadiException("No Locator set in AAFConHttp");
+        }
+        try {
+            if (ignoredURIs.isEmpty()) {
+                return new HRcli(hman, hman.loc.best(), ss);
+            } else {
+                Item item = hman.loc.first();
+                HRcli currentClient = new HRcli(hman, item, ss);
+
+                item = hman.loc.next(item);
+
+                while (item != null) {
+                    if (!ignoredURIs.contains(currentClient.getURI())) {
+                        break;
+                    } else {
+                        currentClient = new HRcli(hman, item, ss);
+                    }
+                    item = hman.loc.next(item);
+                }
+                return currentClient;
+            }
+        } catch (Exception e) {
+            throw new CadiException(e);
+        }
+    }
+
     @Override
     public Rcli<HttpURLConnection> rclient(Locator<URI> loc, SecuritySetter<HttpURLConnection> ss) throws CadiException {
         try {