summaryrefslogtreecommitdiffstats
path: root/cadi/client/src/main
diff options
context:
space:
mode:
authorIanHowell <ian.howell@att.com>2018-04-27 10:32:53 -0500
committerIanHowell <ian.howell@att.com>2018-04-27 11:55:51 -0500
commit1f761f3591242a4ef2b6c7630342e9ecd402574f (patch)
treeea9595378dd40c6bbca4c6c570b0adb47be6e089 /cadi/client/src/main
parent6913298a6dcadd455314eb96fc940128db49965d (diff)
Improve coverage of cadi-client
Issue-ID: AAF-224 Change-Id: I950cffc889945205fada35b6f1d772c5318ba3b4 Signed-off-by: IanHowell <ian.howell@att.com>
Diffstat (limited to 'cadi/client/src/main')
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java69
1 files changed, 41 insertions, 28 deletions
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 655a0c22..ed60b877 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
@@ -73,34 +73,7 @@ public class DNSLocator implements Locator<URI> {
throw new LocatorException("DNSLocator accepts only https or http protocols. (requested URL " + aaf_locate + ')');
}
- int colon = aaf_locate.indexOf(':',start);
- int slash;
- if(colon>0) {
- start = colon+1;
- int left = aaf_locate.indexOf('[',start);
- if(left>0) {
- int right = aaf_locate.indexOf(']',left+1);
- if(right>0) {
- int dash = aaf_locate.indexOf('-',left+1);
- if(dash<0) {
- startPort = endPort = Integer.parseInt(aaf_locate.substring(left+1,right));
- } else {
- startPort = Integer.parseInt(aaf_locate.substring(left+1,dash));
- endPort = Integer.parseInt(aaf_locate.substring(dash + 1,right));
- }
- }
-
- } else {
- slash = aaf_locate.indexOf('/',colon+1);
- if(slash<0) {
- startPort = endPort = Integer.parseInt(aaf_locate.substring(start));
- } else {
- startPort = endPort = Integer.parseInt(aaf_locate.substring(start,slash));
- }
- }
- } else {
- startPort = endPort = port;
- }
+ parsePorts(aaf_locate.substring(start), port);
}
@Override
@@ -185,6 +158,46 @@ public class DNSLocator implements Locator<URI> {
}
return false;
}
+
+ private void parsePorts(String aaf_locate, int defaultPort) throws LocatorException {
+ int slash, start;
+ int colon = aaf_locate.indexOf(':');
+ if(colon > 0) {
+ start = colon + 1;
+ int left = aaf_locate.indexOf('[', start);
+ 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 + ')');
+ } else if (right == (left + 1)) {
+ throw new LocatorException("Missing ports in brackets in DNSLocator constructor. (requested URL " + aaf_locate + ')');
+ }
+ int dash = aaf_locate.indexOf('-', left + 1);
+ if (dash == (right - 1) || dash == (left + 1)) {
+ throw new LocatorException("Missing ports in brackets in DNSLocator constructor. (requested URL " + aaf_locate + ')');
+ }
+ if(dash < 0) {
+ startPort = endPort = Integer.parseInt(aaf_locate.substring(left + 1, right));
+ } else {
+ startPort = Integer.parseInt(aaf_locate.substring(left + 1, dash));
+ endPort = Integer.parseInt(aaf_locate.substring(dash + 1, right));
+ }
+
+ } else {
+ slash = aaf_locate.indexOf('/', start);
+ if (slash == start) {
+ throw new LocatorException("Missing port before '/' in DNSLocator constructor. (requested URL " + aaf_locate + ')');
+ }
+ if(slash < 0) {
+ startPort = endPort = Integer.parseInt(aaf_locate.substring(start));
+ } else {
+ startPort = endPort = Integer.parseInt(aaf_locate.substring(start, slash));
+ }
+ }
+ } else {
+ startPort = endPort = defaultPort;
+ }
+ }
private class Host {
private URI uri;