Merge "AAFcli.java -Declare "value" on a separate line"
[aaf/authz.git] / auth / auth-cass / src / main / java / org / onap / aaf / auth / direct / DirectAAFLocator.java
index 93fab97..f836255 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.
@@ -23,6 +23,7 @@ package org.onap.aaf.auth.direct;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.UnknownHostException;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
@@ -34,8 +35,10 @@ import org.onap.aaf.auth.env.AuthzTrans;
 import org.onap.aaf.auth.layer.Result;
 import org.onap.aaf.cadi.LocatorException;
 import org.onap.aaf.cadi.Access.Level;
+import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.aaf.v2_0.AbsAAFLocator;
 import org.onap.aaf.cadi.config.Config;
+import org.onap.aaf.cadi.config.RegistrationPropHolder;
 import org.onap.aaf.misc.env.util.Split;
 
 import locate.v1_0.Endpoint;
@@ -47,18 +50,18 @@ public class DirectAAFLocator extends AbsAAFLocator<AuthzTrans> {
     private final URI uri;
 
     /**
-     * 
+     *
      * @param env
      * @param ldao
      * @param key  must be one or more of service, version, other in that order
-     * @throws LocatorException 
+     * @throws LocatorException
      */
     public DirectAAFLocator(AuthzEnv env, LocateDAO ldao, String name, String version) throws LocatorException {
-        super(env.access(), name, 1000L /* Don't hit DB more than once a second */); 
+        super(env.access(), name, 1000L /* Don't hit DB more than once a second */);
         this.env = env;
         this.ldao = ldao;
         if (version!=null) {
-            try { 
+            try {
                 String[] v = Split.split('.',version);
                 if (v.length>0) {major = Integer.parseInt(v[0]);}
                 if (v.length>1) {minor = Integer.parseInt(v[1]);}
@@ -68,17 +71,26 @@ public class DirectAAFLocator extends AbsAAFLocator<AuthzTrans> {
                 throw new LocatorException("Invalid Version String: " + version);
             }
         }
-        
+
         try {
-            uri = new URI(access.getProperty(Config.AAF_LOCATE_URL, "localhost")+"/locate/"+name+':'+version);
-        } catch (URISyntaxException e) {
+            String aaf_url;
+            if(name.indexOf('.')>=0) {
+                aaf_url = "https://"+Config.AAF_LOCATE_URL_TAG+'/'+name+':'+version;
+            } else {
+                   aaf_url = "https://"+Config.AAF_LOCATE_URL_TAG+"/%CNS.%NS."+name+':'+version;
+            }
+            RegistrationPropHolder rph = new RegistrationPropHolder(access,0);
+            aaf_url = rph.replacements(getClass().getSimpleName(),aaf_url, null,null);
+            access.printf(Level.INIT,"Creating DirectAAFLocator to %s",aaf_url);
+            uri = new URI(aaf_url);
+        } catch (URISyntaxException | UnknownHostException | CadiException e) {
             throw new LocatorException(e);
         }
         myhostname=null;
-        myport = 0; 
+        myport = 0;
     }
-    
-    
+
+
     @Override
     public boolean refresh() {
         AuthzTrans trans = env.newTransNoAvg();
@@ -107,7 +119,7 @@ public class DirectAAFLocator extends AbsAAFLocator<AuthzTrans> {
                     for (String s : d.subprotocol(false)) {
                         endpoint.getSubprotocol().add(s);
                     }
-                    
+
                     try {
                         epl.add(new EP(endpoint,latitude,longitude));
                     } catch (URISyntaxException e) {