aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java21
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java5
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java84
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java3
5 files changed, 88 insertions, 29 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java
index f511a4746..6fe295c15 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java
@@ -3,6 +3,7 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 IBM.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +28,8 @@ import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class RelationshipList {
+ public List<Relationship> relationship;
+
@JsonProperty("relationship")
public List<Relationship> getRelationship() {
return relationship;
@@ -37,7 +40,6 @@ public class RelationshipList {
this.relationship = relationship;
}
- public List<Relationship> relationship;
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
index eee2acc51..2b3ad60ea 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
@@ -77,6 +77,7 @@ public class AaiController extends RestrictedBaseController {
private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AaiController.class);
private static final String FROM_APP_ID = "VidAaiController";
+ private final ObjectMapper objectMapper = new ObjectMapper();
private AaiService aaiService;
private AAIRestInterface aaiRestInterface;
@@ -157,7 +158,7 @@ public class AaiController extends RestrictedBaseController {
throws IOException {
ResponseEntity<String> responseEntity;
if (aaiResponseData.getHttpCode() == 200) {
- responseEntity = new ResponseEntity<>(new ObjectMapper().writeValueAsString(aaiResponseData.getT()),
+ responseEntity = new ResponseEntity<>(objectMapper.writeValueAsString(aaiResponseData.getT()),
HttpStatus.OK);
} else {
responseEntity = new ResponseEntity<>(aaiResponseData.getErrorMessage(),
@@ -225,7 +226,6 @@ public class AaiController extends RestrictedBaseController {
@RequestMapping(value = "/aai_get_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getFullSubscriberList(HttpServletRequest request) throws IOException {
- ObjectMapper objectMapper = new ObjectMapper();
ResponseEntity<String> responseEntity;
RoleValidator roleValidator = RoleValidator.by(roleProvider.getUserRoles(request));
SubscriberFilteredResults subscriberList = aaiService.getFullSubscriberList(roleValidator);
@@ -270,17 +270,14 @@ public class AaiController extends RestrictedBaseController {
@RequestMapping(value = "/aai_sub_details/{subscriberId}", method = RequestMethod.GET)
public ResponseEntity<String> getSubscriberDetails(HttpServletRequest request, @PathVariable("subscriberId") String subscriberId,
@RequestParam(value="omitServiceInstances", required = false, defaultValue = "false") boolean omitServiceInstances) throws IOException {
- ObjectMapper objectMapper = new ObjectMapper();
- ResponseEntity responseEntity;
List<Role> roles = roleProvider.getUserRoles(request);
RoleValidator roleValidator = RoleValidator.by(roles);
- AaiResponse subscriberData = aaiService.getSubscriberData(subscriberId, roleValidator, featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH) && omitServiceInstances);
- String httpMessage = subscriberData.getT() != null ?
- objectMapper.writeValueAsString(subscriberData.getT()) :
- subscriberData.getErrorMessage();
+ AaiResponse subscriberData = aaiService.getSubscriberData(subscriberId, roleValidator,
+ featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH) && omitServiceInstances);
+ String httpMessage = subscriberData.getT() != null ? objectMapper.writeValueAsString(subscriberData.getT()) : subscriberData.getErrorMessage();
- responseEntity = new ResponseEntity<>(httpMessage, HttpStatus.valueOf(subscriberData.getHttpCode()));
- return responseEntity;
+ return new ResponseEntity<>(httpMessage,
+ HttpStatus.valueOf(subscriberData.getHttpCode()));
}
@RequestMapping(value = "/search_service_instances", method = RequestMethod.GET)
@@ -289,7 +286,6 @@ public class AaiController extends RestrictedBaseController {
@RequestParam(value = "serviceInstanceIdentifier", required = false) String instanceIdentifier,
@RequestParam(value = "project", required = false) List<String> projects,
@RequestParam(value = "owningEntity", required = false) List<String> owningEntities) throws IOException {
- ObjectMapper objectMapper = new ObjectMapper();
ResponseEntity responseEntity;
List<Role> roles = roleProvider.getUserRoles(request);
@@ -354,7 +350,6 @@ public class AaiController extends RestrictedBaseController {
@RequestMapping(value = "/aai_get_network_collection_details/{serviceInstanceId}", method = RequestMethod.GET)
public ResponseEntity<String> getNetworkCollectionDetails(
@PathVariable("serviceInstanceId") String serviceInstanceId) throws IOException {
- com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
AaiResponse<String> resp = aaiService.getNetworkCollectionDetails(serviceInstanceId);
String httpMessage = resp.getT() != null ?
@@ -367,7 +362,6 @@ public class AaiController extends RestrictedBaseController {
public ResponseEntity<String> getInstanceGroupsByCloudRegion(@PathVariable("cloudOwner") String cloudOwner,
@PathVariable("cloudRegionId") String cloudRegionId,
@PathVariable("networkFunction") String networkFunction) throws IOException {
- com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
AaiResponse<AaiGetInstanceGroupsByCloudRegion> resp = aaiService
.getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction);
@@ -424,7 +418,6 @@ public class AaiController extends RestrictedBaseController {
ResponseEntity responseEntity;
try {
- ObjectMapper objectMapper = new ObjectMapper();
List<Role> roles = roleProvider.getUserRoles(request);
RoleValidator roleValidator = RoleValidator.by(roles);
AaiResponse<GetTenantsResponse[]> response = aaiService
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java b/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java
index befbe0320..693c84bff 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nokia. All rights reserved.
+ * Modifications Copyright (C) 2019 IBM.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,9 +46,7 @@ public final class ControllersUtils {
public static ExceptionResponse handleException(Exception e, EELFLoggerDelegate logger) {
logger.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodCallerName(), ExceptionUtils.getMessage(e), e);
-
- ExceptionResponse exceptionResponse = new ExceptionResponse(e);
- return exceptionResponse;
+ return new ExceptionResponse(e);
}
public static ResponseEntity handleWebApplicationException(WebApplicationException e, EELFLoggerDelegate logger) {
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java
index 514779f49..309ead40c 100644
--- a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java
@@ -20,6 +20,13 @@
package org.onap.vid.logging;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
+import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@@ -27,13 +34,14 @@ import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.service.AppService;
import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.onap.vid.controller.ControllersUtils;
+import org.onap.vid.utils.SystemPropertiesWrapper;
import org.springframework.beans.factory.annotation.Autowired;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
@Aspect
@@ -41,10 +49,14 @@ import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
public class VidLoggerAspect {
private String canonicalHostName;
- @Autowired
- EELFLoggerAdvice advice;
+ private final ControllersUtils controllersUtils;
+ private final String appName;
+
+ private final EELFLoggerAdvice advice;
- public VidLoggerAspect() {
+ @Autowired
+ public VidLoggerAspect(EELFLoggerAdvice advice, SystemPropertiesWrapper systemPropertiesWrapper,
+ AppService appService) {
try {
final InetAddress localHost = InetAddress.getLocalHost();
canonicalHostName = localHost.getCanonicalHostName();
@@ -52,9 +64,13 @@ public class VidLoggerAspect {
// YOLO
canonicalHostName = null;
}
+ this.advice = advice;
+ this.controllersUtils = new ControllersUtils(systemPropertiesWrapper);
+
+ this.appName = defaultIfEmpty(appService.getDefaultAppName(), SystemProperties.SDK_NAME);
}
- @Pointcut("execution(public * org.onap.vid.controller.*Controller.*(..))")
+ @Pointcut("execution(public * org.onap.vid.controller..*Controller.*(..))")
public void vidControllers() {}
@Around("vidControllers() && (" +
@@ -69,7 +85,10 @@ public class VidLoggerAspect {
private Object logAroundMethod(ProceedingJoinPoint joinPoint, SystemProperties.SecurityEventTypeEnum securityEventType) throws Throwable {
//Before
Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(),joinPoint.getSignature().getName()};
- Object[] returnArgs = advice.before(securityEventType, joinPoint.getArgs(), passOnArgs);
+ Object[] returnArgs = advice.before(securityEventType, fabricateArgsWithNull(), passOnArgs);
+
+ fixSetRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequestOrNull(joinPoint),
+ joinPoint.getSignature().getDeclaringType().getName());
fixServerFqdnInMDC();
@@ -94,6 +113,51 @@ public class VidLoggerAspect {
EELFLoggerDelegate.mdcPut(SystemProperties.STATUS_CODE, restStatus);
}
+ /**
+ * Returns an array with a single entry with a null value. This will stop org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice.before
+ * from throwing on ArrayIndexOutOfBound, and also prevent SessionExpiredException.
+ */
+ private Object[] fabricateArgsWithNull() {
+ return new Object[]{null};
+ }
+
+ /**
+ * Finds the first joinPoint's param which is an HttpServletRequest. If not found, use Spring's RequestContextHolder
+ * to retrieve it.
+ *
+ * @return null or the current httpServletRequest
+ */
+ private HttpServletRequest httpServletRequestOrNull(ProceedingJoinPoint joinPoint) {
+ final Object httpServletRequest = Arrays.stream(joinPoint.getArgs())
+ .filter(param -> param instanceof HttpServletRequest)
+ .findFirst()
+ .orElseGet(() -> {
+ try {
+ return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
+ } catch (Exception e) { // ClassCast, IllegalState, etc.
+ return null;
+ }
+ });
+
+ return (HttpServletRequest) httpServletRequest;
+ }
+
+ /**
+ * Mimics a part from org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice.before, but with much more carefulness
+ * of exceptions and defaults. Main difference is that if no session, function does not throw. It just fallback to
+ * an empty loginId.
+ */
+ private void fixSetRequestBasedDefaultsIntoGlobalLoggingContext(HttpServletRequest httpServletRequest, String className) {
+ if (httpServletRequest != null) {
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className);
+ String requestId = UserUtils.getRequestId(httpServletRequest);
+ String loginId = controllersUtils.extractUserId(httpServletRequest);
+
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequest, appName, requestId, loginId);
+ }
+ }
+
// Override the non-canonical hostname set by EELFLoggerDelegate::setGlobalLoggingContext()
// that was invoked by advice.before() (and some other SDK cases)
private void fixServerFqdnInMDC() {
diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java
index 7878c2fb8..001a8ae6d 100644
--- a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java
@@ -98,12 +98,13 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc {
status = response.getStatus();
restObject.setStatusCode(status);
rawData = response.getBody();
+ restObject.setRaw(rawData);
if (status == 200) {
if (t instanceof String) {
restObject.set((T)rawData);
}
else {
- restObject.set(JACKSON_OBJECT_MAPPER.readValue(rawData, new TypeReference<T>() {}));
+ restObject.set(JACKSON_OBJECT_MAPPER.readValue(rawData, (Class<T>)t.getClass()));
}
logger.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + SUCCESSFUL_API_MESSAGE);
logger.info(EELFLoggerDelegate.errorLogger, "<== " + methodName + SUCCESSFUL_API_MESSAGE);