aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java')
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java86
1 files changed, 31 insertions, 55 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 d11f1706e9..eb4ba76530 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
@@ -27,9 +27,9 @@ package org.onap.so.apihandler.common;
import java.io.IOException;
import java.util.UUID;
import javax.xml.bind.DatatypeConverter;
+import com.google.common.base.Strings;
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;
@@ -49,6 +49,9 @@ import com.fasterxml.jackson.databind.SerializationFeature;
public class CamundaClient extends RequestClient {
private static Logger logger = LoggerFactory.getLogger(CamundaClient.class);
private static final String CAMUNDA_URL_MESAGE = "Camunda url is: ";
+ private static final String CAMUNDA_RESPONSE = "Response is: {}";
+ private static final String AUTHORIZATION = "Authorization";
+ private static final String BASIC = "Basic ";
public CamundaClient() {
super(CommonConstants.CAMUNDA);
@@ -57,7 +60,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);
@@ -71,7 +74,7 @@ public class CamundaClient extends RequestClient {
setupHeaders(post);
HttpResponse response = client.execute(post);
- logger.debug("Response is: {}", response);
+ logger.debug(CAMUNDA_RESPONSE, response);
return response;
}
@@ -80,52 +83,26 @@ 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("Response is: {}", response);
+ logger.debug(CAMUNDA_RESPONSE, response);
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(),
@@ -140,26 +117,11 @@ 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("Response is: {}", response);
+ logger.debug(CAMUNDA_RESPONSE, response);
return response;
}
@@ -200,7 +162,7 @@ public class CamundaClient extends RequestClient {
jsonReq = mapper.writeValueAsString(camundaRequest);
logger.trace("request body is {}", jsonReq);
} catch (Exception e) {
- logger.error("{} {} {} {} {}", MessageEnum.APIH_WARP_REQUEST.toString(), "Camunda", "wrapRequest",
+ logger.error(Strings.repeat("{} ", 5), MessageEnum.APIH_WARP_REQUEST.toString(), "Camunda", "wrapRequest",
ErrorCode.BusinessProcesssError.getValue(), "Error in APIH Warp request", e);
}
return jsonReq;
@@ -239,7 +201,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);
@@ -292,8 +253,8 @@ public class CamundaClient extends RequestClient {
jsonReq = mapper.writeValueAsString(camundaRequest);
logger.trace("request body is {}", jsonReq);
} catch (Exception e) {
- logger.error("{} {} {} {} {}", MessageEnum.APIH_WARP_REQUEST.toString(), "Camunda", "wrapVIDRequest",
- ErrorCode.BusinessProcesssError.getValue(), "Error in APIH Warp request", e);
+ logger.error(Strings.repeat("{} ", 5), MessageEnum.APIH_WARP_REQUEST.toString(), "Camunda",
+ "wrapVIDRequest", ErrorCode.BusinessProcesssError.getValue(), "Error in APIH Warp request", e);
}
return jsonReq;
}
@@ -309,4 +270,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())));
+ }
+ }
+ }
+ }
}