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