use onap logging 1.6.1 with needed workarounds
[vid.git] / vid-app-common / src / main / java / org / onap / vid / logging / ApacheClientMetricInterceptor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.vid.logging;
22
23 import java.net.URI;
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;
29
30
31 public abstract class ApacheClientMetricInterceptor extends AbstractMetricLogFilter<HttpRequest, HttpResponse, HttpMessage> {
32
33     @Override
34     protected void addHeader(HttpMessage httpMessage, String headerName, String headerValue) {
35         httpMessage.addHeader(headerName, headerValue);
36     }
37
38     @Override
39     protected String getTargetServiceName(HttpRequest httpRequest) {
40         return httpRequest.getRequestLine().getUri();
41     }
42
43     @Override
44     protected String getServiceName(HttpRequest httpRequest) {
45         return URI.create(httpRequest.getRequestLine().getUri()).getPath();
46     }
47
48     @Override
49     protected int getHttpStatusCode(HttpResponse httpResponse) {
50         return httpResponse.getStatusLine().getStatusCode();
51     }
52
53     @Override
54     protected String getResponseCode(HttpResponse httpResponse) {
55         return String.valueOf(httpResponse.getStatusLine().getStatusCode());
56     }
57
58     @Override
59     protected String getTargetEntity(HttpRequest httpRequest) {
60         //fallback to default value that provided by AbstractMetricLogFilter
61         return null;
62     }
63
64     @Override
65     protected void additionalPre(HttpRequest request, HttpMessage message) {
66         LoggingFilterHelper.updateInvocationIDInMdcWithHeaderValue(
67             ()->message.getFirstHeader(ONAPLogConstants.Headers.INVOCATION_ID).getValue());
68     }
69
70 }