1 package org.onap.vid.model.probes;
3 import com.google.common.base.MoreObjects;
4 import org.apache.commons.lang3.StringUtils;
5 import org.onap.vid.aai.ExceptionWithRequestInfo;
6 import org.onap.vid.aai.ResponseWithRequestInfo;
7 import org.onap.vid.mso.RestObjectWithRequestInfo;
8 import org.onap.vid.utils.Logging;
9 import org.springframework.http.HttpMethod;
11 import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
13 public class HttpRequestMetadata extends StatusMetadata {
14 private final HttpMethod httpMethod;
15 private final int httpCode;
16 private final String url;
17 private String rawData = "";
19 public HttpRequestMetadata(HttpMethod httpMethod, int httpCode, String url, String rawData, String description, long duration) {
20 super(description, duration);
21 this.httpMethod = httpMethod;
23 this.httpCode = httpCode;
24 this.rawData = rawData;
27 public HttpRequestMetadata(ResponseWithRequestInfo response, String description, long duration) {
28 this(response, description, duration, true);
31 public HttpRequestMetadata(RestObjectWithRequestInfo response, String description, long duration) {
32 super(description, duration);
33 this.httpMethod = response.getHttpMethod();
34 this.url = response.getRequestedUrl();
35 this.httpCode = response.getHttpCode();
36 this.rawData = response.getRawData();
39 public HttpRequestMetadata(ResponseWithRequestInfo response, String description, long duration, boolean readRawData) {
40 super(description, duration);
41 this.httpMethod = response.getRequestHttpMethod();
42 this.url = response.getRequestUrl();
43 this.httpCode = response.getResponse().getStatus();
46 this.rawData = response.getResponse().readEntity(String.class);
47 } catch (Exception e) {
53 public HttpRequestMetadata(ExceptionWithRequestInfo exception, long duration) {
54 this(exception.getHttpMethod(),
55 defaultIfNull(exception.getHttpCode(), 0),
56 exception.getRequestedUrl(),
57 exception.getRawData(),
58 Logging.exceptionToDescription(exception.getCause()),
64 public HttpMethod getHttpMethod() {
68 public int getHttpCode() {
72 public String getUrl() {
76 public String getRawData() {
77 return StringUtils.substring(rawData, 0, 500);
81 public String toString() {
82 return MoreObjects.toStringHelper(this)
83 .add("httpMethod", httpMethod)
84 .add("httpCode", httpCode)
86 .add("duration", duration)
87 .add("description", description)
88 .add("rawData", rawData)