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;
10 public class AuditLogFilter extends AuditLogServletFilter {
11 private static final String MDC_HTTP_METHOD_KEY = "HttpMethod";
14 protected void additionalPreHandling(HttpServletRequest httpServletRequest) {
15 // Don't overwrite service instance id if it was set outside of this automated method
16 if (MDC.get(ONAPLogConstants.MDCs.SERVICE_INSTANCE_ID) == null) {
17 String serviceInstanceId = getServiceInstanceId(httpServletRequest.getRequestURI());
18 if (serviceInstanceId != null) {
19 MDC.put(ONAPLogConstants.MDCs.SERVICE_INSTANCE_ID, serviceInstanceId);
22 MDC.put(MDC_HTTP_METHOD_KEY, httpServletRequest.getMethod());
25 // restconf URLs follow a pattern, this method attempts to extract the service instance id according to that pattern
26 protected String getServiceInstanceId(String path) {
27 int idx = path.indexOf("service-list");
29 // chomp off service-list/
30 String str = path.substring(idx + 13);
31 idx = str.indexOf("/");
32 //if there is another forward slash with more information chomp it off
34 return str.substring(0, idx);