blob: e7eb6e8295cf092fbd05ee1bbdd683736e6bf915 [file] [log] [blame]
Hyunsun Moona5871462016-11-08 17:54:48 -08001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.opencord.cordvtn.rest;
17
18import org.slf4j.Logger;
19import org.slf4j.LoggerFactory;
20
21import javax.ws.rs.container.ContainerRequestContext;
22import javax.ws.rs.container.ContainerResponseContext;
23import javax.ws.rs.container.ContainerResponseFilter;
24import java.io.IOException;
25
26import static javax.ws.rs.core.Response.Status.Family.SUCCESSFUL;
27
28/**
29 * Implementation of a logging filter to warn any unsuccessful request.
30 */
31public class CordVtnWebLoggingFilter implements ContainerResponseFilter {
32
33 protected final Logger log = LoggerFactory.getLogger(getClass());
34
35 @Override
36 public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
37 throws IOException {
38
39 if (responseContext.getStatusInfo().getFamily() != SUCCESSFUL) {
40 log.warn("Failed to handle request: {} {}, response: {}",
41 requestContext.getMethod(),
42 requestContext.getUriInfo().getAbsolutePath(),
43 responseContext.getEntity());
44 }
45 }
46}