2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.interceptors.post;
22 import java.io.IOException;
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;
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;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
38 @Priority(AAIResponseFilterPriority.RESET_LOGGING_CONTEXT)
39 public class ResetLoggingContext extends AAIContainerFilter implements ContainerResponseFilter {
41 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ResetLoggingContext.class);
44 private HttpServletRequest httpServletRequest;
47 public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
50 this.cleanLoggingContext();
54 private void cleanLoggingContext() {
55 final String responseCode = LoggingContext.responseCode();
56 String url = httpServletRequest.getRequestURL().toString();
58 if (responseCode != null && responseCode.startsWith("ERR.")) {
59 LoggingContext.statusCode(StatusCode.ERROR);
60 LOGGER.error(url + " call failed with responseCode=" + responseCode);
62 LoggingContext.statusCode(StatusCode.COMPLETE);
63 LOGGER.info(url + " call succeeded");
66 LoggingContext.clear();