diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main')
-rw-r--r-- | bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/NssmfAdapterUtils.groovy | 136 | ||||
-rw-r--r-- | bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy | 12 |
2 files changed, 88 insertions, 60 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/NssmfAdapterUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/NssmfAdapterUtils.groovy index 775f088136..bbe5f0d0a4 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/NssmfAdapterUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/NssmfAdapterUtils.groovy @@ -22,22 +22,15 @@ package org.onap.so.bpmn.common.scripts import org.apache.commons.lang3.StringUtils import org.camunda.bpm.engine.delegate.DelegateExecution -import org.json.JSONArray -import org.json.JSONObject -import org.onap.logging.filter.base.ErrorCode import org.onap.logging.filter.base.ONAPComponents -import org.onap.logging.ref.slf4j.ONAPLogConstants +import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.json.JsonUtils import org.onap.so.client.HttpClient import org.onap.so.client.HttpClientFactory -import org.onap.so.logger.LoggingAnchor -import org.onap.so.logger.MessageEnum import org.slf4j.Logger import org.slf4j.LoggerFactory -import org.springframework.web.util.UriUtils -import javax.ws.rs.core.MediaType import javax.ws.rs.core.Response /*** @@ -94,56 +87,91 @@ class NssmfAdapterUtils { } - public String sendPostRequestNSSMF (DelegateExecution execution, String endPoint, String nssmfRequest) { - try { - - String nssmfEndpoint = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint",execution) - String queryEndpoint = nssmfEndpoint + endPoint - def responseData - HttpClient client = httpClientFactory.newJsonClient(new URL(queryEndpoint), ONAPComponents.EXTERNAL) - String basicAuthCred = execution.getVariable("BasicAuthHeaderValue") - client.addAdditionalHeader("Authorization", StringUtils.defaultIfEmpty(basicAuthCred, getBasicDBAuthHeader(execution))) - - logger.debug('sending POST to NSSMF endpoint: ' + endPoint) - Response response = client.post(nssmfRequest) - - responseData = response.readEntity(String.class) - if (responseData != null) { - logger.debug("Received data from NSSMF: " + responseData) - } - - logger.debug('Response code:' + response.getStatus()) - logger.debug('Response:' + System.lineSeparator() + responseData) - if (response.getStatus() >= 200 && response.getStatus() < 300) { - // parse response as needed - return responseData - } - else { - return null - } - } - catch (Exception e) { - logger.debug("ERROR WHILE QUERYING CATALOG DB: " + e.message) - throw e - } + public String sendPostRequestNSSMF (DelegateExecution execution, String endPoint, String nssmfRequest) { + try { - } + String nssmfEndpoint = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint",execution) + String queryEndpoint = nssmfEndpoint + endPoint + def responseData + HttpClient client = httpClientFactory.newJsonClient(new URL(queryEndpoint), ONAPComponents.EXTERNAL) + String basicAuthCred = execution.getVariable("BasicAuthHeaderValue") + client.addAdditionalHeader("Authorization", StringUtils.defaultIfEmpty(basicAuthCred, getBasicDBAuthHeader(execution))) + logger.debug('sending POST to NSSMF endpoint: ' + endPoint) + Response response = client.post(nssmfRequest) + + responseData = response.readEntity(String.class) + if (responseData != null) { + logger.debug("Received data from NSSMF: " + responseData) + } + + logger.debug('Response code:' + response.getStatus()) + logger.debug('Response:' + System.lineSeparator() + responseData) + if (response.getStatus() >= 200 && response.getStatus() < 300) { + // parse response as needed + return responseData + } + else { + return null + } + } + catch (Exception e) { + logger.debug("ERROR WHILE QUERYING CATALOG DB: " + e.message) + throw e + } - private String getBasicDBAuthHeader(DelegateExecution execution) { + } - String encodedString = null - try { - String basicAuthValueDB = UrnPropertiesReader.getVariable("mso.adapters.db.auth", execution) - logger.debug("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB) + public String sendPostRequestNSSMF (DelegateExecution execution, String endPoint, NssmfAdapterNBIRequest nssmfRequest) { + try { + + String nssmfEndpoint = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint",execution) + String queryEndpoint = nssmfEndpoint + endPoint + def responseData + HttpClient client = httpClientFactory.newJsonClient(new URL(queryEndpoint), ONAPComponents.EXTERNAL) + String basicAuthCred = execution.getVariable("BasicAuthHeaderValue") + client.addAdditionalHeader("Authorization", StringUtils.defaultIfEmpty(basicAuthCred, getBasicDBAuthHeader(execution))) + + logger.debug('sending POST to NSSMF endpoint: ' + endPoint) + Response response = client.post(nssmfRequest) + + responseData = response.readEntity(String.class) + if (responseData != null) { + logger.debug("Received data from NSSMF: " + responseData) + } + + logger.debug('Response code:' + response.getStatus()) + logger.debug('Response:' + System.lineSeparator() + responseData) + if (response.getStatus() >= 200 && response.getStatus() < 300) { + // parse response as needed + return responseData + } + else { + return null + } + } + catch (Exception e) { + logger.debug("ERROR WHILE QUERYING CATALOG DB: " + e.message) + throw e + } + + } + + private String getBasicDBAuthHeader(DelegateExecution execution) { + + String encodedString = null + try { + String basicAuthValueDB = UrnPropertiesReader.getVariable("mso.adapters.db.auth", execution) + logger.debug("DEBUG", " Obtained BasicAuth userid password for Catalog DB adapter: " + basicAuthValueDB) + + encodedString = utils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution)) + execution.setVariable("BasicAuthHeaderValue", encodedString) + } catch (IOException ex) { + String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage() + logger.error(dataErrorMessage) + } + return encodedString + } - encodedString = utils.getBasicAuth(basicAuthValueDB, UrnPropertiesReader.getVariable("mso.msoKey", execution)) - execution.setVariable("BasicAuthHeaderValue", encodedString) - } catch (IOException ex) { - String dataErrorMessage = " Unable to encode Catalog DB user/password string - " + ex.getMessage() - logger.error(dataErrorMessage) - } - return encodedString - } } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy index ff31c46a3a..37b30567c7 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy @@ -22,6 +22,7 @@ package org.onap.so.bpmn.common.scripts +import com.google.gson.GsonBuilder import org.onap.so.beans.nsmf.oof.NsiReqBody import org.onap.so.beans.nsmf.oof.NssiReqBody import org.onap.so.beans.nsmf.oof.RequestInfo @@ -682,9 +683,7 @@ return json.toString() nsiReqBody.setNSSTInfo(nsstInfo) nsiReqBody.setPreferReuse(preferReuse) - ObjectMapper objectMapper = new ObjectMapper() - - return objectMapper.writeValueAsString(nsiReqBody) + return bean2JsonStr(nsiReqBody) } public <T> String buildSelectNSSIRequest(String requestId, TemplateInfo nsstInfo, String messageType, @@ -710,9 +709,10 @@ return json.toString() nssiReqBody.setSliceProfile(sliceProfile) nssiReqBody.setNSSTInfo(nsstInfo) + return bean2JsonStr(nssiReqBody) + } - ObjectMapper objectMapper = new ObjectMapper() - - return objectMapper.writeValueAsString(nssiReqBody) + private static <T> String bean2JsonStr(T t) { + return new GsonBuilder().setPrettyPrinting().create().toJson(t) } } |