aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2019-03-29 11:52:02 +0100
committersebdet <sebastien.determe@intl.att.com>2019-03-29 12:00:26 +0100
commit3772c8513f618f9b76fc7bfa55fa140eb60f2a4b (patch)
tree527a1c0bd2f1eb64c9cdba7f5e3d919310d60403 /src/main/java
parent8d36cfd7ccec9ea9a55894eeafba00da6037747d (diff)
Refactoring
Small refactoring of the Http library Issue-ID: CLAMP-333 Change-Id: I90a5488241ab84636bc0cec5849e97c4f98f3a38 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java4
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java2
-rw-r--r--src/main/java/org/onap/clamp/loop/Loop.java40
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopOperation.java (renamed from src/main/java/org/onap/clamp/operation/LoopOperation.java)5
-rw-r--r--src/main/java/org/onap/clamp/policy/PolicyOperation.java4
-rw-r--r--src/main/java/org/onap/clamp/util/HttpConnectionManager.java37
6 files changed, 40 insertions, 52 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
index 0f4659591..f74af49f8 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
@@ -99,7 +99,7 @@ public class DcaeDispatcherServices {
Date startTime = new Date();
LoggingUtils.setTargetContext("DCAE", "getOperationStatus");
try {
- String responseStr = dcaeHttpConnectionManager.doGeneralHttpQuery(statusUrl, "GET", null, null, "DCAE", null, null);
+ String responseStr = dcaeHttpConnectionManager.doHttpRequest(statusUrl, "GET", null, null, "DCAE", null, null);
JSONObject jsonObj = parseResponse(responseStr);
String operationType = (String) jsonObj.get("operationType");
String status = (String) jsonObj.get(DCAE_STATUS_FIELD);
@@ -190,7 +190,7 @@ public class DcaeDispatcherServices {
String nodeAttr) throws IOException, ParseException {
Date startTime = new Date();
try {
- String responseStr = dcaeHttpConnectionManager.doGeneralHttpQuery(url, requestMethod, payload, contentType, "DCAE", null, null);
+ String responseStr = dcaeHttpConnectionManager.doHttpRequest(url, requestMethod, payload, contentType, "DCAE", null, null);
JSONObject jsonObj = parseResponse(responseStr);
JSONObject linksObj = (JSONObject) jsonObj.get(node);
String statusUrl = (String) linksObj.get(nodeAttr);
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
index d8bfeeaec..dcf05423b 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
@@ -207,7 +207,7 @@ public class DcaeInventoryServices {
}
for (int i = 0; i < retryLimit; i++) {
metricsLogger.info("Attempt n°" + i + " to contact DCAE inventory");
- String response = httpConnectionManager.doGeneralHttpQuery(fullUrl, "GET", null, null, "DCAE", null, null);
+ String response = httpConnectionManager.doHttpRequest(fullUrl, "GET", null, null, "DCAE", null, null);
int totalCount = getTotalCountFromDcaeInventoryResponse(response);
metricsLogger.info("getDcaeInformation complete: totalCount returned=" + totalCount);
if (totalCount > 0) {
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java
index cc04ce5d2..e62874a8a 100644
--- a/src/main/java/org/onap/clamp/loop/Loop.java
+++ b/src/main/java/org/onap/clamp/loop/Loop.java
@@ -105,8 +105,7 @@ public class Loop implements Serializable {
@Expose
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
- @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"),
- inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
+ @JoinTable(name = "loops_microservicepolicies", joinColumns = @JoinColumn(name = "loop_id"), inverseJoinColumns = @JoinColumn(name = "microservicepolicy_id"))
private Set<MicroServicePolicy> microServicePolicies = new HashSet<>();
@Expose
@@ -135,23 +134,23 @@ public class Loop implements Serializable {
this.name = name;
}
- public String getDcaeDeploymentId() {
+ String getDcaeDeploymentId() {
return dcaeDeploymentId;
}
- public void setDcaeDeploymentId(String dcaeDeploymentId) {
+ void setDcaeDeploymentId(String dcaeDeploymentId) {
this.dcaeDeploymentId = dcaeDeploymentId;
}
- public String getDcaeDeploymentStatusUrl() {
+ String getDcaeDeploymentStatusUrl() {
return dcaeDeploymentStatusUrl;
}
- public void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
+ void setDcaeDeploymentStatusUrl(String dcaeDeploymentStatusUrl) {
this.dcaeDeploymentStatusUrl = dcaeDeploymentStatusUrl;
}
- public String getSvgRepresentation() {
+ String getSvgRepresentation() {
return svgRepresentation;
}
@@ -159,7 +158,7 @@ public class Loop implements Serializable {
this.svgRepresentation = svgRepresentation;
}
- public String getBlueprint() {
+ String getBlueprint() {
return blueprint;
}
@@ -167,11 +166,11 @@ public class Loop implements Serializable {
this.blueprint = blueprint;
}
- public LoopState getLastComputedState() {
+ LoopState getLastComputedState() {
return lastComputedState;
}
- public void setLastComputedState(LoopState lastComputedState) {
+ void setLastComputedState(LoopState lastComputedState) {
this.lastComputedState = lastComputedState;
}
@@ -183,7 +182,7 @@ public class Loop implements Serializable {
this.operationalPolicies = operationalPolicies;
}
- public Set<MicroServicePolicy> getMicroServicePolicies() {
+ Set<MicroServicePolicy> getMicroServicePolicies() {
return microServicePolicies;
}
@@ -222,7 +221,7 @@ public class Loop implements Serializable {
log.setLoop(this);
}
- public String getDcaeBlueprintId() {
+ String getDcaeBlueprintId() {
return dcaeBlueprintId;
}
@@ -230,7 +229,7 @@ public class Loop implements Serializable {
this.dcaeBlueprintId = dcaeBlueprintId;
}
- public JsonObject getModelPropertiesJson() {
+ JsonObject getModelPropertiesJson() {
return modelPropertiesJson;
}
@@ -240,13 +239,18 @@ public class Loop implements Serializable {
/**
* Generate the loop name.
- * @param serviceName The service name
- * @param serviceVersion The service version
- * @param resourceName The resource name
- * @param blueprintFileName The blueprint file name
+ *
+ * @param serviceName
+ * The service name
+ * @param serviceVersion
+ * The service version
+ * @param resourceName
+ * The resource name
+ * @param blueprintFileName
+ * The blueprint file name
* @return The generated loop name
*/
- public static String generateLoopName(String serviceName, String serviceVersion, String resourceName,
+ static String generateLoopName(String serviceName, String serviceVersion, String resourceName,
String blueprintFilename) {
StringBuilder buffer = new StringBuilder("LOOP_").append(serviceName).append("_v").append(serviceVersion)
.append("_").append(resourceName).append("_").append(blueprintFilename.replaceAll(".yaml", ""));
diff --git a/src/main/java/org/onap/clamp/operation/LoopOperation.java b/src/main/java/org/onap/clamp/loop/LoopOperation.java
index bdb4b3f0f..7def783b5 100644
--- a/src/main/java/org/onap/clamp/operation/LoopOperation.java
+++ b/src/main/java/org/onap/clamp/loop/LoopOperation.java
@@ -21,7 +21,7 @@
*
*/
-package org.onap.clamp.operation;
+package org.onap.clamp.loop;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@@ -45,9 +45,6 @@ import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.util.LoggingUtils;
import org.onap.clamp.clds.util.ONAPLogConstants;
import org.onap.clamp.exception.OperationException;
-import org.onap.clamp.loop.Loop;
-import org.onap.clamp.loop.LoopService;
-import org.onap.clamp.loop.LoopState;
import org.onap.clamp.policy.PolicyOperation;
import org.onap.clamp.util.HttpConnectionManager;
import org.slf4j.event.Level;
diff --git a/src/main/java/org/onap/clamp/policy/PolicyOperation.java b/src/main/java/org/onap/clamp/policy/PolicyOperation.java
index 592338c4d..edce8ff50 100644
--- a/src/main/java/org/onap/clamp/policy/PolicyOperation.java
+++ b/src/main/java/org/onap/clamp/policy/PolicyOperation.java
@@ -83,7 +83,7 @@ public class PolicyOperation {
String url = refProp.getStringValue(POLICY_URL_PROPERTY_NAME) + policyType + POLICY_URL_SUFFIX;
String userName = refProp.getStringValue(POLICY_USER_NAME);
String encodedPass = refProp.getStringValue(POLICY_PASSWORD);
- httpConnectionManager.doGeneralHttpQuery(url, "POST", payload.toString(), "application/json", "POLICY", userName, encodedPass);
+ httpConnectionManager.doHttpRequest(url, "POST", payload.toString(), "application/json", "POLICY", userName, encodedPass);
}
}
@@ -93,7 +93,7 @@ public class PolicyOperation {
String url = refProp.getStringValue(POLICY_URL_PROPERTY_NAME) + policyType + POLICY_URL_SUFFIX + "/" + msPolicy.getName();
String userName = refProp.getStringValue(POLICY_USER_NAME);
String encodedPass = refProp.getStringValue(POLICY_PASSWORD);
- httpConnectionManager.doGeneralHttpQuery(url, "POST", null, null, "POLICY", userName, encodedPass);
+ httpConnectionManager.doHttpRequest(url, "POST", null, null, "POLICY", userName, encodedPass);
}
}
diff --git a/src/main/java/org/onap/clamp/util/HttpConnectionManager.java b/src/main/java/org/onap/clamp/util/HttpConnectionManager.java
index 4e97f29b7..6459fa971 100644
--- a/src/main/java/org/onap/clamp/util/HttpConnectionManager.java
+++ b/src/main/java/org/onap/clamp/util/HttpConnectionManager.java
@@ -27,22 +27,19 @@ package org.onap.clamp.util;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import sun.misc.BASE64Encoder;
-
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.security.GeneralSecurityException;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
import javax.net.ssl.HttpsURLConnection;
import javax.ws.rs.BadRequestException;
-import org.apache.commons.codec.DecoderException;
import org.apache.commons.io.IOUtils;
-import org.onap.clamp.clds.util.CryptoUtils;
import org.onap.clamp.clds.util.LoggingUtils;
import org.springframework.stereotype.Component;
@@ -55,14 +52,16 @@ public class HttpConnectionManager {
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
private static final String REQUEST_FAILED_LOG = "Request Failed - response payload=";
- private String doHttpsQuery(URL url, String requestMethod, String payload, String contentType, String target, String userName, String password) throws IOException {
+ private String doHttpsQuery(URL url, String requestMethod, String payload, String contentType, String target,
+ String userName, String password) throws IOException {
LoggingUtils utils = new LoggingUtils(logger);
logger.info("Using HTTPS URL:" + url.toString());
HttpsURLConnection secureConnection = (HttpsURLConnection) url.openConnection();
secureConnection = utils.invokeHttps(secureConnection, target, requestMethod);
secureConnection.setRequestMethod(requestMethod);
if (userName != null && password != null) {
- secureConnection.setRequestProperty("Authorization", "Basic " + generateBasicAuth(userName, password));
+ secureConnection.setRequestProperty("Authorization", "Basic "
+ + Base64.getEncoder().encodeToString((userName + ":" + password).getBytes(StandardCharsets.UTF_8)));
}
if (payload != null && contentType != null) {
secureConnection.setRequestProperty("Content-Type", contentType);
@@ -91,14 +90,16 @@ public class HttpConnectionManager {
}
}
- private String doHttpQuery(URL url, String requestMethod, String payload, String contentType, String target, String userName, String password) throws IOException {
+ private String doHttpQuery(URL url, String requestMethod, String payload, String contentType, String target,
+ String userName, String password) throws IOException {
LoggingUtils utils = new LoggingUtils(logger);
logger.info("Using HTTP URL:" + url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection = utils.invoke(connection, target, requestMethod);
connection.setRequestMethod(requestMethod);
if (userName != null && password != null) {
- connection.setRequestProperty("Authorization", "Basic " + generateBasicAuth(userName, password));
+ connection.setRequestProperty("Authorization", "Basic "
+ + Base64.getEncoder().encodeToString((userName + ":" + password).getBytes(StandardCharsets.UTF_8)));
}
if (payload != null && contentType != null) {
connection.setRequestProperty("Content-Type", contentType);
@@ -144,8 +145,8 @@ public class HttpConnectionManager {
* @throws IOException
* In case of issue with the streams
*/
- public String doGeneralHttpQuery(String url, String requestMethod, String payload, String contentType, String target, String userName, String password)
- throws IOException {
+ public String doHttpRequest(String url, String requestMethod, String payload, String contentType, String target,
+ String userName, String password) throws IOException {
URL urlObj = new URL(url);
if (url.contains("https://")) { // Support for HTTPS
return doHttpsQuery(urlObj, requestMethod, payload, contentType, target, userName, password);
@@ -153,18 +154,4 @@ public class HttpConnectionManager {
return doHttpQuery(urlObj, requestMethod, payload, contentType, target, userName, password);
}
}
-
- private String generateBasicAuth(String userName, String encodedPassword) {
- String password = "";
- try {
- password = CryptoUtils.decrypt(encodedPassword);
- } catch (GeneralSecurityException e) {
- logger.error("Unable to decrypt the password", e);
- } catch (DecoderException e) {
- logger.error("Exception caught when decoding the HEX String Key for encryption", e);
- }
- BASE64Encoder enc = new sun.misc.BASE64Encoder();
- String userpassword = userName + ":" + password;
- return enc.encode( userpassword.getBytes() );
- }
}