51e684456b3342228bacb651ca0292b0fda5297d
[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
29
30 public abstract class ApacheClientMetricInterceptor extends AbstractMetricLogFilter<HttpRequest, HttpResponse, HttpMessage> {
31
32     @Override
33     protected void addHeader(HttpMessage httpMessage, String headerName, String headerValue) {
34         httpMessage.addHeader(headerName, headerValue);
35     }
36
37     @Override
38     protected String getTargetServiceName(HttpRequest httpRequest) {
39         return httpRequest.getRequestLine().getUri();
40     }
41
42     @Override
43     protected String getServiceName(HttpRequest httpRequest) {
44         return URI.create(httpRequest.getRequestLine().getUri()).getPath();
45     }
46
47     @Override
48     protected int getHttpStatusCode(HttpResponse httpResponse) {
49         return httpResponse.getStatusLine().getStatusCode();
50     }
51
52     @Override
53     protected String getResponseCode(HttpResponse httpResponse) {
54         return String.valueOf(httpResponse.getStatusLine().getStatusCode());
55     }
56
57     @Override
58     protected String getTargetEntity(HttpRequest httpRequest) {
59         //fallback to default value that provided by AbstractMetricLogFilter
60         return null;
61     }
62 }