Improved multi Proxy DNSLocator based
[aaf/authz.git] / cadi / aaf / src / main / java / org / onap / aaf / cadi / aaf / v2_0 / AbsAAFLocator.java
index 3941b15..a654e6f 100644 (file)
@@ -66,20 +66,20 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
 
 
     public AbsAAFLocator(Access access, String name, final long refreshMin) throws LocatorException {
-       RegistrationPropHolder rph;
-               try {
-                       rph = new RegistrationPropHolder(access, 0);
-               } catch (UnknownHostException | CadiException e1) {
-                       throw new LocatorException(e1);
-               }
+        RegistrationPropHolder rph;
         try {
-               aaf_locator_host = rph.replacements(getClass().getSimpleName(),"https://"+Config.AAF_LOCATE_URL_TAG,null,null);
-               if(aaf_locator_host.endsWith("/locate")) {
+            rph = new RegistrationPropHolder(access, 0);
+        } catch (UnknownHostException | CadiException e1) {
+            throw new LocatorException(e1);
+        }
+        URI aaf_locator_uri;
+        try {
+            aaf_locator_host = rph.replacements(getClass().getSimpleName(),"https://"+Config.AAF_LOCATE_URL_TAG,null,null);
+            if(aaf_locator_host.endsWith("/locate")) {
                 aaf_locator_uri = new URI(aaf_locator_host);
-               } else {
-                       aaf_locator_uri = new URI(aaf_locator_host+"/locate");
-               }
-               
+            } else {
+                aaf_locator_uri = new URI(aaf_locator_host+"/locate");
+            }
             access.printf(Level.INFO, "AbsAAFLocator AAF URI is %s",aaf_locator_uri);
         } catch (URISyntaxException e) {
             throw new LocatorException(e);
@@ -110,9 +110,8 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
             this.name = split[0];
             this.version = (split.length > 1) ? split[1] : access.getProperty(Config.AAF_API_VERSION,Config.AAF_DEFAULT_API_VERSION);
         }
-        
     }
-
+    
     /**
      * This is the way to setup specialized AAFLocators ahead of time.
      * @param preload
@@ -122,6 +121,9 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
     }
         
     public static Locator<URI> create(final String name, final String version) throws LocatorException {
+        if(locatorCreator==null) {
+            throw new LocatorException("LocatorCreator is not set");
+        }
         return locatorCreator.create(name, version);
     }
 
@@ -135,7 +137,7 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
         if (path.length>1 && "locate".equals(path[1])) {
            return path[2];
         } else if(path.length>1) {
-               return path[1];
+             return path[1];
         } else {
             return locatorURI.toString();
         }
@@ -234,7 +236,10 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
     @Override
     public Item best() throws LocatorException {
         if (!hasItems()) {
-            throw new LocatorException("No Entries found for '" + aaf_locator_uri.toString() + '/' + name + ':' + version + '\'');
+            throw new LocatorException(String.format("No Entries found for '%s/%s:%s'",
+                       (aaf_locator_uri==null?aaf_locator_host:aaf_locator_uri.toString()),
+                       name,
+                       version));
         }
         List<EP> lep = new ArrayList<>();
         EP first = null;
@@ -365,7 +370,7 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
         }
         return null;
     }
-
+    
     protected static class AAFLItem implements Item {
             private Iterator<EP> iter;
             private URI uri;
@@ -468,8 +473,8 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
     }
 
     protected void clear() {
-       epList.clear();
-       earliest=0L;
+        epList.clear();
+        earliest=0L;
     }