aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-09-26 07:50:07 +0300
committerIttay Stern <ittay.stern@att.com>2019-10-02 12:38:31 +0300
commita92741c73951498d10644635da2335391ac56e02 (patch)
tree1553e9e9cf7288165c960544f508817c90db2968 /vid-app-common/src/main/java/org
parent32208b52da320c4013b577b55dde8f41bebaa240 (diff)
Verify partner-name header sent to AAI, SO
Issue-ID: VID-253 Change-Id: I80c710db1eb3f48c52b7ecebb234e75a503bf65d Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java608
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt17
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java3
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java3
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java4
5 files changed, 326 insertions, 309 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
index 034800516..45ced6bdf 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
@@ -8,9 +8,9 @@
* 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.
@@ -22,6 +22,7 @@ package org.onap.vid.aai.util;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
+import static org.onap.vid.logging.Headers.PARTNER_NAME;
import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
import com.att.eelf.configuration.EELFLogger;
@@ -52,305 +53,308 @@ import org.springframework.http.HttpMethod;
*/
public class AAIRestInterface {
- /** The logger. */
- protected EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AAIRestInterface.class);
-
- protected final EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("aai");
-
- /** The client. */
- private Client client = null;
-
- /** The rest srvr base URL. */
- private String restSrvrBaseURL;
-
- @Autowired
- protected HttpsAuthClient httpsAuthClientFactory;
- private final ServletRequestHelper servletRequestHelper;
- private final SystemPropertyHelper systemPropertyHelper;
- protected final Logging loggingService;
-
- protected static final String START_STRING = " start";
- protected static final String TRANSACTION_ID_HEADER = "X-TransactionId";
- protected static final String FROM_APP_ID_HEADER = "X-FromAppId";
- protected static final String SUCCESSFUL_API_MESSAGE = " REST api call was successful!";
- protected static final String URL_DECLARATION = ", url=";
-
- public AAIRestInterface(HttpsAuthClient httpsAuthClientFactory,
- ServletRequestHelper servletRequestHelper,
- SystemPropertyHelper systemPropertyHelper,
- Logging loggingService) {
- this.httpsAuthClientFactory = httpsAuthClientFactory;
- this.servletRequestHelper = servletRequestHelper;
- this.systemPropertyHelper = systemPropertyHelper;
- this.loggingService = loggingService;
- initRestClient();
- }
-
- /**
- * For testing purpose
- */
- AAIRestInterface(Optional<Client> client,
- HttpsAuthClient httpsAuthClientFactory,
- ServletRequestHelper servletRequestHelper,
- SystemPropertyHelper systemPropertyHelper,
- Logging loggingService){
- this.httpsAuthClientFactory = httpsAuthClientFactory;
- this.servletRequestHelper = servletRequestHelper;
- this.systemPropertyHelper = systemPropertyHelper;
- this.loggingService = loggingService;
- if (client != null && client.isPresent()){
- this.client = client.get();
- }
-
- }
-
- /**
- * Encode URL.
- *
- * @param nodeKey the node key
- * @return the string
- * @throws UnsupportedEncodingException the unsupported encoding exception
- */
- public String encodeURL (String nodeKey) throws UnsupportedEncodingException {
- return URLEncoder.encode(nodeKey, "UTF-8").replaceAll("\\+", "%20");
- }
-
- protected void initRestClient() {
- initRestClient(false);
- }
-
-
- private void initRestClient(boolean propagateExceptions) {
- if (client == null) {
- try {
- client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE);
- } catch (Exception e) {
- logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient" + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : " + e.toString());
- if (propagateExceptions) {
- ExceptionUtils.rethrow(e);
- }
- }
- }
- }
-
-
-
- /**
- * Sets the rest srvr base URL.
- *
- * @param baseURL the base URL
- */
- public void setRestSrvrBaseURL(String baseURL)
- {
- if (baseURL == null) {
- logger.info(EELFLoggerDelegate.errorLogger, "REST Server base URL cannot be null.");
- logger.debug(EELFLoggerDelegate.debugLogger, "REST Server base URL cannot be null.");
- }
-
- restSrvrBaseURL = baseURL;
- }
-
- /**
- * Gets the rest srvr base URL.
- *
- * @return the rest srvr base URL
- */
- public String getRestSrvrBaseURL() {
- return restSrvrBaseURL;
- }
-
-
- /**
- * Rest get.
- *
- * @param fromAppId the from app id
- * @param transId the trans id
- * @param requestUri the request uri
- * @param xml the xml
- * @return the string
- */
- public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml) {
- return RestGet(fromAppId, transId, requestUri, xml, false);
- }
-
- public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml, boolean propagateExceptions) {
- return doRest(fromAppId, transId, requestUri, null, HttpMethod.GET, xml, propagateExceptions);
- }
-
- public ResponseWithRequestInfo doRest(String fromAppId, String transId, URI requestUri, String payload, HttpMethod method, boolean xml, boolean propagateExceptions) {
- String url = null;
- String methodName = "Rest"+method.name();
- try {
-
- url = systemPropertyHelper.getFullServicePath(requestUri);
-
- initRestClient(propagateExceptions);
-
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING);
- logger.debug(EELFLoggerDelegate.debugLogger, url + " for the get REST API");
-
- loggingService.logRequest(outgoingRequestsLogger, method, url, payload);
-
- final Response response;
- Invocation.Builder requestBuilder = client.target(url)
- .request()
- .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON)
- .header(TRANSACTION_ID_HEADER, transId)
- .header(FROM_APP_ID_HEADER, fromAppId)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId());
-
- requestBuilder = systemPropertyHelper.isClientCertEnabled() ?
- requestBuilder : authenticateRequest(requestBuilder);
-
- Invocation restInvocation = StringUtils.isEmpty(payload) ?
- requestBuilder.build(method.name()) :
- requestBuilder.build(method.name(), Entity.entity(payload, MediaType.APPLICATION_JSON));
-
- response = restInvocation.invoke();
- loggingService.logResponse(outgoingRequestsLogger, method, url, response);
-
- if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + SUCCESSFUL_API_MESSAGE);
- logger.info(EELFLoggerDelegate.errorLogger, methodName + SUCCESSFUL_API_MESSAGE);
- } else {
- logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response));
- }
- return new ResponseWithRequestInfo(response, url, method);
- } catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
- if (propagateExceptions) {
- throw new ExceptionWithRequestInfo(method, defaultIfNull(url, requestUri.toASCIIString()), e);
- } else {
- return new ResponseWithRequestInfo(null, url, method);
- }
- }
- }
-
- protected String extractOrGenerateRequestId() {
- return servletRequestHelper.extractOrGenerateRequestId();
- }
-
-
- /**
- * Delete.
- *
- * @param sourceID the source ID
- * @param transId the trans id
- * @param path the path
- * @return true, if successful
- */
- public boolean Delete(String sourceID, String transId, String path) {
- String methodName = "Delete";
- transId += ":" + UUID.randomUUID().toString();
- logger.debug(methodName + START_STRING);
- Boolean response = false;
- String url = systemPropertyHelper.getFullServicePath(path);
- try {
-
- initRestClient();
- loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url);
- final Response cres = client.target(url)
- .request()
- .accept(MediaType.APPLICATION_JSON)
- .header(TRANSACTION_ID_HEADER, transId)
- .header(FROM_APP_ID_HEADER, sourceID)
- .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
- .delete();
- loggingService.logResponse(outgoingRequestsLogger, HttpMethod.DELETE, url, cres);
- if (cres.getStatusInfo().equals(Response.Status.NOT_FOUND)) {
- logger.debug(EELFLoggerDelegate.debugLogger, "Resource does not exist...: " + cres.getStatus()
- + ":" + cres.readEntity(String.class));
- response = false;
- } else if (cres.getStatusInfo().equals(Response.Status.OK) || cres.getStatusInfo().equals(Response.Status.NO_CONTENT)) {
- logger.debug(EELFLoggerDelegate.debugLogger, "Resource " + url + " deleted");
- logger.info(EELFLoggerDelegate.errorLogger, "Resource " + url + " deleted");
- response = true;
- } else {
- logger.debug(EELFLoggerDelegate.debugLogger, "Deleting Resource failed: " + cres.getStatus()
- + ":" + cres.readEntity(String.class));
- response = false;
- }
-
- } catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
- }
- return response;
- }
-
-
- /**
- * Rest put.
- *
- * @param fromAppId the from app id
- * @param path the path
- * @param payload the payload
- * @param xml the xml
- * @param propagateExceptions
- * @return the string
- */
- public ResponseWithRequestInfo RestPut(String fromAppId, String path, String payload, boolean xml, boolean propagateExceptions) {
- return doRest(fromAppId, UUID.randomUUID().toString(), Unchecked.toURI(path), payload, HttpMethod.PUT, xml, propagateExceptions);
- }
-
-
-
- /**
- * Rest post.
- *
- * @param fromAppId the from app id
- * @param path the path
- * @param payload the payload
- * @param xml the xml
- * @return the string
- */
- public Response RestPost(String fromAppId, String path, String payload, boolean xml) {
- String methodName = "RestPost";
- String url=systemPropertyHelper.getServiceBasePath(path);
- String transId = UUID.randomUUID().toString();
- logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING);
-
- Response response = null;
- try {
- initRestClient();
- loggingService.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload);
- response = authenticateRequest(client.target(url)
- .request()
- .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON)
- .header(TRANSACTION_ID_HEADER, transId)
- .header(FROM_APP_ID_HEADER, fromAppId))
- .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
- .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
- loggingService.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, response);
-
- if (response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
- logger.info(EELFLoggerDelegate.errorLogger, getValidResponseLogMessage(methodName));
- logger.debug(EELFLoggerDelegate.debugLogger, getValidResponseLogMessage(methodName));
- } else {
- logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response));
- }
- } catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
- }
- return response;
- }
-
- protected String getFailedResponseLogMessage(String path, String methodName, Exception e) {
- return methodName + URL_DECLARATION + path + ", Exception: " + e.toString();
- }
-
- protected String getValidResponseLogMessage(String methodName) {
- return methodName + URL_DECLARATION;
- }
-
- protected String getInvalidResponseLogMessage(String path, String methodName, Response cres) {
- return methodName + " with status=" + cres.getStatus() + URL_DECLARATION + path;
- }
-
- private Invocation.Builder authenticateRequest(Invocation.Builder requestBuilder) throws InvalidPropertyException, UnsupportedEncodingException {
- return requestBuilder
- .header("Authorization", "Basic " + systemPropertyHelper.getEncodedCredentials());
- }
+ /** The logger. */
+ protected EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AAIRestInterface.class);
+
+ protected final EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("aai");
+
+ /** The client. */
+ private Client client = null;
+
+ /** The rest srvr base URL. */
+ private String restSrvrBaseURL;
+
+ @Autowired
+ protected HttpsAuthClient httpsAuthClientFactory;
+ private final ServletRequestHelper servletRequestHelper;
+ private final SystemPropertyHelper systemPropertyHelper;
+ protected final Logging loggingService;
+
+ protected static final String START_STRING = " start";
+ protected static final String TRANSACTION_ID_HEADER = "X-TransactionId";
+ protected static final String FROM_APP_ID_HEADER = "X-FromAppId";
+ protected static final String SUCCESSFUL_API_MESSAGE = " REST api call was successful!";
+ protected static final String URL_DECLARATION = ", url=";
+
+ public AAIRestInterface(HttpsAuthClient httpsAuthClientFactory,
+ ServletRequestHelper servletRequestHelper,
+ SystemPropertyHelper systemPropertyHelper,
+ Logging loggingService) {
+ this.httpsAuthClientFactory = httpsAuthClientFactory;
+ this.servletRequestHelper = servletRequestHelper;
+ this.systemPropertyHelper = systemPropertyHelper;
+ this.loggingService = loggingService;
+ initRestClient();
+ }
+
+ /**
+ * For testing purpose
+ */
+ AAIRestInterface(Optional<Client> client,
+ HttpsAuthClient httpsAuthClientFactory,
+ ServletRequestHelper servletRequestHelper,
+ SystemPropertyHelper systemPropertyHelper,
+ Logging loggingService){
+ this.httpsAuthClientFactory = httpsAuthClientFactory;
+ this.servletRequestHelper = servletRequestHelper;
+ this.systemPropertyHelper = systemPropertyHelper;
+ this.loggingService = loggingService;
+ if (client != null && client.isPresent()){
+ this.client = client.get();
+ }
+
+ }
+
+ /**
+ * Encode URL.
+ *
+ * @param nodeKey the node key
+ * @return the string
+ * @throws UnsupportedEncodingException the unsupported encoding exception
+ */
+ public String encodeURL (String nodeKey) throws UnsupportedEncodingException {
+ return URLEncoder.encode(nodeKey, "UTF-8").replaceAll("\\+", "%20");
+ }
+
+ protected void initRestClient() {
+ initRestClient(false);
+ }
+
+
+ private void initRestClient(boolean propagateExceptions) {
+ if (client == null) {
+ try {
+ client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE);
+ } catch (Exception e) {
+ logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient" + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, "Exception in REST call to DB : " + e.toString());
+ if (propagateExceptions) {
+ ExceptionUtils.rethrow(e);
+ }
+ }
+ }
+ }
+
+
+
+ /**
+ * Sets the rest srvr base URL.
+ *
+ * @param baseURL the base URL
+ */
+ public void setRestSrvrBaseURL(String baseURL)
+ {
+ if (baseURL == null) {
+ logger.info(EELFLoggerDelegate.errorLogger, "REST Server base URL cannot be null.");
+ logger.debug(EELFLoggerDelegate.debugLogger, "REST Server base URL cannot be null.");
+ }
+
+ restSrvrBaseURL = baseURL;
+ }
+
+ /**
+ * Gets the rest srvr base URL.
+ *
+ * @return the rest srvr base URL
+ */
+ public String getRestSrvrBaseURL() {
+ return restSrvrBaseURL;
+ }
+
+
+ /**
+ * Rest get.
+ *
+ * @param fromAppId the from app id
+ * @param transId the trans id
+ * @param requestUri the request uri
+ * @param xml the xml
+ * @return the string
+ */
+ public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml) {
+ return RestGet(fromAppId, transId, requestUri, xml, false);
+ }
+
+ public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml, boolean propagateExceptions) {
+ return doRest(fromAppId, transId, requestUri, null, HttpMethod.GET, xml, propagateExceptions);
+ }
+
+ public ResponseWithRequestInfo doRest(String fromAppId, String transId, URI requestUri, String payload, HttpMethod method, boolean xml, boolean propagateExceptions) {
+ String url = null;
+ String methodName = "Rest"+method.name();
+ try {
+
+ url = systemPropertyHelper.getFullServicePath(requestUri);
+
+ initRestClient(propagateExceptions);
+
+ logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING);
+ logger.debug(EELFLoggerDelegate.debugLogger, url + " for the get REST API");
+
+ loggingService.logRequest(outgoingRequestsLogger, method, url, payload);
+
+ final Response response;
+ Invocation.Builder requestBuilder = client.target(url)
+ .request()
+ .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON)
+ .header(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue())
+ .header(TRANSACTION_ID_HEADER, transId)
+ .header(FROM_APP_ID_HEADER, fromAppId)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId());
+
+ requestBuilder = systemPropertyHelper.isClientCertEnabled() ?
+ requestBuilder : authenticateRequest(requestBuilder);
+
+ Invocation restInvocation = StringUtils.isEmpty(payload) ?
+ requestBuilder.build(method.name()) :
+ requestBuilder.build(method.name(), Entity.entity(payload, MediaType.APPLICATION_JSON));
+
+ response = restInvocation.invoke();
+ loggingService.logResponse(outgoingRequestsLogger, method, url, response);
+
+ if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
+ logger.debug(EELFLoggerDelegate.debugLogger, methodName + SUCCESSFUL_API_MESSAGE);
+ logger.info(EELFLoggerDelegate.errorLogger, methodName + SUCCESSFUL_API_MESSAGE);
+ } else {
+ logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response));
+ }
+ return new ResponseWithRequestInfo(response, url, method);
+ } catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
+ if (propagateExceptions) {
+ throw new ExceptionWithRequestInfo(method, defaultIfNull(url, requestUri.toASCIIString()), e);
+ } else {
+ return new ResponseWithRequestInfo(null, url, method);
+ }
+ }
+ }
+
+ protected String extractOrGenerateRequestId() {
+ return servletRequestHelper.extractOrGenerateRequestId();
+ }
+
+
+ /**
+ * Delete.
+ *
+ * @param sourceID the source ID
+ * @param transId the trans id
+ * @param path the path
+ * @return true, if successful
+ */
+ public boolean Delete(String sourceID, String transId, String path) {
+ String methodName = "Delete";
+ transId += ":" + UUID.randomUUID().toString();
+ logger.debug(methodName + START_STRING);
+ Boolean response = false;
+ String url = systemPropertyHelper.getFullServicePath(path);
+ try {
+
+ initRestClient();
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url);
+ final Response cres = client.target(url)
+ .request()
+ .accept(MediaType.APPLICATION_JSON)
+ .header(TRANSACTION_ID_HEADER, transId)
+ .header(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue())
+ .header(FROM_APP_ID_HEADER, sourceID)
+ .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
+ .delete();
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.DELETE, url, cres);
+ if (cres.getStatusInfo().equals(Response.Status.NOT_FOUND)) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Resource does not exist...: " + cres.getStatus()
+ + ":" + cres.readEntity(String.class));
+ response = false;
+ } else if (cres.getStatusInfo().equals(Response.Status.OK) || cres.getStatusInfo().equals(Response.Status.NO_CONTENT)) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Resource " + url + " deleted");
+ logger.info(EELFLoggerDelegate.errorLogger, "Resource " + url + " deleted");
+ response = true;
+ } else {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Deleting Resource failed: " + cres.getStatus()
+ + ":" + cres.readEntity(String.class));
+ response = false;
+ }
+
+ } catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
+ }
+ return response;
+ }
+
+
+ /**
+ * Rest put.
+ *
+ * @param fromAppId the from app id
+ * @param path the path
+ * @param payload the payload
+ * @param xml the xml
+ * @param propagateExceptions
+ * @return the string
+ */
+ public ResponseWithRequestInfo RestPut(String fromAppId, String path, String payload, boolean xml, boolean propagateExceptions) {
+ return doRest(fromAppId, UUID.randomUUID().toString(), Unchecked.toURI(path), payload, HttpMethod.PUT, xml, propagateExceptions);
+ }
+
+
+
+ /**
+ * Rest post.
+ *
+ * @param fromAppId the from app id
+ * @param path the path
+ * @param payload the payload
+ * @param xml the xml
+ * @return the string
+ */
+ public Response RestPost(String fromAppId, String path, String payload, boolean xml) {
+ String methodName = "RestPost";
+ String url=systemPropertyHelper.getServiceBasePath(path);
+ String transId = UUID.randomUUID().toString();
+ logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING);
+
+ Response response = null;
+ try {
+ initRestClient();
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload);
+ response = authenticateRequest(client.target(url)
+ .request()
+ .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON)
+ .header(TRANSACTION_ID_HEADER, transId)
+ .header(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue())
+ .header(FROM_APP_ID_HEADER, fromAppId))
+ .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
+ .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, response);
+
+ if (response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) {
+ logger.info(EELFLoggerDelegate.errorLogger, getValidResponseLogMessage(methodName));
+ logger.debug(EELFLoggerDelegate.debugLogger, getValidResponseLogMessage(methodName));
+ } else {
+ logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response));
+ }
+ } catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e));
+ }
+ return response;
+ }
+
+ protected String getFailedResponseLogMessage(String path, String methodName, Exception e) {
+ return methodName + URL_DECLARATION + path + ", Exception: " + e.toString();
+ }
+
+ protected String getValidResponseLogMessage(String methodName) {
+ return methodName + URL_DECLARATION;
+ }
+
+ protected String getInvalidResponseLogMessage(String path, String methodName, Response cres) {
+ return methodName + " with status=" + cres.getStatus() + URL_DECLARATION + path;
+ }
+
+ private Invocation.Builder authenticateRequest(Invocation.Builder requestBuilder) throws InvalidPropertyException, UnsupportedEncodingException {
+ return requestBuilder
+ .header("Authorization", "Basic " + systemPropertyHelper.getEncodedCredentials());
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt b/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt
index a0bbceea1..b2969feb2 100644
--- a/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/Headers.kt
@@ -6,16 +6,27 @@ import org.onap.portalsdk.core.util.SystemProperties
import org.onap.vid.logging.RequestIdHeader.*
import javax.servlet.http.HttpServletRequest
-enum class RequestIdHeader(val headerName: String) {
+interface Header {
+ val headerName: String
+ fun stringEquals(header: String): Boolean = headerName.equals(header, true)
+}
+
+abstract class NamedHeader(override val headerName: String) : Header {
+ abstract fun getHeaderValue(): String
+}
+@JvmField
+val PARTNER_NAME = object : NamedHeader("X-ONAP-PartnerName") {
+ override fun getHeaderValue() = "VID.VID"
+}
+
+enum class RequestIdHeader(override val headerName: String) : Header {
ONAP_ID("X-ONAP-RequestID"),
REQUEST_ID("X-RequestID"),
TRANSACTION_ID("X-TransactionID"),
ECOMP_ID(SystemProperties.ECOMP_REQUEST_ID),
;
- fun stringEquals(header: String) = headerName.equals(header, true)
-
fun getHeaderValue(request: HttpServletRequest): String? = request.getHeader(headerName)
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java
index 3d980dce8..8f9b98a55 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java
@@ -30,6 +30,7 @@ import static org.onap.vid.controller.MsoController.REQUEST_TYPE;
import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
import static org.onap.vid.controller.MsoController.WORKFLOW_ID;
+import static org.onap.vid.logging.Headers.PARTNER_NAME;
import static org.onap.vid.mso.MsoProperties.MSO_REST_API_CLOUD_RESOURCES_REQUEST_STATUS;
import static org.onap.vid.mso.MsoProperties.MSO_REST_API_OPERATIONAL_ENVIRONMENT_ACTIVATE;
import static org.onap.vid.mso.MsoProperties.MSO_REST_API_OPERATIONAL_ENVIRONMENT_CREATE;
@@ -230,7 +231,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic {
UUID requestId = UUID.randomUUID();
extraHeaders.put("X-ONAP-RequestID",requestId.toString());
- extraHeaders.put("X-ONAP-PartnerName","VID");
+ extraHeaders.put(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue());
extraHeaders.put("X-RequestorID",userId);
return msoClientInterface.invokeWorkflow(request,final_endpoint,extraHeaders);
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java
index b07fe05a1..9c8902d00 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java
@@ -20,6 +20,7 @@
package org.onap.vid.mso;
+import static org.onap.vid.logging.Headers.PARTNER_NAME;
import static org.onap.vid.utils.Logging.ONAP_REQUEST_ID_HEADER_KEY;
import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
import static org.onap.vid.utils.Logging.getMethodCallerName;
@@ -109,7 +110,7 @@ public class RestMsoImplementation implements RestInterface {
MultivaluedHashMap<String, Object> commonHeaders = new MultivaluedHashMap();
commonHeaders.put("Authorization", Collections.singletonList(("Basic " + authStringEnc)));
- commonHeaders.put("X-ONAP-PartnerName", Collections.singletonList("VID"));
+ commonHeaders.put(PARTNER_NAME.getHeaderName(), Collections.singletonList(PARTNER_NAME.getHeaderValue()));
String requestIdValue = Logging.extractOrGenerateRequestId();
commonHeaders.put(REQUEST_ID_HEADER_KEY, Collections.singletonList(requestIdValue));
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java
index b2ccde93b..1d6dae99a 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java
@@ -20,6 +20,7 @@
*/
package org.onap.vid.mso.rest;
+import static org.onap.vid.logging.Headers.PARTNER_NAME;
import static org.onap.vid.utils.Logging.ONAP_REQUEST_ID_HEADER_KEY;
import com.google.common.collect.ImmutableMap;
@@ -66,7 +67,6 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf
* The Constant dateFormat.
*/
public static final String X_FROM_APP_ID = "X-FromAppId";
- public static final String X_ONAP_PARTNER_NAME = "X-ONAP-PartnerName";
final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
private static final String START = " start";
private final SyncRestClient client;
@@ -563,7 +563,7 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf
map.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
map.put(X_FROM_APP_ID, systemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME));
- map.put(X_ONAP_PARTNER_NAME, "VID");
+ map.put(PARTNER_NAME.getHeaderName(), PARTNER_NAME.getHeaderValue());
return ImmutableMap.copyOf(map);
}