aboutsummaryrefslogtreecommitdiffstats
path: root/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java')
-rw-r--r--blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java55
1 files changed, 29 insertions, 26 deletions
diff --git a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java
index 55cdca40b..8cb5e9bea 100644
--- a/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java
+++ b/blueprints-processor/adaptors/rest-adaptor-provider/src/main/java/org/onap/ccsdk/config/rest/adaptor/service/GenericRestClientAdapterImpl.java
@@ -1,15 +1,18 @@
/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
*
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.onap.ccsdk.config.rest.adaptor.service;
@@ -26,16 +29,16 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
public class GenericRestClientAdapterImpl extends AbstractConfigRestClientAdapter {
-
+
private static EELFLogger logger = EELFManager.getInstance().getLogger(GenericRestClientAdapterImpl.class);
private String baseUrl = "";
-
+
public GenericRestClientAdapterImpl(Map<String, String> properties, String serviceSelector)
throws ConfigRestAdaptorException {
super(properties, serviceSelector);
init(serviceSelector);
}
-
+
private void init(String serviceSelector) throws ConfigRestAdaptorException {
try {
if (isRestClientServiceAdapaterEnabled) {
@@ -45,11 +48,11 @@ public class GenericRestClientAdapterImpl extends AbstractConfigRestClientAdapte
+ ConfigRestAdaptorConstants.SERVICE_USER_PROPERTY;
String passProperty = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector
+ ConfigRestAdaptorConstants.SERVICE_PSSWD_PROPERTY;
-
+
baseUrl = properties.get(baseUrlProperty);
String userId = properties.get(userProperty);
String pass = properties.get(passProperty);
-
+
initialise(userId, pass);
logger.info("Initialised restconf adaptor service for selector ({})", serviceSelector);
if (restTemplate == null) {
@@ -58,52 +61,52 @@ public class GenericRestClientAdapterImpl extends AbstractConfigRestClientAdapte
} else {
throw new ConfigRestAdaptorException("rest selector (" + serviceSelector + ") is not enabled");
}
-
+
} catch (Exception e) {
throw new ConfigRestAdaptorException("GenericRestClientServiceAdapter : " + e.getMessage(), e);
}
}
-
+
@Override
public <T> T getResource(String path, Class<T> responseType) throws ConfigRestAdaptorException {
return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path), responseType);
}
-
+
@Override
public <T> T postResource(String path, Object request, Class<T> responseType) throws ConfigRestAdaptorException {
return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType);
}
-
+
@Override
public <T> T exchangeResource(String path, Object request, Class<T> responseType, String method)
throws ConfigRestAdaptorException {
return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, responseType, method);
}
-
+
@Override
public RestResponse getResource(String path) throws ConfigRestAdaptorException {
return super.getResource(formHttpHeaders(), constructUrl(baseUrl, path));
}
-
+
@Override
public RestResponse postResource(String path, Object request) throws ConfigRestAdaptorException {
return super.postResource(formHttpHeaders(), constructUrl(baseUrl, path), request);
}
-
+
@Override
public RestResponse exchangeResource(String path, Object request, String method) throws ConfigRestAdaptorException {
return super.exchangeResource(formHttpHeaders(), constructUrl(baseUrl, path), request, method);
}
-
+
private HttpHeaders formHttpHeaders() {
-
+
HttpHeaders headers = new HttpHeaders();
-
+
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
headers.add("X-TransactionId", generateUUID());
headers.add("X-ECOMP-RequestID", headers.getFirst("X-TransactionId"));
-
+
String appIDPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector
+ ConfigRestAdaptorConstants.SERVICE_APPID_PROPERTY;
String environmentPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector
@@ -112,7 +115,7 @@ public class GenericRestClientAdapterImpl extends AbstractConfigRestClientAdapte
+ ConfigRestAdaptorConstants.SERVICE_CLIENTAUTH_PROPERTY;
String authorizationPath = ConfigRestAdaptorConstants.REST_ADAPTOR_BASE_PROPERTY + serviceSelector
+ ConfigRestAdaptorConstants.SERVICE_AUTHORIZATION_PROPERTY;
-
+
if (StringUtils.isNotBlank(properties.get(appIDPath))) {
headers.add("X-FromAppId", properties.get(appIDPath));
}
@@ -125,12 +128,12 @@ public class GenericRestClientAdapterImpl extends AbstractConfigRestClientAdapte
if (StringUtils.isNotBlank(properties.get(environmentPath))) {
headers.add("Environment", properties.get(environmentPath));
}
-
+
return headers;
}
-
+
private synchronized String generateUUID() {
return UUID.randomUUID().toString();
}
-
+
}