diff options
author | 2020-12-01 11:48:20 -0800 | |
---|---|---|
committer | 2020-12-01 11:48:20 -0800 | |
commit | 32fb53c13342d5ad353c839b7ffd0ca85d14bd48 (patch) | |
tree | f1b92068cf7b79d29e96243899e12495abb4795a /core/filters/provider/src/main | |
parent | 53eacd8519a535f96d8b4231e48925324f1086dd (diff) |
Migrate sli-core files
Migrate sli-core repo files into new
directory "core".
Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Diffstat (limited to 'core/filters/provider/src/main')
2 files changed, 47 insertions, 0 deletions
diff --git a/core/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilter.java b/core/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilter.java new file mode 100644 index 000000000..7805e365d --- /dev/null +++ b/core/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerAuditLogFilter.java @@ -0,0 +1,40 @@ +package org.onap.ccsdk.sli.core.filters; + +import javax.servlet.http.HttpServletRequest; +import org.onap.logging.filter.base.AuditLogServletFilter; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.slf4j.MDC; + +public class ControllerAuditLogFilter extends AuditLogServletFilter { + private static final String MDC_HTTP_METHOD_KEY = "HttpMethod"; + + @Override + protected void additionalPreHandling(HttpServletRequest httpServletRequest) { + // Don't overwrite service instance id if it was set outside of this automated method + if (MDC.get(ONAPLogConstants.MDCs.SERVICE_INSTANCE_ID) == null) { + String serviceInstanceId = getServiceInstanceId(httpServletRequest.getPathInfo()); + if (serviceInstanceId != null) { + MDC.put(ONAPLogConstants.MDCs.SERVICE_INSTANCE_ID, serviceInstanceId); + } + } + MDC.put(MDC_HTTP_METHOD_KEY, httpServletRequest.getMethod()); + } + + // restconf URLs follow a pattern, this method attempts to extract the service instance id according to that pattern + protected String getServiceInstanceId(String path) { + int idx = path.indexOf("service-list"); + if (idx != -1) { + // chomp off service-list/ + String str = path.substring(idx + 13); + idx = str.indexOf("/"); + //if there is another forward slash with more information chomp it off + if (idx != -1) { + return str.substring(0, idx); + } else { + return str; + } + } + return null; + } + +} diff --git a/core/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerPayloadLoggingFilter.java b/core/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerPayloadLoggingFilter.java new file mode 100644 index 000000000..3f9f93fc5 --- /dev/null +++ b/core/filters/provider/src/main/java/org/onap/ccsdk/sli/core/filters/ControllerPayloadLoggingFilter.java @@ -0,0 +1,7 @@ +package org.onap.ccsdk.sli.core.filters; + +import org.onap.logging.filter.base.PayloadLoggingServletFilter; + +public class ControllerPayloadLoggingFilter extends PayloadLoggingServletFilter { + +} |