summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/dcaegen2/services/pmmapper/messagerouter/VESPublisher.java10
-rw-r--r--src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java20
-rw-r--r--src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSender.java26
-rw-r--r--src/main/resources/reconfigure.sh2
4 files changed, 46 insertions, 12 deletions
diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/messagerouter/VESPublisher.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/messagerouter/VESPublisher.java
index 77b0545..46d40e4 100644
--- a/src/main/java/org/onap/dcaegen2/services/pmmapper/messagerouter/VESPublisher.java
+++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/messagerouter/VESPublisher.java
@@ -20,6 +20,8 @@
package org.onap.dcaegen2.services.pmmapper.messagerouter;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
import java.util.List;
import org.onap.dcaegen2.services.pmmapper.exceptions.MRPublisherException;
@@ -61,7 +63,13 @@ public class VESPublisher {
private void publish(String ves) {
try {
String topicUrl = config.getPublisherTopicUrl();
- sender.send("POST", topicUrl, ves);
+ ves = ves.replaceAll("\n", "");
+ String userCredentials = topicUrl.startsWith("https") ? Base64.getEncoder()
+ .encodeToString((this.config.getPublisherUserName() + ":" +
+ this.config.getPublisherPassword())
+ .getBytes(StandardCharsets.UTF_8))
+ : "";
+ sender.send("POST", topicUrl, ves, userCredentials);
} catch (Exception e) {
throw new MRPublisherException(e.getMessage(), e);
}
diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java
index 390fa0d..0630d53 100644
--- a/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java
+++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/model/MapperConfig.java
@@ -118,6 +118,12 @@ public class MapperConfig implements Configurable{
@GSONRequired
@SerializedName("dmaap_info")
DmaapInfo dmaapInfo;
+
+ @SerializedName("aaf_username")
+ private String aafUsername;
+
+ @SerializedName("aaf_password")
+ private String aafPassword;
}
@Getter
@@ -133,12 +139,6 @@ public class MapperConfig implements Configurable{
@SerializedName("subscriber_id")
private String subscriberId;
- @SerializedName("aaf_username")
- private String aafUsername;
-
- @SerializedName("aaf_password")
- private String aafPassword;
-
@SerializedName("client_role")
private String clientRole;
@@ -149,6 +149,14 @@ public class MapperConfig implements Configurable{
private String topicUrl;
}
+ public String getPublisherUserName() {
+ return this.getStreamsPublishes().getDmaapPublisher().getAafUsername();
+ }
+
+ public String getPublisherPassword() {
+ return this.getStreamsPublishes().getDmaapPublisher().getAafPassword();
+ }
+
@Override
public void reconfigure(MapperConfig mapperConfig) {
if(!this.equals(mapperConfig)) {
diff --git a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSender.java b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSender.java
index fdbae59..c8e29f3 100644
--- a/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSender.java
+++ b/src/main/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSender.java
@@ -27,6 +27,8 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -38,6 +40,7 @@ import org.slf4j.LoggerFactory;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
+import org.jboss.logging.MDC;
public class RequestSender {
private static final int MAX_RETRIES = 5;
@@ -68,16 +71,27 @@ public class RequestSender {
}
/**
+ * Works just like {@link RequestSender#send(method,urlString,body, basicAuth)}, except {@code basicAuth }
+ * is set to empty String by default.
+ * @see RequestSender#send(String,String,String,String)
+ */
+ public String send(String method, final String urlString, final String body) throws Exception {
+ return send(method,urlString,body,"");
+ }
+
+ /**
* Sends an http request to a given endpoint.
* @param method of the outbound request
* @param urlString representing given endpoint
* @param body of the request as json
+ * @param encodedCredentials base64-encoded username password credentials
* @return http response body
* @throws Exception
*/
- public String send(String method, final String urlString, final String body) throws Exception {
+ public String send(String method, final String urlString, final String body, final String encodedCredentials) throws Exception {
final UUID invocationID = logger.invoke(ONAPLogConstants.InvocationMode.SYNCHRONOUS);
- final UUID requestID = UUID.randomUUID();
+ String requestID = Optional.ofNullable((String)MDC.get(ONAPLogConstants.MDCs.REQUEST_ID))
+ .orElse( UUID.randomUUID().toString());
String result = "";
for (int i = 1; i <= MAX_RETRIES; i++) {
@@ -89,6 +103,10 @@ public class RequestSender {
HttpsURLConnection.setDefaultSSLSocketFactory(SSLContext.getDefault().getSocketFactory());
}
+ if(!encodedCredentials.isEmpty()) {
+ connection.setRequestProperty("Authorization", "Basic " + encodedCredentials);
+ }
+
if(!body.isEmpty()) {
setMessageBody(connection, body);
}
@@ -116,10 +134,10 @@ public class RequestSender {
return result;
}
- private HttpURLConnection getHttpURLConnection(String method, URL url, UUID invocationID, UUID requestID) throws IOException {
+ private HttpURLConnection getHttpURLConnection(String method, URL url, UUID invocationID, String requestID) throws IOException {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setReadTimeout(DEFAULT_READ_TIMEOUT);
- connection.setRequestProperty(ONAPLogConstants.Headers.REQUEST_ID, requestID.toString());
+ connection.setRequestProperty(ONAPLogConstants.Headers.REQUEST_ID, requestID);
connection.setRequestProperty(ONAPLogConstants.Headers.INVOCATION_ID, invocationID.toString());
connection.setRequestProperty(ONAPLogConstants.Headers.PARTNER_NAME, MapperConfig.CLIENT_NAME);
connection.setRequestMethod(method);
diff --git a/src/main/resources/reconfigure.sh b/src/main/resources/reconfigure.sh
index ac6f940..79aea06 100644
--- a/src/main/resources/reconfigure.sh
+++ b/src/main/resources/reconfigure.sh
@@ -2,5 +2,5 @@
while true
do
sleep 60
- echo $(wget -S --spider localhost:8081/reconfigure 2>&1) >> /var/log/ONAP/dcaegen2/services/pm-mapper/reconfigure.log
+ echo $(wget -S --spider --no-check-certificate https://localhost:8443/reconfigure 2>&1) >> /var/log/ONAP/dcaegen2/services/pm-mapper/reconfigure.log
done