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.schemaservice.interceptors.post;
22 import com.att.eelf.configuration.EELFLogger;
23 import com.att.eelf.configuration.EELFManager;
24 import org.onap.aai.logging.LoggingContext;
25 import org.onap.aai.logging.LoggingContext.StatusCode;
26 import org.onap.aai.schemaservice.interceptors.AAIContainerFilter;
27 import org.springframework.beans.factory.annotation.Autowired;
29 import javax.annotation.Priority;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.ws.rs.container.ContainerRequestContext;
32 import javax.ws.rs.container.ContainerResponseContext;
33 import javax.ws.rs.container.ContainerResponseFilter;
34 import javax.ws.rs.core.Response.Status;
35 import javax.ws.rs.core.Response.StatusType;
36 import java.io.IOException;
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(responseContext);
54 private void cleanLoggingContext(ContainerResponseContext responseContext) {
55 //String url = httpServletRequest.getRequestURL().toString();
56 boolean success = true;
57 String uri = httpServletRequest.getRequestURI();
58 String queryString = httpServletRequest.getQueryString();
60 if (queryString != null && !queryString.isEmpty()) {
61 uri = uri + "?" + queryString;
63 // For now, we use the the HTTP status code,
64 // This may change, once the requirements for response codes are defined
66 int httpStatusCode = responseContext.getStatus();
67 if (httpStatusCode < 100 || httpStatusCode > 599) {
68 httpStatusCode = Status.INTERNAL_SERVER_ERROR.getStatusCode();
70 LoggingContext.responseCode(Integer.toString(httpStatusCode));
72 StatusType sType = responseContext.getStatusInfo();
74 Status.Family sFamily = sType.getFamily();
75 if (!(Status.Family.SUCCESSFUL.equals(sFamily) ||
76 (Status.NOT_FOUND.equals(Status.fromStatusCode(httpStatusCode))))) {
80 if ((httpStatusCode < 200 || httpStatusCode > 299) && (!(Status.NOT_FOUND.equals(Status.fromStatusCode(httpStatusCode))))) {
85 LoggingContext.statusCode(StatusCode.COMPLETE);
86 LOGGER.info(uri + " call succeeded");
88 LoggingContext.statusCode(StatusCode.ERROR);
89 LOGGER.error(uri + " call failed with responseCode=" + httpStatusCode);
91 LoggingContext.clear();