2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.controllerblueprints.filters;
\r
19 import com.google.common.base.Preconditions;
\r
20 import org.apache.commons.lang3.StringUtils;
\r
21 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;
\r
22 import org.onap.logging.ref.slf4j.ONAPLogAdapter;
\r
23 import org.slf4j.Logger;
\r
24 import org.slf4j.LoggerFactory;
\r
25 import org.slf4j.MDC;
\r
26 import org.springframework.beans.factory.annotation.Value;
\r
27 import org.springframework.stereotype.Component;
\r
29 import javax.servlet.*;
\r
30 import javax.servlet.annotation.WebFilter;
\r
31 import javax.servlet.http.HttpServletRequest;
\r
32 import javax.servlet.http.HttpServletResponse;
\r
33 import java.io.IOException;
\r
36 * ApplicationLoggingFilter
\r
38 * @author Brinda Santh 8/14/2018
\r
41 @WebFilter(asyncSupported = true, urlPatterns = {"/*"})
\r
42 @SuppressWarnings("unused")
\r
43 public class ApplicationLoggingFilter implements Filter {
\r
44 private static Logger log = LoggerFactory.getLogger(ApplicationLoggingFilter.class);
\r
46 @SuppressWarnings("unused")
\r
47 @Value("${appVersion}")
\r
48 private String appVersion;
\r
50 public void doFilter(ServletRequest request,
\r
51 ServletResponse response,
\r
52 FilterChain chain) throws IOException, ServletException {
\r
54 HttpServletRequest req = (HttpServletRequest) request;
\r
55 HttpServletResponse res = (HttpServletResponse) response;
\r
57 ONAPLogAdapter onapLogAdapter = new ONAPLogAdapter(log);
\r
58 onapLogAdapter.entering(req);
\r
60 String[] tokens = StringUtils.split(appVersion, '.');
\r
61 Preconditions.checkNotNull(tokens, "failed to split application versions");
\r
62 Preconditions.checkArgument(tokens.length == 3, "failed to tokenize application versions");
\r
63 res.addHeader(BluePrintConstants.RESPONSE_HEADER_TRANSACTION_ID, MDC.get("RequestID"));
\r
64 res.addHeader(BluePrintConstants.RESPONSE_HEADER_MINOR_VERSION, tokens[1]);
\r
65 res.addHeader(BluePrintConstants.RESPONSE_HEADER_PATCH_VERSION, tokens[2]);
\r
66 res.addHeader(BluePrintConstants.RESPONSE_HEADER_LATEST_VERSION, appVersion);
\r
67 chain.doFilter(request, response);
\r
68 // Clean the MDC info
\r
69 onapLogAdapter.exiting();
\r
73 public void init(FilterConfig filterConfig) {
\r
78 public void destroy() {
\r