Standalone TCA with EELF Logger
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-web / src / main / java / org / onap / dcae / analytics / web / http / BaseHttpClientPreferences.java
1 /*
2  * ================================================================================
3  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  *
18  */
19
20 package org.onap.dcae.analytics.web.http;
21
22 import lombok.EqualsAndHashCode;
23 import lombok.Getter;
24 import lombok.ToString;
25
26 import java.net.URL;
27
28 import javax.annotation.Nonnull;
29 import javax.annotation.Nullable;
30
31 import org.onap.dcae.analytics.model.AnalyticsHttpConstants;
32 import org.onap.dcae.analytics.model.AnalyticsModelConstants;
33 import org.onap.dcae.analytics.model.util.supplier.RandomIdSupplier;
34 import org.springframework.http.HttpHeaders;
35
36 /**
37  * Base implementation for {@link HttpClientPreferences}
38  *
39  * @author Rajiv Singla
40  */
41 @Getter
42 @ToString(exclude = "password")
43 @EqualsAndHashCode
44 public abstract class BaseHttpClientPreferences implements HttpClientPreferences {
45
46     protected String requestURL;
47     protected String httpClientId;
48     protected HttpHeaders requestHeaders;
49     protected String username;
50     protected String password;
51     protected URL proxyURL;
52     protected Boolean ignoreSSLValidation;
53     protected Boolean enableEcompAuditLogging;
54
55     public BaseHttpClientPreferences(@Nonnull final String requestURL) {
56         this.requestURL = requestURL;
57     }
58
59     public BaseHttpClientPreferences(@Nonnull final String requestURL,
60                                      @Nullable final String httpClientId,
61                                      @Nullable final HttpHeaders httpHeaders,
62                                      @Nullable final String username,
63                                      @Nullable final String password,
64                                      @Nullable final URL proxyURL,
65                                      @Nullable final Boolean ignoreSSLValidation,
66                                      @Nullable final Boolean enableEcompAuditLogging) {
67         this.requestURL = requestURL;
68         // create http client id if not present
69         this.httpClientId = httpClientId != null ? httpClientId :
70                 AnalyticsHttpConstants.DEFAULT_HTTP_CLIENT_ID_PREFIX +
71                         new RandomIdSupplier(AnalyticsModelConstants.DEFAULT_RANDOM_ID_LENGTH);
72         this.requestHeaders = httpHeaders;
73         this.username = username;
74         this.password = password;
75         this.proxyURL = proxyURL;
76         this.ignoreSSLValidation = ignoreSSLValidation != null && ignoreSSLValidation;
77         this.enableEcompAuditLogging = enableEcompAuditLogging != null && enableEcompAuditLogging;
78     }
79
80 }