Update traversal from AJSC 2 to Spring Boot
[aai/traversal.git] / aai-traversal / src / main / java / org / onap / aai / interceptors / post / ResetLoggingContext.java
1 package org.onap.aai.interceptors.post;
2
3 import java.io.IOException;
4
5 import javax.annotation.Priority;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.ws.rs.container.ContainerRequestContext;
8 import javax.ws.rs.container.ContainerResponseContext;
9 import javax.ws.rs.container.ContainerResponseFilter;
10
11 import org.onap.aai.interceptors.AAIContainerFilter;
12 import org.onap.aai.logging.LoggingContext;
13 import org.onap.aai.logging.LoggingContext.StatusCode;
14 import org.springframework.beans.factory.annotation.Autowired;
15
16 import com.att.eelf.configuration.EELFLogger;
17 import com.att.eelf.configuration.EELFManager;
18
19 @Priority(AAIResponseFilterPriority.RESET_LOGGING_CONTEXT)
20 public class ResetLoggingContext extends AAIContainerFilter implements ContainerResponseFilter {
21
22         private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ResetLoggingContext.class);
23
24         @Autowired
25         private HttpServletRequest httpServletRequest;
26         
27         @Override
28         public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
29                         throws IOException {
30
31                 this.cleanLoggingContext();
32
33         }
34
35         private void cleanLoggingContext() {
36                 final String responseCode = LoggingContext.responseCode();
37                 String url = httpServletRequest.getRequestURL().toString();
38
39                 if (responseCode != null && responseCode.startsWith("ERR.")) {
40                         LoggingContext.statusCode(StatusCode.ERROR);
41                         LOGGER.error(url + " call failed with responseCode=" + responseCode);
42                 } else {
43                         LoggingContext.statusCode(StatusCode.COMPLETE);
44                         LOGGER.info(url + " call succeeded");
45                 }
46
47                 LoggingContext.clear();
48         }
49
50 }