Sonar Fixes, Formatting
[aaf/authz.git] / cadi / client / src / main / java / org / onap / aaf / cadi / http / HMangr.java
index 8e3138a..1d1f273 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,14 +30,15 @@ import java.net.URISyntaxException;
 import javax.net.ssl.SSLHandshakeException;
 
 import org.onap.aaf.cadi.Access;
+import org.onap.aaf.cadi.Access.Level;
 import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.Locator;
+import org.onap.aaf.cadi.Locator.Item;
 import org.onap.aaf.cadi.LocatorException;
 import org.onap.aaf.cadi.SecuritySetter;
-import org.onap.aaf.cadi.Access.Level;
-import org.onap.aaf.cadi.Locator.Item;
 import org.onap.aaf.cadi.client.Rcli;
 import org.onap.aaf.cadi.client.Retryable;
+import org.onap.aaf.cadi.util.FixURIinfo;
 import org.onap.aaf.misc.env.APIException;
 
 public class HMangr {
@@ -45,7 +46,7 @@ public class HMangr {
     private int readTimeout, connectionTimeout;
     public final Locator<URI> loc;
     private Access access;
-    
+
     public HMangr(Access access, Locator<URI> loc) throws LocatorException {
         readTimeout = 10000;
         connectionTimeout=3000;
@@ -57,18 +58,18 @@ public class HMangr {
     }
 
     /**
-     * Reuse the same service.  This is helpful for multiple calls that change service side cached data so that 
+     * Reuse the same service.  This is helpful for multiple calls that change service side cached data so that
      * there is not a speed issue.
-     * 
+     *
      * If the service goes down, another service will be substituted, if available.
-     * 
+     *
      * @param access
      * @param loc
      * @param ss
      * @param item
      * @param retryable
      * @return
-     * @throws URISyntaxException 
+     * @throws URISyntaxException
      * @throws Exception
      */
     public<RET> RET same(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable) throws APIException, CadiException, LocatorException {
@@ -106,7 +107,7 @@ public class HMangr {
                 } else {
                     client.setSecuritySetter(ss);
                 }
-                
+
                 retry = false;
                 try {
                     ret = retryable.code(client);
@@ -117,14 +118,14 @@ public class HMangr {
                     try {
                         Throwable ec = e.getCause();
                         if (ec instanceof java.net.ConnectException) {
-                            if (client!=null && loc.hasItems()) { 
+                            if (client!=null && loc.hasItems()) {
                                 access.log(Level.WARN,"Connection refused, trying next available service");
                                 retry = true;
                             } else {
                                 throw new CadiException("Connection refused, no more services to try");
                             }
                         } else if (ec instanceof java.net.SocketException) {
-                            if (client!=null && loc.hasItems()) { 
+                            if (client!=null && loc.hasItems()) {
                                 access.log(Level.WARN,"Socket prematurely closed, trying next available service");
                                 retry = true;
                             } else {
@@ -154,27 +155,35 @@ public class HMangr {
         }
         return ret;
     }
-    
-    
+
+
     public<RET> RET best(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable) throws LocatorException, CadiException, APIException {
         retryable.item(loc.best());
         return same(ss,retryable);
     }
     public<RET> RET all(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable) throws LocatorException, CadiException, APIException {
-        return oneOf(ss,retryable,true,null);
+        return call(ss,retryable,true,null);
     }
 
     public<RET> RET all(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable,boolean notify) throws LocatorException, CadiException, APIException {
-        return oneOf(ss,retryable,notify,null);
+        return call(ss,retryable,notify,null);
+    }
+
+    public <RET> RET allExcept(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable,boolean notify, String selfHost) throws LocatorException, CadiException, APIException {
+        return call(ss,retryable,notify,selfHost);
     }
-    
+
     public<RET> RET oneOf(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable,boolean notify,String host) throws LocatorException, CadiException, APIException {
+        return call(ss,retryable,notify,host);
+    }
+    private<RET> RET call(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable,boolean notify,String host) throws LocatorException, CadiException, APIException {
         RET ret = null;
         // make sure we have all current references:
         loc.refresh();
         for (Item li=loc.first();li!=null;li=loc.next(li)) {
             URI uri=loc.get(li);
-            if (host!=null && !host.equals(uri.getHost())) {
+            FixURIinfo fui = new FixURIinfo(uri);
+            if (host!=null && !host.equals(fui.getHost())) {
                 break;
             }
             try {
@@ -202,12 +211,12 @@ public class HMangr {
                 access.log(Level.ERROR,"Connection to",uri,"refused during call to all services");
             }
         }
-            
-        if (ret == null && notify) 
+
+        if (ret == null && notify)
             throw new LocatorException("No available clients to call");
         return ret;
     }
-    
+
 
     public void close() {
         // TODO Anything here?
@@ -221,7 +230,7 @@ public class HMangr {
     public int readTimeout() {
         return readTimeout;
     }
-    
+
     public void connectionTimeout(int t) {
         connectionTimeout = t;
     }