X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2FPropAccess.java;h=461ef43cfb6b80b464f8d843bc163dba22409265;hb=dd097a4b411cd78ced737548a43e019b1f3172f1;hp=a9d671cc77986f08a4b154e9501f226659599414;hpb=27e133b8f3f189bb41354d0624dcdb0998bd4701;p=aaf%2Fauthz.git diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java index a9d671cc..461ef43c 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java @@ -26,6 +26,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -91,10 +93,20 @@ public class PropAccess implements Access { int eq; for (String arg : args) { if ((eq=arg.indexOf('='))>0) { - nprops.setProperty(arg.substring(0, eq),arg.substring(eq+1)); + String key = arg.substring(0, eq); + if(Config.CADI_PROP_FILES.equals(key)) { + nprops.setProperty(key,arg.substring(eq+1)); + } } } init(nprops); + + // Re-overlay Args + for (String arg : args) { + if ((eq=arg.indexOf('='))>0) { + props.setProperty(arg.substring(0, eq),arg.substring(eq+1)); + } + } } protected void init(Properties p) { @@ -103,15 +115,16 @@ public class PropAccess implements Access { level=DEFAULT.maskOf(); props = new Properties(); - // First, load related System Properties + + // Find the "cadi_prop_files" + // First in VM Args for (Entry es : System.getProperties().entrySet()) { String key = es.getKey().toString(); - for (String start : new String[] {"cadi_","aaf_","cm_"}) { - if (key.startsWith(start)) { - props.put(key, es.getValue()); - } - } + if(Config.CADI_PROP_FILES.equals(key)) { + props.put(key,es.getValue().toString()); + } } + // Second, overlay or fill in with Passed in Props if (p!=null) { props.putAll(p); @@ -120,6 +133,16 @@ public class PropAccess implements Access { // Third, load any Chained Property Files load(props.getProperty(Config.CADI_PROP_FILES)); + // Fourth, System.getProperties takes precedence over Files + for (Entry es : System.getProperties().entrySet()) { + String key = es.getKey().toString(); + for (String start : new String[] {"HOSTNAME","cadi_","aaf_","cm_"}) { + if (key.startsWith(start)) { + props.put(key, es.getValue()); + } + } + } + String sLevel = props.getProperty(Config.CADI_LOGLEVEL); if (sLevel!=null) { level=Level.valueOf(sLevel).maskOf(); @@ -274,41 +297,53 @@ public class PropAccess implements Access { sb.append("] "); } else { int idx = 0; - if (elements[idx] instanceof Integer) { + if(elements[idx]!=null && + elements[idx] instanceof Integer) { sb.append('-'); sb.append(elements[idx]); ++idx; } sb.append("] "); - String s; - boolean first = true; - for (Object o : elements) { - if (o!=null) { - s=o.toString(); - if (first) { - first = false; - } else { - int l = s.length(); - if (l>0) { - switch(s.charAt(l-1)) { - case ' ': - break; - default: - sb.append(' '); - } - } - } - sb.append(s); - } - } + write(true,sb,elements); } return sb; } + + private static boolean write(boolean first, StringBuilder sb, Object[] elements) { + String s; + for (Object o : elements) { + if (o!=null) { + if(o.getClass().isArray()) { + first = write(first,sb,(Object[])o); + } else { + s=o.toString(); + if (first) { + first = false; + } else { + int l = s.length(); + if (l>0) { + switch(s.charAt(l-1)) { + case ' ': + break; + default: + sb.append(' '); + } + } + } + sb.append(s); + } + } + } + return first; + } @Override public void log(Exception e, Object... elements) { - log(Level.ERROR,e.getMessage(),elements); - e.printStackTrace(System.err); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + pw.println(); + e.printStackTrace(pw); + log(Level.ERROR,elements,sw.toString()); } @Override