summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers')
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java70
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClient.java15
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientFactory.java11
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/RequestClientTest.java60
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java8
5 files changed, 92 insertions, 72 deletions
diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java
index e6e81671cf..75fb00c7a6 100644
--- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java
+++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java
@@ -29,7 +29,6 @@ import java.util.UUID;
import javax.xml.bind.DatatypeConverter;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
@@ -60,7 +59,7 @@ public class CamundaClient extends RequestClient {
@Override
public HttpResponse post(String camundaReqXML, String requestId, String requestTimeout, String schemaVersion,
- String serviceInstanceId, String action) throws ClientProtocolException, IOException {
+ String serviceInstanceId, String action) throws IOException {
HttpPost post = new HttpPost(url);
logger.debug(CAMUNDA_URL_MESAGE + url);
String jsonReq = wrapRequest(camundaReqXML, requestId, serviceInstanceId, requestTimeout, schemaVersion);
@@ -83,44 +82,18 @@ public class CamundaClient extends RequestClient {
private void setupHeaders(HttpPost post) {
post.addHeader(ONAPLogConstants.Headers.REQUEST_ID, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
post.addHeader(ONAPLogConstants.Headers.INVOCATION_ID, UUID.randomUUID().toString());
-
- String encryptedCredentials = null;
- if (props != null) {
- encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH);
- if (encryptedCredentials != null) {
- String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH,
- props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP));
- if (userCredentials != null) {
- post.addHeader(AUTHORIZATION,
- BASIC + new String(DatatypeConverter.printBase64Binary(userCredentials.getBytes())));
- }
- }
- }
+ addAuthorizationHeader(post);
}
@Override
- public HttpResponse post(String jsonReq) throws ClientProtocolException, IOException {
+ public HttpResponse post(String jsonReq) throws IOException {
HttpPost post = new HttpPost(url);
logger.debug(CAMUNDA_URL_MESAGE + url);
StringEntity input = new StringEntity(jsonReq);
input.setContentType(CommonConstants.CONTENT_TYPE_JSON);
setupHeaders(post);
-
- String encryptedCredentials = null;
- if (props != null) {
- encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH);
- if (encryptedCredentials != null) {
- String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH,
- props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP));
- if (userCredentials != null) {
- post.addHeader(AUTHORIZATION,
- BASIC + new String(DatatypeConverter.printBase64Binary(userCredentials.getBytes())));
- }
- }
- }
-
-
+ addAuthorizationHeader(post);
post.setEntity(input);
HttpResponse response = client.execute(post);
logger.debug(CAMUNDA_RESPONSE, response);
@@ -128,7 +101,7 @@ public class CamundaClient extends RequestClient {
return response;
}
- public HttpResponse post(RequestClientParameter parameterObject) throws ClientProtocolException, IOException {
+ public HttpResponse post(RequestClientParameter parameterObject) throws IOException {
HttpPost post = new HttpPost(url);
logger.debug(CAMUNDA_URL_MESAGE + url);
String jsonReq = wrapVIDRequest(parameterObject.getRequestId(), parameterObject.isBaseVfModule(),
@@ -143,23 +116,8 @@ public class CamundaClient extends RequestClient {
StringEntity input = new StringEntity(jsonReq);
input.setContentType(CommonConstants.CONTENT_TYPE_JSON);
-
-
setupHeaders(post);
-
- String encryptedCredentials = null;
- if (props != null) {
- encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH);
- if (encryptedCredentials != null) {
- String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH,
- props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP));
- if (userCredentials != null) {
- post.addHeader(AUTHORIZATION,
- BASIC + new String(DatatypeConverter.printBase64Binary(userCredentials.getBytes())));
- }
- }
- }
-
+ addAuthorizationHeader(post);
post.setEntity(input);
HttpResponse response = client.execute(post);
logger.debug(CAMUNDA_RESPONSE, response);
@@ -242,7 +200,6 @@ public class CamundaClient extends RequestClient {
CamundaInput recipeParamsInput = new CamundaInput();
CamundaInput instanceGroupIdInput = new CamundaInput();
- // host.setValue(parseURL());
requestIdInput.setValue(StringUtils.defaultString(requestId));
isBaseVfModuleInput.setValue(isBaseVfModule);
recipeTimeoutInput.setValue(recipeTimeout);
@@ -312,4 +269,19 @@ public class CamundaClient extends RequestClient {
}
return host;
}
+
+ private void addAuthorizationHeader(HttpPost post) {
+ String encryptedCredentials;
+ if (props != null) {
+ encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH);
+ if (encryptedCredentials != null) {
+ String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH,
+ props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP));
+ if (userCredentials != null) {
+ post.addHeader(AUTHORIZATION,
+ BASIC + new String(DatatypeConverter.printBase64Binary(userCredentials.getBytes())));
+ }
+ }
+ }
+ }
}
diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClient.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClient.java
index 9b7801711f..318b3ba5af 100644
--- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClient.java
+++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClient.java
@@ -25,7 +25,6 @@ package org.onap.so.apihandler.common;
import java.io.IOException;
import java.security.GeneralSecurityException;
import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.onap.so.utils.CryptoUtils;
import org.slf4j.Logger;
@@ -70,22 +69,12 @@ public abstract class RequestClient {
public abstract HttpResponse post(String request, String requestId, String requestTimeout, String schemaVersion,
String serviceInstanceId, String action) throws IOException;
- public abstract HttpResponse post(String request) throws ClientProtocolException, IOException;
+ public abstract HttpResponse post(String request) throws IOException;
- public abstract HttpResponse post(RequestClientParameter parameterObject)
- throws ClientProtocolException, IOException;
+ public abstract HttpResponse post(RequestClientParameter parameterObject) throws IOException;
public abstract HttpResponse get() throws IOException;
- protected String decryptPropValue(String prop, String defaultValue, String encryptionKey) {
- try {
- return CryptoUtils.decrypt(prop, encryptionKey);
- } catch (GeneralSecurityException e) {
- logger.debug("Security exception", e);
- }
- return defaultValue;
- }
-
protected String getEncryptedPropValue(String prop, String defaultValue, String encryptionKey) {
try {
return CryptoUtils.decrypt(prop, encryptionKey);
diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientFactory.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientFactory.java
index 4149d5ee45..c2ffa7e004 100644
--- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientFactory.java
+++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientFactory.java
@@ -4,6 +4,9 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ *
* 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
@@ -20,9 +23,7 @@
package org.onap.so.apihandler.common;
-
-
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@@ -34,7 +35,7 @@ public class RequestClientFactory {
private Environment env;
// based on URI, returns BPEL, CamundaTask or Camunda client
- public RequestClient getRequestClient(String orchestrationURI) throws IllegalStateException {
+ public RequestClient getRequestClient(String orchestrationURI) {
RequestClient retClient;
String url;
@@ -45,7 +46,7 @@ public class RequestClientFactory {
url = env.getProperty(CommonConstants.CAMUNDA_URL) + orchestrationURI;
retClient = new CamundaClient();
}
- retClient.setClient(new DefaultHttpClient());
+ retClient.setClient(HttpClientBuilder.create().build());
retClient.setProps(env);
retClient.setUrl(url);
return retClient;
diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/RequestClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/RequestClientTest.java
new file mode 100644
index 0000000000..86b12ae8f6
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/RequestClientTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (c) 2019 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.apihandler.common;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RequestClientTest {
+
+ private static final String ENCRYPTION_KEY = "aa3871669d893c7fb8abbcda31b88b4f";
+
+ private RequestClient requestClient;
+
+ @Before
+ public void init() {
+ requestClient = Mockito.mock(RequestClient.class, Mockito.CALLS_REAL_METHODS);
+ }
+
+ @Test
+ public void getEncryptedPropValueWithSuccess() {
+
+ String encryptedValue = requestClient.getEncryptedPropValue(
+ "E8E19DD16CC90D2E458E8FF9A884CC0452F8F3EB8E321F96038DE38D5C1B0B02DFAE00B88E2CF6E2A4101AB2C011FC161212EE",
+ "defaultValue", ENCRYPTION_KEY);
+
+ Assert.assertEquals("apihBpmn:camunda-R1512!", encryptedValue);
+ }
+
+ @Test
+ public void getDefaultEncryptedPropValue() {
+
+ String encryptedValue =
+ requestClient.getEncryptedPropValue("012345678901234567890123456789", "defaultValue", ENCRYPTION_KEY);
+
+ Assert.assertEquals("defaultValue", encryptedValue);
+ }
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java
index d9db5713a7..6942d441e6 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java
@@ -34,8 +34,6 @@ import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.client.graphinventory.entities.uri.Depth;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -63,7 +61,7 @@ public class AAIClientHelper {
* Update managing ECOMP Environment Info from A&AI
*
* @param id = operationalEnvironmentId
- * @param AAIOperationalEnvironment object
+ * @param aaiRequest object
*/
public void updateAaiOperationalEnvironment(String id, OperationalEnvironment aaiRequest) {
@@ -75,7 +73,7 @@ public class AAIClientHelper {
public void updateAaiOperationalEnvironment(String operationalEnvironmentId, Map<String, String> payload)
- throws Exception {
+ throws AAIClientCallFailed {
try {
AAIResourceUri uri =
AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, operationalEnvironmentId);
@@ -90,7 +88,7 @@ public class AAIClientHelper {
/**
* Create an Operational Environment object in A&AI
*
- * @param AAIOperationalEnvironment object
+ * @param operationalEnvironment object
*/
public void createOperationalEnvironment(OperationalEnvironment operationalEnvironment) {