summaryrefslogtreecommitdiffstats
path: root/cadi/client
diff options
context:
space:
mode:
Diffstat (limited to 'cadi/client')
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/client/AbsAuthentication.java12
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/client/AbsTransferSS.java2
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/client/Rcli.java38
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/client/Result.java2
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/http/HAuthorizationHeader.java4
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/http/HBasicAuthSS.java4
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java30
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/http/HMangr.java40
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/http/HNoAuthSS.java2
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/http/HRcli.java4
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/http/HSecurityInfoInit.java4
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/http/HTransferSS.java6
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/http/HX509SS.java18
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java30
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/locator/HotPeerLocator.java64
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/locator/PropertyLocator.java54
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java4
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/routing/GreatCircle.java4
-rw-r--r--cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_PropertyLocator.java2
19 files changed, 162 insertions, 162 deletions
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/client/AbsAuthentication.java b/cadi/client/src/main/java/org/onap/aaf/cadi/client/AbsAuthentication.java
index cce7b5f3..da85702d 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/client/AbsAuthentication.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/client/AbsAuthentication.java
@@ -76,7 +76,7 @@ public abstract class AbsAuthentication<CLIENT> implements SecuritySetter<CLIENT
}
protected String headValue() throws IOException {
- if(headValue==null) {
+ if (headValue==null) {
return "";
} else {
return new String(symm.decode(headValue));
@@ -93,7 +93,7 @@ public abstract class AbsAuthentication<CLIENT> implements SecuritySetter<CLIENT
}
public boolean isDenied() {
- if(lastMiss>0 && lastMiss>System.currentTimeMillis()) {
+ if (lastMiss>0 && lastMiss>System.currentTimeMillis()) {
return true;
} else {
lastMiss=0L;
@@ -102,17 +102,17 @@ public abstract class AbsAuthentication<CLIENT> implements SecuritySetter<CLIENT
}
public synchronized int setLastResponse(int httpcode) {
- if(httpcode == 401) {
+ if (httpcode == 401) {
++count;
- if(lastMiss==0L && count>MAX_TEMP_COUNT) {
+ if (lastMiss==0L && count>MAX_TEMP_COUNT) {
lastMiss=System.currentTimeMillis()+WAIT_TIME;
}
- // if(count>MAX_SPAM_COUNT) {
+ // if (count>MAX_SPAM_COUNT) {
// System.err.printf("Your service has %d consecutive bad service logins to AAF. \nIt will now exit\n",
// count);
// System.exit(401);
// }
- if(count%1000==0) {
+ if (count%1000==0) {
System.err.printf("Your service has %d consecutive bad service logins to AAF. AAF Access will be disabled after %d\n",
count,MAX_SPAM_COUNT);
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/client/AbsTransferSS.java b/cadi/client/src/main/java/org/onap/aaf/cadi/client/AbsTransferSS.java
index 0c38bd90..baac6daa 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/client/AbsTransferSS.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/client/AbsTransferSS.java
@@ -56,7 +56,7 @@ public abstract class AbsTransferSS<CLIENT> implements SecuritySetter<CLIENT> {
private void init(TaggedPrincipal principal, String app) {
this.principal=principal;
- if(principal==null) {
+ if (principal==null) {
return;
} else {
value = principal.getName() + ':' +
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/client/Rcli.java b/cadi/client/src/main/java/org/onap/aaf/cadi/client/Rcli.java
index b414487b..6b486b8e 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/client/Rcli.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/client/Rcli.java
@@ -268,20 +268,20 @@ public abstract class Rcli<CT> {
@Override
public void transfer(OutputStream os) throws IOException, APIException {
PrintStream ps;
- if(os instanceof PrintStream) {
+ if (os instanceof PrintStream) {
ps = (PrintStream)os;
} else {
ps = new PrintStream(os);
}
boolean first = true;
- for(String fp : formParam) {
- if(fp!=null) {
- if(first) {
+ for (String fp : formParam) {
+ if (fp!=null) {
+ if (first) {
first = false;
} else {
ps.print('&');
}
- if(fp.endsWith("=")) {
+ if (fp.endsWith("=")) {
first = true;
}
ps.print(fp);
@@ -376,7 +376,7 @@ public abstract class Rcli<CT> {
client.setMethod(GET);
client.addHeader(ACCEPT, accept);
- for(int i=1;i<headers.length;i=i+2) {
+ for (int i=1;i<headers.length;i=i+2) {
client.addHeader(headers[i-1],headers[i]);
}
client.setPathInfo(pp.path());
@@ -393,7 +393,7 @@ public abstract class Rcli<CT> {
EClient<CT> client = client();
client.setMethod(GET);
client.addHeader(ACCEPT, accept);
- for(int i=1;i<headers.length;i=i+2) {
+ for (int i=1;i<headers.length;i=i+2) {
client.addHeader(headers[i-1],headers[i]);
}
client.setPathInfo(pp.path());
@@ -410,7 +410,7 @@ public abstract class Rcli<CT> {
EClient<CT> client = client();
client.setMethod(GET);
client.addHeader(ACCEPT, typeString(df.getTypeClass()));
- for(int i=1;i<headers.length;i=i+2) {
+ for (int i=1;i<headers.length;i=i+2) {
client.addHeader(headers[i-1],headers[i]);
}
client.setPathInfo(pp.path());
@@ -664,7 +664,7 @@ public abstract class Rcli<CT> {
throw new CadiException("Invalid incoming URI",e);
}
String name;
- for(Enumeration<String> en = req.getHeaderNames();en.hasMoreElements();) {
+ for (Enumeration<String> en = req.getHeaderNames();en.hasMoreElements();) {
name = en.nextElement();
client.addHeader(name,req.getHeader(name));
}
@@ -673,7 +673,7 @@ public abstract class Rcli<CT> {
client.setPathInfo(pathParam);
String meth = req.getMethod();
client.setMethod(meth);
- if(!"GET".equals(meth)) {
+ if (!"GET".equals(meth)) {
client.setPayload(new EClient.Transfer() {
@Override
public void transfer(OutputStream os) throws IOException, APIException {
@@ -682,7 +682,7 @@ public abstract class Rcli<CT> {
// reuse Buffers
Pooled<byte[]> pbuff = buffPool.get();
try {
- while((read=is.read(pbuff.content))>=0) {
+ while ((read=is.read(pbuff.content))>=0) {
os.write(pbuff.content,0,read);
}
} finally {
@@ -704,21 +704,21 @@ public abstract class Rcli<CT> {
public ParsePath(final String origPath) {
path = origPath;
- if(origPath==null) {
+ if (origPath==null) {
query=queryEnd=pound=-1;
queryParams=null;
} else {
query = origPath.indexOf('?');
pound = origPath.indexOf('#');
queryEnd = pound>=0?pound:path.length();
- if(oneCallQueryParams==null) {
- if(query>=0) {
+ if (oneCallQueryParams==null) {
+ if (query>=0) {
queryParams = path.substring(query+1,queryEnd);
} else {
queryParams=null;
}
} else {
- if(query>=0) {
+ if (query>=0) {
queryParams = oneCallQueryParams + '&' + path.substring(query+1,queryEnd);
} else {
queryParams = oneCallQueryParams;
@@ -729,12 +729,12 @@ public abstract class Rcli<CT> {
}
public String path() {
- if(query>=0) {
- if(pound>=0) {
+ if (query>=0) {
+ if (pound>=0) {
return path.substring(pound+1);
}
return path.substring(0,query);
- } else if(pound>=0) {
+ } else if (pound>=0) {
return path.substring(0,pound);
} else {
return path;
@@ -746,7 +746,7 @@ public abstract class Rcli<CT> {
}
public String frag() {
- if(pound>=0) {
+ if (pound>=0) {
return path.substring(pound+1);
} else {
return null;
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/client/Result.java b/cadi/client/src/main/java/org/onap/aaf/cadi/client/Result.java
index e9de27e7..0e2a4b16 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/client/Result.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/client/Result.java
@@ -51,7 +51,7 @@ public class Result<T> {
public String toString() {
StringBuilder sb = new StringBuilder("Code: ");
sb.append(code);
- if(error!=null) {
+ if (error!=null) {
sb.append(" = ");
sb.append(error);
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HAuthorizationHeader.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HAuthorizationHeader.java
index 3c38ff8d..c2f56458 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HAuthorizationHeader.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HAuthorizationHeader.java
@@ -38,7 +38,7 @@ public class HAuthorizationHeader extends AbsAuthentication<HttpURLConnection> {
@Override
public void setSecurity(HttpURLConnection huc) throws CadiException {
- if(isDenied()) {
+ if (isDenied()) {
throw new CadiException(REPEAT_OFFENDER);
}
try {
@@ -46,7 +46,7 @@ public class HAuthorizationHeader extends AbsAuthentication<HttpURLConnection> {
} catch (IOException e) {
throw new CadiException(e);
}
- if(securityInfo!=null && huc instanceof HttpsURLConnection) {
+ if (securityInfo!=null && huc instanceof HttpsURLConnection) {
securityInfo.setSocketFactoryOn((HttpsURLConnection)huc);
}
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HBasicAuthSS.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HBasicAuthSS.java
index e4ab6d72..7e5cbd3b 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HBasicAuthSS.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HBasicAuthSS.java
@@ -48,7 +48,7 @@ public class HBasicAuthSS extends HAuthorizationHeader implements BasicAuth {
public HBasicAuthSS(SecurityInfoC<HttpURLConnection> si, String user, String pass, boolean asDefault) throws IOException {
this(si, user,pass);
- if(asDefault) {
+ if (asDefault) {
si.set(this);
}
}
@@ -59,7 +59,7 @@ public class HBasicAuthSS extends HAuthorizationHeader implements BasicAuth {
public HBasicAuthSS(BasicPrincipal bp, SecurityInfoC<HttpURLConnection> si, boolean asDefault) throws IOException {
this(si, bp.getName(),new String(bp.getCred()));
- if(asDefault) {
+ if (asDefault) {
si.set(this);
}
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java
index 1d3d9547..d8852834 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HClient.java
@@ -111,13 +111,13 @@ public class HClient implements EClient<HttpURLConnection> {
public void send() throws APIException {
try {
// Build URL from given URI plus current Settings
- if(uri.getPath()==null) {
+ if (uri.getPath()==null) {
throw new APIException("Invalid URL entered for HClient");
}
StringBuilder pi=null;
- if(pathinfo!=null) { // additional pathinfo
+ if (pathinfo!=null) { // additional pathinfo
pi = new StringBuilder(uri.getPath());
- if(!pathinfo.startsWith("/")) {
+ if (!pathinfo.startsWith("/")) {
pi.append('/');
}
pi.append(pathinfo);
@@ -133,7 +133,7 @@ public class HClient implements EClient<HttpURLConnection> {
);
huc = getConnection(sendURI, pi);
huc.setRequestMethod(meth);
- if(ss!=null) {
+ if (ss!=null) {
ss.setSecurity(huc);
}
if (headers != null)
@@ -153,7 +153,7 @@ public class HClient implements EClient<HttpURLConnection> {
throw new APIException(e);
} finally { // ensure all these are reset after sends
meth=pathinfo=null;
- if(headers!=null) {
+ if (headers!=null) {
headers.clear();
}
pathinfo = query = fragment = "";
@@ -200,7 +200,7 @@ public class HClient implements EClient<HttpURLConnection> {
huc.setReadTimeout(timeout);
respCode = huc.getResponseCode();
ss.setLastResponse(respCode);
- if(evalInfo(huc)) {
+ if (evalInfo(huc)) {
return true;
} else {
extractError();
@@ -216,13 +216,13 @@ public class HClient implements EClient<HttpURLConnection> {
private void extractError() {
InputStream is = huc.getErrorStream();
try {
- if(is==null) {
+ if (is==null) {
is = huc.getInputStream();
}
- if(is!=null) {
+ if (is!=null) {
errContent = new StringBuilder();
int c;
- while((c=is.read())>=0) {
+ while ((c=is.read())>=0) {
errContent.append((char)c);
}
}
@@ -274,7 +274,7 @@ public class HClient implements EClient<HttpURLConnection> {
}
public void close() {
- if(huc!=null) {
+ if (huc!=null) {
huc.disconnect();
}
}
@@ -382,12 +382,12 @@ public class HClient implements EClient<HttpURLConnection> {
int read;
InputStream is;
OutputStream os = resp.getOutputStream();
- if(respCode==expected) {
+ if (respCode==expected) {
is = huc.getInputStream();
// reuse Buffers
Pooled<byte[]> pbuff = Rcli.buffPool.get();
try {
- while((read=is.read(pbuff.content))>=0) {
+ while ((read=is.read(pbuff.content))>=0) {
os.write(pbuff.content,0,read);
}
} finally {
@@ -396,14 +396,14 @@ public class HClient implements EClient<HttpURLConnection> {
return true;
} else {
is = huc.getErrorStream();
- if(is==null) {
+ if (is==null) {
is = huc.getInputStream();
}
- if(is!=null) {
+ if (is!=null) {
errContent = new StringBuilder();
Pooled<byte[]> pbuff = Rcli.buffPool.get();
try {
- while((read=is.read(pbuff.content))>=0) {
+ while ((read=is.read(pbuff.content))>=0) {
os.write(pbuff.content,0,read);
}
} finally {
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HMangr.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HMangr.java
index da349efc..8e3138af 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HMangr.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HMangr.java
@@ -49,7 +49,7 @@ public class HMangr {
public HMangr(Access access, Locator<URI> loc) throws LocatorException {
readTimeout = 10000;
connectionTimeout=3000;
- if(loc == null) {
+ if (loc == null) {
throw new LocatorException("Null Locator passed");
}
this.loc = loc;
@@ -79,20 +79,20 @@ public class HMangr {
do {
Item item;
// if no previous state, get the best
- if(retryable.item()==null) {
+ if (retryable.item()==null) {
item = loc.best();
- if(item==null) {
+ if (item==null) {
throw new LocatorException("No Services Found for " + loc);
}
retryable.item(item);
retryable.lastClient = null;
}
- if(client==null) {
+ if (client==null) {
item = retryable.item();
URI uri=loc.get(item);
- if(uri==null) {
+ if (uri==null) {
loc.invalidate(retryable.item());
- if(loc.hasItems()) {
+ if (loc.hasItems()) {
retryable.item(loc.next(retryable.item()));
continue;
} else {
@@ -116,22 +116,22 @@ public class HMangr {
retryable.item(loc.next(item));
try {
Throwable ec = e.getCause();
- if(ec instanceof java.net.ConnectException) {
- if(client!=null && loc.hasItems()) {
+ if (ec instanceof java.net.ConnectException) {
+ 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()) {
+ } else if (ec instanceof java.net.SocketException) {
+ if (client!=null && loc.hasItems()) {
access.log(Level.WARN,"Socket prematurely closed, trying next available service");
retry = true;
} else {
throw new CadiException("Socket prematurely closed, no more services to try");
}
- } else if(ec instanceof SocketException) {
- if("java.net.SocketException: Connection reset".equals(ec.getMessage())) {
+ } else if (ec instanceof SocketException) {
+ if ("java.net.SocketException: Connection reset".equals(ec.getMessage())) {
access.log(Level.ERROR, ec.getMessage(), " can mean Certificate Expiration or TLS Protocol issues");
}
retryable.item(null);
@@ -148,7 +148,7 @@ public class HMangr {
loc.invalidate(item);
retryable.item(loc.next(item));
}
- } while(retry);
+ } while (retry);
} finally {
retryable.lastClient = client;
}
@@ -172,9 +172,9 @@ public class HMangr {
RET ret = null;
// make sure we have all current references:
loc.refresh();
- for(Item li=loc.first();li!=null;li=loc.next(li)) {
+ for (Item li=loc.first();li!=null;li=loc.next(li)) {
URI uri=loc.get(li);
- if(host!=null && !host.equals(uri.getHost())) {
+ if (host!=null && !host.equals(uri.getHost())) {
break;
}
try {
@@ -182,14 +182,14 @@ public class HMangr {
access.log(Level.DEBUG,"Success calling",uri,"during call to all services");
} catch (APIException | CadiException e) {
Throwable t = e.getCause();
- if(t!=null && t instanceof ConnectException) {
+ if (t!=null && t instanceof ConnectException) {
loc.invalidate(li);
access.log(Level.ERROR,"Connection to",uri,"refused during call to all services");
- } else if(t instanceof SSLHandshakeException) {
+ } else if (t instanceof SSLHandshakeException) {
access.log(Level.ERROR,t.getMessage());
loc.invalidate(li);
- } else if(t instanceof SocketException) {
- if("java.net.SocketException: Connection reset".equals(t.getMessage())) {
+ } else if (t instanceof SocketException) {
+ if ("java.net.SocketException: Connection reset".equals(t.getMessage())) {
access.log(Level.ERROR, t.getMessage(), " can mean Certificate Expiration or TLS Protocol issues");
}
retryable.item(null);
@@ -203,7 +203,7 @@ public class HMangr {
}
}
- if(ret == null && notify)
+ if (ret == null && notify)
throw new LocatorException("No available clients to call");
return ret;
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HNoAuthSS.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HNoAuthSS.java
index 0f1c8b41..1fecce2b 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HNoAuthSS.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HNoAuthSS.java
@@ -37,7 +37,7 @@ public class HNoAuthSS extends AbsAuthentication<HttpURLConnection> {
@Override
public void setSecurity(HttpURLConnection client) throws CadiException {
- if(securityInfo!=null && client instanceof HttpsURLConnection) {
+ if (securityInfo!=null && client instanceof HttpsURLConnection) {
securityInfo.setSocketFactoryOn((HttpsURLConnection)client);
}
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HRcli.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HRcli.java
index 674936d7..cbd7b33e 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HRcli.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HRcli.java
@@ -81,9 +81,9 @@ public class HRcli extends Rcli<HttpURLConnection> {
*/
protected EClient<HttpURLConnection> client() throws CadiException {
try {
- if(uri==null) {
+ if (uri==null) {
Item item = hman.loc.best();
- if(item==null) {
+ if (item==null) {
throw new CadiException("No service available for " + hman.loc.toString());
}
uri = hman.loc.get(item);
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HSecurityInfoInit.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HSecurityInfoInit.java
index d792be49..3f3517f2 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HSecurityInfoInit.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HSecurityInfoInit.java
@@ -41,9 +41,9 @@ public class HSecurityInfoInit implements SecurityInfoInit<HttpURLConnection> {
@Override
public SecuritySetter<HttpURLConnection> bestDefault(SecurityInfoC<HttpURLConnection> si) throws CadiException {
try {
- if(si.defaultAlias!=null) {
+ if (si.defaultAlias!=null) {
si.set(new HX509SS(si));
- } else if(si.access.getProperty(Config.AAF_APPID, null)!=null &&
+ } else if (si.access.getProperty(Config.AAF_APPID, null)!=null &&
si.access.getProperty(Config.AAF_APPPASS, null)!=null) {
si.set(new HBasicAuthSS(si));
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HTransferSS.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HTransferSS.java
index c527ed02..f68c1f61 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HTransferSS.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HTransferSS.java
@@ -44,14 +44,14 @@ public class HTransferSS extends AbsTransferSS<HttpURLConnection> {
@Override
public void setSecurity(HttpURLConnection huc) throws CadiException {
- if(defSS==null) {
+ if (defSS==null) {
throw new CadiException("Need App Credentials to send message");
}
defSS.setSecurity(huc);
- if(value!=null) {
+ if (value!=null) {
huc.addRequestProperty(Config.CADI_USER_CHAIN, value);
}
- if(securityInfo!=null) {
+ if (securityInfo!=null) {
securityInfo.setSocketFactoryOn((HttpsURLConnection)huc);
}
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HX509SS.java b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HX509SS.java
index cb8e6ce0..f441186e 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/http/HX509SS.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/http/HX509SS.java
@@ -68,8 +68,8 @@ public class HX509SS implements SecuritySetter<HttpURLConnection> {
public HX509SS(final String sendAlias, SecurityInfoC<HttpURLConnection> si, boolean asDefault) throws APIException, CadiException {
securityInfo = si;
- if((alias=sendAlias) == null) {
- if(si.defaultAlias == null) {
+ if ((alias=sendAlias) == null) {
+ if (si.defaultAlias == null) {
throw new APIException("JKS Alias is required to use X509SS Security. Use " + Config.CADI_ALIAS +" to set default alias");
} else {
alias = si.defaultAlias;
@@ -78,16 +78,16 @@ public class HX509SS implements SecuritySetter<HttpURLConnection> {
priv=null;
X509KeyManager[] xkms = si.getKeyManagers();
- if(xkms==null || xkms.length==0) {
+ if (xkms==null || xkms.length==0) {
throw new APIException("There are no valid keys available in given Keystores. Wrong Keypass? Expired?");
}
- for(int i=0;priv==null&&i<xkms.length;++i) {
+ for (int i=0;priv==null&&i<xkms.length;++i) {
priv = xkms[i].getPrivateKey(alias);
}
try {
- for(int i=0;cert==null&&i<xkms.length;++i) {
+ for (int i=0;cert==null&&i<xkms.length;++i) {
X509Certificate[] chain = xkms[i].getCertificateChain(alias);
- if(chain!=null&&chain.length>0) {
+ if (chain!=null&&chain.length>0) {
algo = chain[0].getSigAlgName();
pub = chain[0].getEncoded();
ByteArrayOutputStream baos = new ByteArrayOutputStream(pub.length*2);
@@ -99,17 +99,17 @@ public class HX509SS implements SecuritySetter<HttpURLConnection> {
} catch (CertificateEncodingException | IOException e) {
throw new CadiException(e);
}
- if(algo==null) {
+ if (algo==null) {
throw new APIException("X509 Security Setter not configured");
}
}
@Override
public void setSecurity(HttpURLConnection huc) throws CadiException {
- if(huc instanceof HttpsURLConnection) {
+ if (huc instanceof HttpsURLConnection) {
securityInfo.setSocketFactoryOn((HttpsURLConnection)huc);
}
- if(alias==null) { // must be a one-way
+ if (alias==null) { // must be a one-way
huc.setRequestProperty(AbsAuthentication.AUTHORIZATION, cert);
// Test Signed content
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java
index 1fc4b83e..8357129f 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java
@@ -46,7 +46,7 @@ public class DNSLocator implements Locator<URI> {
this.protocol = protocol;
this.access = access;
int dash = range.indexOf('-');
- if(dash<0) {
+ if (dash<0) {
startPort = endPort = Integer.parseInt(range);
} else {
startPort = Integer.parseInt(range.substring(0,dash));
@@ -57,15 +57,15 @@ public class DNSLocator implements Locator<URI> {
public DNSLocator(Access access, String aaf_locate) throws LocatorException {
this.access = access;
- if(aaf_locate==null) {
+ if (aaf_locate==null) {
throw new LocatorException("Null passed into DNSLocator constructor");
}
int start, port;
- if(aaf_locate.startsWith("https:")) {
+ if (aaf_locate.startsWith("https:")) {
protocol = "https:";
start = 9; // https://
port = 443;
- } else if(aaf_locate.startsWith("http:")) {
+ } else if (aaf_locate.startsWith("http:")) {
protocol = "http:";
start = 8; // http://
port = 80;
@@ -83,8 +83,8 @@ public class DNSLocator implements Locator<URI> {
@Override
public boolean hasItems() {
- for(Host h : hosts) {
- if(h.status==Status.OK) {
+ for (Host h : hosts) {
+ if (h.status==Status.OK) {
return true;
}
}
@@ -100,7 +100,7 @@ public class DNSLocator implements Locator<URI> {
@Override
public Item best() throws LocatorException {
// not a good "best"
- for(int i=0;i<hosts.length;++i) {
+ for (int i=0;i<hosts.length;++i) {
switch(hosts[i].status) {
case OK:
return new DLItem(i);
@@ -110,7 +110,7 @@ public class DNSLocator implements Locator<URI> {
break;
case UNTRIED:
try {
- if(hosts[i].ia.isReachable(CHECK_TIME)) {
+ if (hosts[i].ia.isReachable(CHECK_TIME)) {
hosts[i].status = Status.OK;
return new DLItem(i);
}
@@ -133,7 +133,7 @@ public class DNSLocator implements Locator<URI> {
@Override
public Item next(Item item) throws LocatorException {
DLItem di = (DLItem)item;
- if(++di.cnt<hosts.length) {
+ if (++di.cnt<hosts.length) {
return di;
} else {
return null;
@@ -146,8 +146,8 @@ public class DNSLocator implements Locator<URI> {
InetAddress[] ias = InetAddress.getAllByName(host);
Host[] temp = new Host[ias.length * (1 + endPort - startPort)];
int cnt = -1;
- for(int j=startPort; j<=endPort; ++j) {
- for(int i=0;i<ias.length;++i) {
+ for (int j=startPort; j<=endPort; ++j) {
+ for (int i=0;i<ias.length;++i) {
temp[++cnt] = new Host(ias[i], j, suffix);
}
}
@@ -162,10 +162,10 @@ public class DNSLocator implements Locator<URI> {
private void parsePorts(String aaf_locate, int defaultPort) throws LocatorException {
int slash, start;
int colon = aaf_locate.indexOf(':');
- if(colon > 0) {
+ if (colon > 0) {
start = colon + 1;
int left = aaf_locate.indexOf('[', start);
- if(left > 0) {
+ if (left > 0) {
int right = aaf_locate.indexOf(']', left + 1);
if (right < 0) {
throw new LocatorException("Missing closing bracket in DNSLocator constructor. (requested URL " + aaf_locate + ')');
@@ -176,7 +176,7 @@ public class DNSLocator implements Locator<URI> {
if (dash == (right - 1) || dash == (left + 1)) {
throw new LocatorException("Missing ports in brackets in DNSLocator constructor. (requested URL " + aaf_locate + ')');
}
- if(dash < 0) {
+ if (dash < 0) {
startPort = endPort = Integer.parseInt(aaf_locate.substring(left + 1, right));
} else {
startPort = Integer.parseInt(aaf_locate.substring(left + 1, dash));
@@ -188,7 +188,7 @@ public class DNSLocator implements Locator<URI> {
if (slash == start) {
throw new LocatorException("Missing port before '/' in DNSLocator constructor. (requested URL " + aaf_locate + ')');
}
- if(slash < 0) {
+ if (slash < 0) {
startPort = endPort = Integer.parseInt(aaf_locate.substring(start));
} else {
startPort = endPort = Integer.parseInt(aaf_locate.substring(start, slash));
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/HotPeerLocator.java b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/HotPeerLocator.java
index 26b8817b..93cefc58 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/HotPeerLocator.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/HotPeerLocator.java
@@ -74,15 +74,15 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
this.invalidateTime = invalidateTime;
double distance = Double.MAX_VALUE;
- for(int i=0;i<urlstrs.length;++i) {
+ for (int i=0;i<urlstrs.length;++i) {
String[] info = Split.split('/', urlstrs[i]);
- if(info.length<3) {
+ if (info.length<3) {
throw new LocatorException("Configuration needs LAT and LONG, i.e. ip:port/lat/long");
}
try {
clients[i] = _newClient(urlstrs[i]);
failures[i] = 0L;
- } catch(LocatorException le) {
+ } catch (LocatorException le) {
failures[i] = System.currentTimeMillis()+invalidateTime;
}
@@ -90,15 +90,15 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
distances[i]=d;
// find preferred server
- if(d<distance) {
+ if (d<distance) {
preferred = i;
distance=d;
}
}
access.printf(Level.INIT,"Preferred Client is %s",urlstrs[preferred]);
- for(int i=0;i<urlstrs.length;++i) {
- if(i!=preferred) {
+ for (int i=0;i<urlstrs.length;++i) {
+ if (i!=preferred) {
access.printf(Level.INIT,"Alternate Client is %s",urlstrs[i]);
}
}
@@ -117,7 +117,7 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
@Override
public Item best() throws LocatorException {
- if(failures[preferred]==0L) {
+ if (failures[preferred]==0L) {
return new HPItem(preferred);
} else {
long now = System.currentTimeMillis();
@@ -125,9 +125,9 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
int best = -1;
boolean tickle = false;
// try for best existing client
- for(int i=0;i<urlstrs.length;++i) {
- if(failures[i]<now && distances[i]<d) {
- if(clients[i]!=null) {
+ for (int i=0;i<urlstrs.length;++i) {
+ if (failures[i]<now && distances[i]<d) {
+ if (clients[i]!=null) {
best = i;
break;
} else {
@@ -135,13 +135,13 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
}
}
}
- if(best<0 && tickle) {
+ if (best<0 && tickle) {
tickle=false;
- if(refresh()) {
+ if (refresh()) {
// try again
- for(int i=0;i<urlstrs.length;++i) {
- if(failures[i]==0L && distances[i]<d) {
- if(clients[i]!=null) {
+ for (int i=0;i<urlstrs.length;++i) {
+ if (failures[i]==0L && distances[i]<d) {
+ if (clients[i]!=null) {
best = i;
break;
}
@@ -154,9 +154,9 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
* If a valid client is available, but there are some that can refresh, return the client immediately
* but start a Thread to do the background Client setup.
*/
- if(tickle) {
+ if (tickle) {
synchronized(clients) {
- if(refreshThread==null) {
+ if (refreshThread==null) {
refreshThread = new Thread(new Runnable(){
@Override
public void run() {
@@ -170,7 +170,7 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
}
}
- if(best<0) {
+ if (best<0) {
throw new LocatorException("No Clients available");
}
@@ -183,8 +183,8 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
public CLIENT get(Item item) throws LocatorException {
HPItem hpi = (HPItem)item;
CLIENT c = clients[hpi.idx];
- if(c==null) {
- if(failures[hpi.idx]>System.currentTimeMillis()) {
+ if (c==null) {
+ if (failures[hpi.idx]>System.currentTimeMillis()) {
throw new LocatorException("Client requested is invalid");
} else {
synchronized(clients) {
@@ -192,7 +192,7 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
failures[hpi.idx]=0L;
}
}
- } else if(failures[hpi.idx]>0){
+ } else if (failures[hpi.idx]>0){
throw new LocatorException("Client requested is invalid");
}
return c;
@@ -200,7 +200,7 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
public String info(Item item) {
HPItem hpi = (HPItem)item;
- if(hpi!=null && hpi.idx<urlstrs.length) {
+ if (hpi!=null && hpi.idx<urlstrs.length) {
return urlstrs[hpi.idx];
} else {
return "Invalid Item";
@@ -209,8 +209,8 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
@Override
public boolean hasItems() {
- for(int i=0;i<clients.length;++i) {
- if(clients[i]!=null && failures[i]==0L) {
+ for (int i=0;i<clients.length;++i) {
+ if (clients[i]!=null && failures[i]==0L) {
return true;
}
}
@@ -233,7 +233,7 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
@Override
public Item next(Item item) throws LocatorException {
HPItem hpi = (HPItem)item;
- if(++hpi.idx>=clients.length) {
+ if (++hpi.idx>=clients.length) {
return null;
}
return hpi;
@@ -244,11 +244,11 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
boolean force = !hasItems(); // If no Items at all, reset
boolean rv = true;
long now = System.currentTimeMillis();
- for(int i=0;i<clients.length;++i) {
- if(failures[i]>0L && (failures[i]<now || force)) { // retry
+ for (int i=0;i<clients.length;++i) {
+ if (failures[i]>0L && (failures[i]<now || force)) { // retry
try {
synchronized(clients) {
- if(clients[i]==null) {
+ if (clients[i]==null) {
clients[i]=_newClient(urlstrs[i]);
}
failures[i]=0L;
@@ -264,8 +264,8 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
@Override
public void destroy() {
- for(int i=0;i<clients.length;++i) {
- if(clients[i]!=null) {
+ for (int i=0;i<clients.length;++i) {
+ if (clients[i]!=null) {
_destroy(clients[i]);
clients[i] = null;
}
@@ -289,8 +289,8 @@ public abstract class HotPeerLocator<CLIENT> implements Locator<CLIENT> {
}
public boolean invalidate(CLIENT client) throws LocatorException {
- for(int i=0;i<clients.length;++i) {
- if(clients[i]==client) { // yes, "==" is appropriate here.. Comparing Java Object Reference
+ for (int i=0;i<clients.length;++i) {
+ if (clients[i]==client) { // yes, "==" is appropriate here.. Comparing Java Object Reference
invalidate(new HPItem(i));
return true;
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/PropertyLocator.java b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/PropertyLocator.java
index c1073315..eb0ecf11 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/PropertyLocator.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/PropertyLocator.java
@@ -61,7 +61,7 @@ public class PropertyLocator implements Locator<URI> {
minRefresh = minRefreshMillis;
backgroundRefresh = backgroundRefreshMillis;
lastRefreshed=0L;
- if(locList==null) {
+ if (locList==null) {
throw new LocatorException("No Location List given for PropertyLocator");
}
String[] locarray = Split.split(',',locList);
@@ -69,10 +69,10 @@ public class PropertyLocator implements Locator<URI> {
random = new SecureRandom();
- for(int i=0;i<locarray.length;++i) {
+ for (int i=0;i<locarray.length;++i) {
try {
int range = locarray[i].indexOf(":[");
- if(range<0) {
+ if (range<0) {
uriList.add(new URI(locarray[i]));
} else {
String mach_colon = locarray[i].substring(0, range+1);
@@ -81,7 +81,7 @@ public class PropertyLocator implements Locator<URI> {
int slash = locarray[i].indexOf('/',brac);
int start = Integer.parseInt(locarray[i].substring(range+2, dash));
int end = Integer.parseInt(locarray[i].substring(dash+1, brac));
- for(int port=start;port<=end;++port) {
+ for (int port=start;port<=end;++port) {
uriList.add(new URI(mach_colon+port + (slash>=0?locarray[i].substring(slash):"")));
}
}
@@ -106,7 +106,7 @@ public class PropertyLocator implements Locator<URI> {
@Override
public URI get(Item item) throws LocatorException {
synchronized(orig) {
- if(item==null) {
+ if (item==null) {
return null;
} else {
return resolved[((PLItem)item).idx];
@@ -126,31 +126,31 @@ public class PropertyLocator implements Locator<URI> {
@Override
public Item next(Item item) throws LocatorException {
- if(item==null) {
+ if (item==null) {
return null;
} else {
int spot;
- if((spot=(((PLItem)item).order+1))>=end)return null;
+ if ((spot=(((PLItem)item).order+1))>=end)return null;
return current[spot];
}
}
@Override
public synchronized void invalidate(Item item) throws LocatorException {
- if(--end<0) {
+ if (--end<0) {
refresh();
return;
}
- if(item==null) {
+ if (item==null) {
return;
}
PLItem pli = (PLItem)item;
int i,order;
- for(i=0;i<end;++i) {
- if(pli==current[i])break;
+ for (i=0;i<end;++i) {
+ if (pli==current[i])break;
}
order = current[i].order;
- for(;i<end;++i) {
+ for (;i<end;++i) {
current[i]=current[i+1];
current[i].order=order++;
}
@@ -159,7 +159,7 @@ public class PropertyLocator implements Locator<URI> {
@Override
public Item best() throws LocatorException {
- if(current.length==0) {
+ if (current.length==0) {
refresh();
}
switch(current.length) {
@@ -175,27 +175,27 @@ public class PropertyLocator implements Locator<URI> {
@Override
public synchronized boolean refresh() {
- if(System.currentTimeMillis()>lastRefreshed) {
+ if (System.currentTimeMillis()>lastRefreshed) {
// Build up list
List<URI> resolve = new ArrayList<>();
String realname;
- for(int i = 0; i < orig.length ; ++i) {
+ for (int i = 0; i < orig.length ; ++i) {
try {
InetAddress ia[] = InetAddress.getAllByName(orig[i].getHost());
URI o,n;
- for(int j=0;j<ia.length;++j) {
+ for (int j=0;j<ia.length;++j) {
o = orig[i];
Socket socket = createSocket();
try {
realname=ia[j].getHostAddress().equals(ia[j].getHostName())?ia[j].getCanonicalHostName():ia[j].getHostName();
int port = o.getPort();
- if(port<0) { // default
+ if (port<0) { // default
port = "https".equalsIgnoreCase(o.getScheme())?443:80;
}
socket.connect(new InetSocketAddress(realname,port),3000);
try {
- if(socket.isConnected()) {
+ if (socket.isConnected()) {
n = new URI(
o.getScheme(),
o.getUserInfo(),
@@ -212,7 +212,7 @@ public class PropertyLocator implements Locator<URI> {
}
} catch (IOException e) {
} finally {
- if(!socket.isClosed()) {
+ if (!socket.isClosed()) {
try {
socket.close();
} catch (IOException e) {
@@ -227,14 +227,14 @@ public class PropertyLocator implements Locator<URI> {
}
end=resolve.size();
PLItem[] newCurrent;
- if(current==null || current.length!=end) {
+ if (current==null || current.length!=end) {
newCurrent = new PLItem[end];
} else {
newCurrent = current;
}
- for(int i=0; i< end; ++i) {
- if(newCurrent[i]==null){
+ for (int i=0; i< end; ++i) {
+ if (newCurrent[i]==null){
newCurrent[i]=new PLItem(i);
} else {
newCurrent[i].idx=newCurrent[i].order=i;
@@ -271,18 +271,18 @@ public class PropertyLocator implements Locator<URI> {
public String toString() {
StringBuilder sb = new StringBuilder();
boolean first = true;
- for(URI uri : orig) {
+ for (URI uri : orig) {
boolean isResolved=false;
- if(uri!=null) {
- if(first) {
+ if (uri!=null) {
+ if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(uri.toString());
sb.append(" [");
- for(URI u2 : resolved) {
- if(uri.equals(u2)) {
+ for (URI u2 : resolved) {
+ if (uri.equals(u2)) {
isResolved = true;
break;
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java
index 816dec82..3b79dba5 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java
@@ -47,8 +47,8 @@ public class SingleEndpointLocator implements Locator<URI> {
@Override
public boolean hasItems() {
- if(noRetryUntil!=null) {
- if(new Date().after(noRetryUntil)) {
+ if (noRetryUntil!=null) {
+ if (new Date().after(noRetryUntil)) {
noRetryUntil = null;
} else {
return false;
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/routing/GreatCircle.java b/cadi/client/src/main/java/org/onap/aaf/cadi/routing/GreatCircle.java
index 3bce5245..27eb507f 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/routing/GreatCircle.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/routing/GreatCircle.java
@@ -87,7 +87,7 @@ public class GreatCircle {
switch(coords.length) {
case 1:
array = Split.split(',',coords[0]);
- if(array.length!=4)return -1;
+ if (array.length!=4)return -1;
return calc(
Double.parseDouble(array[0]),
Double.parseDouble(array[1]),
@@ -97,7 +97,7 @@ public class GreatCircle {
case 2:
array = Split.split(',',coords[0]);
String [] array2 = Split.split(',',coords[1]);
- if(array.length!=2 || array2.length!=2)return -1;
+ if (array.length!=2 || array2.length!=2)return -1;
return calc(
Double.parseDouble(array[0]),
Double.parseDouble(array[1]),
diff --git a/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_PropertyLocator.java b/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_PropertyLocator.java
index 7b61e398..0eae1198 100644
--- a/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_PropertyLocator.java
+++ b/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_PropertyLocator.java
@@ -107,7 +107,7 @@ public class JU_PropertyLocator {
private int countItems(PropertyLocator pl) throws LocatorException {
int count = 0;
- for(Item i = pl.first(); i != null; i = pl.next(i)) {
+ for (Item i = pl.first(); i != null; i = pl.next(i)) {
++count;
}
return count;