summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common/src
diff options
context:
space:
mode:
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>2021-02-03 13:56:31 +0100
committerDan Timoney <dtimoney@att.com>2021-02-05 16:52:27 -0500
commit80ebbf5b525b1a251f8e0eebd4a841d85716cf65 (patch)
treed68f747f92dc0c5e6a938474e252e26db63138e7 /sdnr/wt/common/src
parent4e69f3358d31173a222b275e2a82da692846aa1a (diff)
Update common and data-provider
common and data-provider migrated to Aluminium Issue-ID: CCSDK-3111 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> Change-Id: Ifb4ddb60f84ca7585137e04bc94d44885fe1f5f4 Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/common/src')
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java1
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/SearchResult.java11
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java41
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPResponse.java10
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseServlet.java8
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletInputStreamFromByteArrayInputStream.java15
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToByteArrayOutputStream.java18
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToStringWriter.java20
-rw-r--r--sdnr/wt/common/src/test/resources/testpom.xml4
9 files changed, 106 insertions, 22 deletions
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java
index 1ae9f1e6c..232b68c73 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/HtDatabaseClient.java
@@ -261,6 +261,7 @@ public class HtDatabaseClient extends ExtRestClient implements DatabaseClient, A
total = response.getTotal();
} catch (IOException e) {
+ LOG.warn("Possible Database connection failure. If this error persists, please check Database connectivity");
LOG.warn("error do search {}: {}", queryBuilder, e);
}
return new SearchResult<SearchHit>(response != null ? response.getHits() : new SearchHit[] {}, total);
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/SearchResult.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/SearchResult.java
index 5a011eec9..529853e08 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/SearchResult.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/database/SearchResult.java
@@ -45,10 +45,6 @@ public class SearchResult<T> {
this.total = total;
}
- // public SearchResult(List<T> hits,long total) {
- // this.hits = hits;
- // this.total = total;
- // }
public SearchResult() {
this.hits = new ArrayList<>();
this.total = 0;
@@ -69,4 +65,11 @@ public class SearchResult<T> {
public void add(T object) {
this.hits.add(object);
}
+
+ @Override
+ public String toString() {
+ return "SearchResult [hits=" + hits + ", total=" + total + "]";
+ }
+
+
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java
index 155e51609..198fb920c 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPClient.java
@@ -48,7 +48,11 @@ import java.security.interfaces.RSAPrivateKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import javax.annotation.Nonnull;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
@@ -56,7 +60,7 @@ import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
-import javax.xml.bind.DatatypeConverter;
+import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -111,6 +115,29 @@ public class BaseHTTPClient {
throws IOException {
return this.sendRequest(uri, method, body != null ? body.getBytes(CHARSET) : null, headers);
}
+ public BaseHTTPResponse sendRequest(HttpServletRequest req) throws IOException {
+ final String method = req.getMethod();
+ byte[] buffer=null;
+
+ if(!"GET".equals(method)) {
+ InputStream is = req.getInputStream();
+ buffer=is.readAllBytes();
+ is.close();
+
+ }
+ return this.sendRequest(req.getRequestURI(), method, buffer,mapHeaders(req));
+ }
+
+ private Map<String, String> mapHeaders(HttpServletRequest req) {
+ Map<String,String> headers = new HashMap<>();
+ Enumeration<String> keys = req.getHeaderNames();
+ String key;
+ while(keys.hasMoreElements()) {
+ key=keys.nextElement();
+ headers.put(key,req.getHeader(key));
+ }
+ return headers;
+ }
protected @Nonnull BaseHTTPResponse sendRequest(String uri, String method, byte[] body, Map<String, String> headers)
throws IOException {
@@ -164,10 +191,16 @@ public class BaseHTTPClient {
// Receive answer
int responseCode = ((HttpURLConnection) http).getResponseCode();
String sresponse = "";
+ Map<String,String> responseHeaders = null;
InputStream response = null;
try {
if (responseCode >= 200 && responseCode < 300) {
response = http.getInputStream();
+ responseHeaders = new HashMap<>();
+ for(Entry<String,List<String>> entry:http.getHeaderFields().entrySet()) {
+ responseHeaders.put(entry.getKey(), String.join(";", entry.getValue()));
+ }
+
} else {
response = ((HttpURLConnection) http).getErrorStream();
if (response == null) {
@@ -195,7 +228,7 @@ public class BaseHTTPClient {
}
LOG.debug("ResponseCode: " + responseCode);
LOG.trace("Response (len:{}): {}", String.valueOf(lensum), sresponse);
- return new BaseHTTPResponse(responseCode, sresponse);
+ return new BaseHTTPResponse(responseCode, sresponse,responseHeaders);
}
public static SSLContext setupSsl(boolean trustall)
@@ -299,7 +332,7 @@ public class BaseHTTPClient {
String data = new String(pem);
String[] tokens = data.split(beginDelimiter);
tokens = tokens[1].split(endDelimiter);
- return DatatypeConverter.parseBase64Binary(tokens[0]);
+ return Base64.getDecoder().decode(tokens[0]);
}
protected static RSAPrivateKey generatePrivateKeyFromDER(byte[] keyBytes)
@@ -337,4 +370,6 @@ public class BaseHTTPClient {
return SSLCERT_PEM;
}
+
+
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPResponse.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPResponse.java
index 91a2cc27c..a0fd7220e 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPResponse.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseHTTPResponse.java
@@ -21,6 +21,8 @@
*/
package org.onap.ccsdk.features.sdnr.wt.common.http;
+import java.util.Map;
+
public class BaseHTTPResponse {
public static final int CODE404 = 404;
@@ -28,10 +30,14 @@ public class BaseHTTPResponse {
public static final BaseHTTPResponse UNKNOWN = new BaseHTTPResponse(-1, "");
public final int code;
public final String body;
-
+ public final Map<String,String> headers;
public BaseHTTPResponse(int code, String body) {
+ this(code, body, null);
+ }
+ public BaseHTTPResponse(int code, String body, Map<String,String> rawData) {
this.code = code;
this.body = body;
+ this.headers = rawData;
}
@Override
@@ -40,6 +46,6 @@ public class BaseHTTPResponse {
}
public boolean isSuccess() {
- return this.code == CODE200;
+ return this.code >= CODE200 && this.code<300;
}
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseServlet.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseServlet.java
index 59e4e7705..f66070200 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseServlet.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/http/BaseServlet.java
@@ -32,7 +32,6 @@ import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
-
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
@@ -41,7 +40,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -328,9 +326,9 @@ public abstract class BaseServlet extends HttpServlet {
response = http.getInputStream();
} else {
response = http.getErrorStream();
- if (response == null) {
- http.getInputStream();
- }
+// if (response == null) {
+// response = http.getInputStream();
+// }
}
LOG.debug("ResponseCode: {}", responseCode);
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletInputStreamFromByteArrayInputStream.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletInputStreamFromByteArrayInputStream.java
index b926ff65c..6475ac3c9 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletInputStreamFromByteArrayInputStream.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletInputStreamFromByteArrayInputStream.java
@@ -23,6 +23,7 @@ package org.onap.ccsdk.features.sdnr.wt.common.test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
public class ServletInputStreamFromByteArrayInputStream extends ServletInputStream {
@@ -42,4 +43,18 @@ public class ServletInputStreamFromByteArrayInputStream extends ServletInputStre
return bis.read();
}
+ @Override
+ public boolean isFinished() {
+ return false;
+ }
+
+ @Override
+ public boolean isReady() {
+ return false;
+ }
+
+ @Override
+ public void setReadListener(ReadListener readListener) {
+ }
+
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToByteArrayOutputStream.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToByteArrayOutputStream.java
index 1914d9b67..3ea607cc0 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToByteArrayOutputStream.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToByteArrayOutputStream.java
@@ -24,6 +24,7 @@ package org.onap.ccsdk.features.sdnr.wt.common.test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.servlet.ServletOutputStream;
+import javax.servlet.WriteListener;
public class ServletOutputStreamToByteArrayOutputStream extends ServletOutputStream {
@@ -32,12 +33,21 @@ public class ServletOutputStreamToByteArrayOutputStream extends ServletOutputStr
// end of variables
+ public ByteArrayOutputStream getByteArrayOutputStream() {
+ return out;
+ }
+
@Override
- public void write(int arg0) throws IOException {
- out.write(arg0);
+ public void setWriteListener(WriteListener writeListener) {
}
- public ByteArrayOutputStream getByteArrayOutputStream() {
- return out;
+ @Override
+ public void write(int b) throws IOException {
+ out.write(b);
+ }
+
+ @Override
+ public boolean isReady() {
+ return false;
}
}
diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToStringWriter.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToStringWriter.java
index 57ed596ae..48d9f940f 100644
--- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToStringWriter.java
+++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/ServletOutputStreamToStringWriter.java
@@ -24,6 +24,7 @@ package org.onap.ccsdk.features.sdnr.wt.common.test;
import java.io.IOException;
import java.io.StringWriter;
import javax.servlet.ServletOutputStream;
+import javax.servlet.WriteListener;
public class ServletOutputStreamToStringWriter extends ServletOutputStream {
@@ -31,13 +32,28 @@ public class ServletOutputStreamToStringWriter extends ServletOutputStream {
private StringWriter out = new StringWriter();
// end of variables
+ public StringWriter getStringWriter() {
+ return out;
+ }
+
@Override
public void write(int arg0) throws IOException {
out.write(arg0);
}
- public StringWriter getStringWriter() {
- return out;
+ @Override
+ public String toString() {
+ return out.toString();
}
+ @Override
+ public boolean isReady() {
+ return false;
+ }
+
+ @Override
+ public void setWriteListener(WriteListener writeListener) {
+ }
+
+
}
diff --git a/sdnr/wt/common/src/test/resources/testpom.xml b/sdnr/wt/common/src/test/resources/testpom.xml
index 1adf713c1..6fba87af9 100644
--- a/sdnr/wt/common/src/test/resources/testpom.xml
+++ b/sdnr/wt/common/src/test/resources/testpom.xml
@@ -29,13 +29,13 @@
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>binding-parent</artifactId>
- <version>2.1.0</version>
+ <version>2.0.0-SNAPSHOT</version>
<relativePath/>
</parent>
<groupId>org.onap.ccsdk.features.sdnr.wt</groupId>
<artifactId>sdnr-wt-common</artifactId>
- <version>1.1.1-SNAPSHOT</version>
+ <version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ccsdk-features :: ${project.artifactId}</name>