2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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.vid.logging;
24 import org.apache.http.HttpMessage;
25 import org.apache.http.HttpRequest;
26 import org.apache.http.HttpResponse;
27 import org.onap.logging.filter.base.AbstractMetricLogFilter;
28 import org.onap.logging.ref.slf4j.ONAPLogConstants;
31 public abstract class ApacheClientMetricInterceptor extends AbstractMetricLogFilter<HttpRequest, HttpResponse, HttpMessage> {
34 protected void addHeader(HttpMessage httpMessage, String headerName, String headerValue) {
35 httpMessage.addHeader(headerName, headerValue);
39 protected String getTargetServiceName(HttpRequest httpRequest) {
40 return httpRequest.getRequestLine().getUri();
44 protected String getServiceName(HttpRequest httpRequest) {
45 return URI.create(httpRequest.getRequestLine().getUri()).getPath();
49 protected int getHttpStatusCode(HttpResponse httpResponse) {
50 return httpResponse.getStatusLine().getStatusCode();
54 protected String getResponseCode(HttpResponse httpResponse) {
55 return String.valueOf(httpResponse.getStatusLine().getStatusCode());
59 protected String getTargetEntity(HttpRequest httpRequest) {
60 //fallback to default value that provided by AbstractMetricLogFilter
65 protected void additionalPre(HttpRequest request, HttpMessage message) {
66 LoggingFilterHelper.updateInvocationIDInMdcWithHeaderValue(
67 ()->message.getFirstHeader(ONAPLogConstants.Headers.INVOCATION_ID).getValue());