Update the license for 2017-2018 license
[aai/traversal.git] / aai-traversal / src / main / java / org / onap / aai / interceptors / post / ResetLoggingContext.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.interceptors.post;
21
22 import java.io.IOException;
23
24 import javax.annotation.Priority;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.ws.rs.container.ContainerRequestContext;
27 import javax.ws.rs.container.ContainerResponseContext;
28 import javax.ws.rs.container.ContainerResponseFilter;
29
30 import org.onap.aai.interceptors.AAIContainerFilter;
31 import org.onap.aai.logging.LoggingContext;
32 import org.onap.aai.logging.LoggingContext.StatusCode;
33 import org.springframework.beans.factory.annotation.Autowired;
34
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
37
38 @Priority(AAIResponseFilterPriority.RESET_LOGGING_CONTEXT)
39 public class ResetLoggingContext extends AAIContainerFilter implements ContainerResponseFilter {
40
41         private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ResetLoggingContext.class);
42
43         @Autowired
44         private HttpServletRequest httpServletRequest;
45         
46         @Override
47         public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
48                         throws IOException {
49
50                 this.cleanLoggingContext();
51
52         }
53
54         private void cleanLoggingContext() {
55                 final String responseCode = LoggingContext.responseCode();
56                 String url = httpServletRequest.getRequestURL().toString();
57
58                 if (responseCode != null && responseCode.startsWith("ERR.")) {
59                         LoggingContext.statusCode(StatusCode.ERROR);
60                         LOGGER.error(url + " call failed with responseCode=" + responseCode);
61                 } else {
62                         LoggingContext.statusCode(StatusCode.COMPLETE);
63                         LOGGER.info(url + " call succeeded");
64                 }
65
66                 LoggingContext.clear();
67         }
68
69 }