diff options
author | rob.bog <r.bogacki@samsung.com> | 2019-05-29 15:18:09 +0200 |
---|---|---|
committer | rob.bog <r.bogacki@samsung.com> | 2019-05-29 15:19:12 +0200 |
commit | f5f7f63a21dace915dd6e6be5b36c23a5406e57e (patch) | |
tree | fd0449973a18574a3102ac930ee6e24966a5728d /mso-api-handlers | |
parent | c1cd5ef428017bc26513395a3bfc00caf7209f8a (diff) |
Improvements in CamundaClient
Removed code duplicates.
Fixed declarations of thrown exceptions.
Fixed imports.
Issue-ID: SO-1936
Signed-off-by: Robert Bogacki <r.bogacki@samsung.com>
Change-Id: Ic178341b0049307da033408719ff263a00059ba7
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.java | 70 |
1 files changed, 21 insertions, 49 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()))); + } + } + } + } } |