2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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=========================================================
21 package org.onap.logging.filter.base;
25 import javax.ws.rs.client.ClientRequestContext;
26 import javax.ws.rs.client.ClientResponseContext;
28 import org.onap.logging.ref.slf4j.ONAPLogConstants;
31 public class FilteredMetricLogClientFilter extends MetricLogClientFilter {
32 protected CustomFilter<ClientRequestContext, ClientResponseContext> customFilter;
33 private static final String REQUEST_STATE_PROPERTY_NAME = "org.onap.logging.filter.base.RequestState";
35 public FilteredMetricLogClientFilter(CustomFilter<ClientRequestContext, ClientResponseContext> f) {
39 protected void additionalPre(ClientRequestContext request) {
40 request.setProperty(REQUEST_STATE_PROPERTY_NAME, MDC.getCopyOfContextMap());
43 protected void additionalPost(ClientRequestContext request, ClientResponseContext response) {
44 if (customFilter.shouldLog(request, response)) {
45 Map<String, String> responseState = MDC.getCopyOfContextMap();
46 Map<String, String> requestState = (Map<String, String>) request.getProperty(REQUEST_STATE_PROPERTY_NAME);
47 MDC.setContextMap(requestState);
48 logger.info(ONAPLogConstants.Markers.INVOKE, "Invoke");
49 MDC.setContextMap(responseState);
50 logger.info(INVOKE_RETURN, "InvokeReturn");
54 protected void logRequest() {
55 // override with empty so log entries are not duplicated
58 protected void logResponse() {
59 // override with empty so log entries are not duplicated