* ================================================================================
* Copyright (C) 2018 Huawei Technologies Co., Ltd. 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
import java.io.IOException;
import java.security.GeneralSecurityException;
-
import javax.xml.bind.DatatypeConverter;
-
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.onap.so.bpmn.core.UrnPropertiesReader;
+import org.onap.so.logger.ErrorCode;
import org.onap.so.logger.MessageEnum;
-import org.onap.so.logger.MsoLogger;
import org.onap.so.utils.CryptoUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
- * Support to call resource recipes from the BPMN workflow.
- * Such as call resource recipe in service workflow.
- * <br>
+ * Support to call resource recipes from the BPMN workflow. Such as call resource recipe in service workflow. <br>
* <p>
* </p>
*
@Component
public class BpmnRestClient {
+ private static Logger logger = LoggerFactory.getLogger(BpmnRestClient.class);
+
public static final String DEFAULT_BPEL_AUTH = "admin:admin";
public static final String ENCRYPTION_KEY_PROP = "org.onap.so.adapters.network.encryptionKey";
public static final String CAMUNDA_AUTH = "mso.camundaAuth";
- private static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";
+ private static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";
@Autowired
private UrnPropertiesReader urnPropertiesReader;
- private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, BpmnRestClient.class);
private static boolean noProperties = true;
- //because for NS it will take a long time the time out of the resouce will be 2 hours.
+ // because for NS it will take a long time the time out of the resouce will be 2 hours.
private static final String DEFAULT_TIME_OUT = "7200";
public synchronized final boolean getNoPropertiesState() {
}
/**
- * post the recipe Uri
- * <br>
+ * post the recipe Uri <br>
*
* @param recipeUri The request recipe uri
* @param requestId the request id
* @throws IOException
* @since ONAP Beijing Release
*/
- public HttpResponse post(String recipeUri, String requestId, int recipeTimeout, String requestAction, String serviceInstanceId, String serviceType,
- String requestDetails, String recipeParamXsd) throws ClientProtocolException, IOException {
+ public HttpResponse post(String recipeUri, String requestId, int recipeTimeout, String requestAction,
+ String serviceInstanceId, String serviceType, String requestDetails, String recipeParamXsd)
+ throws ClientProtocolException, IOException {
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(recipeUri);
- RequestConfig requestConfig =
- RequestConfig.custom().setSocketTimeout(recipeTimeout).setConnectTimeout(recipeTimeout).setConnectionRequestTimeout(recipeTimeout).build();
+ RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(recipeTimeout)
+ .setConnectTimeout(recipeTimeout).setConnectionRequestTimeout(recipeTimeout).build();
post.setConfig(requestConfig);
- msoLogger.debug("call the bpmn, url:" + recipeUri);
- String jsonReq = wrapResourceRequest(requestId, recipeTimeout, requestAction, serviceInstanceId, serviceType, requestDetails, recipeParamXsd);
+ logger.debug("call the bpmn, url: {}", recipeUri);
+ String jsonReq = wrapResourceRequest(requestId, recipeTimeout, requestAction, serviceInstanceId, serviceType,
+ requestDetails, recipeParamXsd);
StringEntity input = new StringEntity(jsonReq);
input.setContentType(CONTENT_TYPE_JSON);
String encryptedCredentials;
encryptedCredentials = urnPropertiesReader.getVariable(CAMUNDA_AUTH);
- if(encryptedCredentials != null) {
- String userCredentials = getEncryptedPropValue(encryptedCredentials, DEFAULT_BPEL_AUTH, ENCRYPTION_KEY_PROP);
- if(userCredentials != null) {
- post.addHeader("Authorization", "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()));
+ if (encryptedCredentials != null) {
+ String userCredentials =
+ getEncryptedPropValue(encryptedCredentials, DEFAULT_BPEL_AUTH, ENCRYPTION_KEY_PROP);
+ if (userCredentials != null) {
+ post.addHeader("Authorization",
+ "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()));
}
}
-
+
post.setEntity(input);
return client.execute(post);
}
/**
- * prepare the resource recipe bpmn request.
- * <br>
+ * prepare the resource recipe bpmn request. <br>
*
* @param requestId
* @param recipeTimeout
* @return
* @since ONAP Beijing Release
*/
- private String wrapResourceRequest(String requestId, int recipeTimeout, String requestAction, String serviceInstanceId, String serviceType,
- String requestDetails, String recipeParams) {
+ private String wrapResourceRequest(String requestId, int recipeTimeout, String requestAction,
+ String serviceInstanceId, String serviceType, String requestDetails, String recipeParams) {
String jsonReq = null;
- if(requestId == null) {
+ if (requestId == null) {
requestId = "";
}
- if(requestAction == null) {
+ if (requestAction == null) {
requestAction = "";
}
- if(serviceInstanceId == null) {
+ if (serviceInstanceId == null) {
serviceInstanceId = "";
}
- if(requestDetails == null) {
+ if (requestDetails == null) {
requestDetails = "";
}
recipeRequest.setResourceInput(resourceInput);
recipeRequest.setRecipeTimeout(recipeTimeoutInput);
jsonReq = recipeRequest.toString();
- msoLogger.trace("request body is " + jsonReq);
- } catch(Exception e) {
- msoLogger.error(MessageEnum.APIH_WARP_REQUEST, "Camunda", "wrapVIDRequest", MsoLogger.ErrorCode.BusinessProcesssError, "Error in APIH Warp request",
- e);
+ 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);
}
return jsonReq;
}
protected String getEncryptedPropValue(String prop, String defaultValue, String encryptionKey) {
try {
return CryptoUtils.decrypt(prop, urnPropertiesReader.getVariable(encryptionKey));
- } catch(GeneralSecurityException e) {
- msoLogger.debug("Security exception", e);
+ } catch (GeneralSecurityException e) {
+ logger.debug("Security exception", e);
}
return defaultValue;
}