summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/dcae/collectors/restconf/common/AdditionalHeaderWebTarget.java10
-rwxr-xr-xsrc/main/java/org/onap/dcae/collectors/restconf/common/RestConfProc.java40
2 files changed, 34 insertions, 16 deletions
diff --git a/src/main/java/org/onap/dcae/collectors/restconf/common/AdditionalHeaderWebTarget.java b/src/main/java/org/onap/dcae/collectors/restconf/common/AdditionalHeaderWebTarget.java
index 81a658d..e814778 100644
--- a/src/main/java/org/onap/dcae/collectors/restconf/common/AdditionalHeaderWebTarget.java
+++ b/src/main/java/org/onap/dcae/collectors/restconf/common/AdditionalHeaderWebTarget.java
@@ -29,25 +29,27 @@ import java.util.Map;
class AdditionalHeaderWebTarget implements WebTarget {
private WebTarget base;
private String token;
+ private String headerName;
- public AdditionalHeaderWebTarget(WebTarget target, String token) {
+ public AdditionalHeaderWebTarget(WebTarget target, String token, String headerName) {
base = target;
this.token = token;
+ this.headerName = headerName;
}
@Override
public Invocation.Builder request() {
- return base.request().header("X-ACCESS-TOKEN", token);
+ return base.request().header(headerName, token);
}
@Override
public Invocation.Builder request(String... acceptedResponseTypes) {
- return base.request().header("X-ACCESS-TOKEN", token);
+ return base.request().header(headerName, token);
}
@Override
public Invocation.Builder request(MediaType... acceptedResponseTypes) {
- return base.request().header("X-ACCESS-TOKEN", token);
+ return base.request().header(headerName, token);
}
@Override
diff --git a/src/main/java/org/onap/dcae/collectors/restconf/common/RestConfProc.java b/src/main/java/org/onap/dcae/collectors/restconf/common/RestConfProc.java
index 4b3154c..5a4c880 100755
--- a/src/main/java/org/onap/dcae/collectors/restconf/common/RestConfProc.java
+++ b/src/main/java/org/onap/dcae/collectors/restconf/common/RestConfProc.java
@@ -36,6 +36,7 @@ import javax.net.ssl.X509TrustManager;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.HttpHeaders;
import java.nio.file.Paths;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@@ -47,9 +48,10 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.Base64;
-import static org.onap.dcae.collectors.restconf.common.RestapiCallNodeUtil.addAuthType;
import static org.onap.dcae.collectors.restconf.common.RestapiCallNodeUtil.getParameters;
+import static org.onap.dcae.collectors.restconf.common.RestapiCallNodeUtil.addAuthType;
public class RestConfProc {
@@ -171,16 +173,19 @@ public class RestConfProc {
paramMap.get(Constants.KSETTING_KEY_STORE_FILENAME));
params.put(Constants.KSETTING_KEY_STORE_PASSWORD, "adminadmin");
- restApiCallNode.sendRequest(params, ctx, null);
- log.debug("ctx response" + ctx);
- String httpResponse = ctx.getAttribute("httpResponse");
- JSONObject jsonObj = new JSONObject(httpResponse);
- log.debug("http response" + httpResponse);
- JSONObject data = jsonObj.getJSONObject("data");
- String tokenId = data.get("token_id").toString();
-
- paramMap.put("customHttpHeaders", "X-ACCESS-TOKEN=" + tokenId);
- paramMap.put("TokenId", tokenId);
+ String httpResponse = null;
+ try {
+ restApiCallNode.sendRequest(params, ctx, null);
+ httpResponse = ctx.getAttribute("httpResponse");
+ JSONObject jsonObj = new JSONObject(httpResponse);
+ JSONObject data = jsonObj.getJSONObject("data");
+ String tokenId = data.get("token_id").toString();
+ paramMap.put("customHttpHeaders", "X-ACCESS-TOKEN=" + tokenId);
+ paramMap.put("TokenId", tokenId);
+ } catch (Exception e) {
+ log.info("Access token is not supported" + e.getMessage());
+ log.info("http response" + httpResponse);
+ }
restApiCallNode.sendRequest(paramMap, ctx, null);
@@ -254,7 +259,13 @@ public class RestConfProc {
Client client = ignoreSslClient().register(SseFeature.class);
WebTarget target = addAuthType(client, p).target(url);
- AdditionalHeaderWebTarget newTarget = new AdditionalHeaderWebTarget(target, paramMap.get("TokenId"));
+ String token = paramMap.get("TokenId");
+ String headerName = "X-ACCESS-TOKEN";
+ if (token == null) {
+ headerName = HttpHeaders.AUTHORIZATION;
+ token = getAuthorizationToken(p.restapiUser, p.restapiPassword);
+ }
+ AdditionalHeaderWebTarget newTarget = new AdditionalHeaderWebTarget(target, token, headerName);
EventSource eventSource = EventSource.target(newTarget).build();
eventSource.register(new DataChangeEventListener(ctx));
eventSource.open();
@@ -273,6 +284,11 @@ public class RestConfProc {
}
}
+ private String getAuthorizationToken(String userName, String password) {
+ return "Basic " + Base64.getEncoder().encodeToString((
+ userName + ":" + password).getBytes());
+ }
+
/**
* To process the array of events which are received from controller
*