1 package org.onap.ccsdk.apps.filters
4 import javax.servlet.http.HttpServletRequest;
5 import org.onap.logging.filter.base.AuditLogServletFilter;
6 import org.onap.logging.ref.slf4j.ONAPLogConstants;
8 import org.springframework.stereotype.Component;
11 public class AuditLogFilter extends AuditLogServletFilter {
12 private static final String MDC_HTTP_METHOD_KEY = "HttpMethod";
15 protected void additionalPreHandling(HttpServletRequest httpServletRequest) {
16 // Don't overwrite service instance id if it was set outside of this automated method
17 if (MDC.get(ONAPLogConstants.MDCs.SERVICE_INSTANCE_ID) == null) {
18 String serviceInstanceId = getServiceInstanceId(httpServletRequest.getRequestURI());
19 if (serviceInstanceId != null) {
20 MDC.put(ONAPLogConstants.MDCs.SERVICE_INSTANCE_ID, serviceInstanceId);
23 MDC.put(MDC_HTTP_METHOD_KEY, httpServletRequest.getMethod());
26 // restconf URLs follow a pattern, this method attempts to extract the service instance id according to that pattern
27 protected String getServiceInstanceId(String path) {
28 int idx = path.indexOf("service-list");
30 // chomp off service-list/
31 String str = path.substring(idx + 13);
32 idx = str.indexOf("/");
33 //if there is another forward slash with more information chomp it off
35 return str.substring(0, idx);