Package: LoggingFilter
LoggingFilter
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LoggingFilter() |
|
|
|
|
|
||||||||||||||||||||
destroy() |
|
|
|
|
|
||||||||||||||||||||
doFilter(ServletRequest, ServletResponse, FilterChain) |
|
|
|
|
|
||||||||||||||||||||
init(FilterConfig) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.rest.impl.server;
28:
29: import javax.annotation.Nonnull;
30: import java.util.Enumeration;
31: import java.io.IOException;
32: import javax.servlet.Filter;
33: import javax.servlet.FilterChain;
34: import javax.servlet.FilterConfig;
35: import javax.servlet.ServletException;
36: import javax.servlet.ServletRequest;
37: import javax.servlet.ServletResponse;
38: import javax.servlet.http.HttpServletRequest;
39: import javax.servlet.http.HttpServletResponse;
40: import org.springframework.http.HttpStatus;
41: import lombok.extern.slf4j.Slf4j;
42:
43: /***********************************************************************************************************************
44: *
45: * @author Fabrizio Giudici
46: *
47: **********************************************************************************************************************/
48: @Slf4j
49: public class LoggingFilter implements Filter
50: {
51:
52: @Override
53: public void init (@Nonnull final FilterConfig filterConfig)
54: {
55: }
56:
57: @Override
58: public void doFilter (@Nonnull final ServletRequest req,
59: @Nonnull final ServletResponse res,
60: @Nonnull final FilterChain chain)
61: throws IOException, ServletException
62: {
63: final HttpServletRequest request = (HttpServletRequest)req;
64: final HttpServletResponse response = (HttpServletResponse)res;
65:
66: try
67: {
68: log.debug(">>>> request: {} {} {}", request.getMethod(), request.getRequestURI(), request.getProtocol());
69:
70:• for (final Enumeration<String> names = request.getHeaderNames(); names.hasMoreElements(); )
71: {
72: final String headerName = names.nextElement();
73: log.debug(">>>> request header: {} = {}", headerName, request.getHeader(headerName));
74: }
75:
76: chain.doFilter(req, res);
77: }
78: finally
79: {
80: final int status = response.getStatus();
81: log.debug(">>>> response {} {}", status, HttpStatus.valueOf(status).getReasonPhrase());
82:
83:• for (final String headerName : response.getHeaderNames())
84: {
85: log.debug(">>>> response header: {} = {}", headerName, response.getHeaders(headerName));
86: }
87: }
88: }
89:
90: @Override
91: public void destroy()
92: {
93: }
94: }