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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dcae.analytics.web.http;
22 import lombok.EqualsAndHashCode;
24 import lombok.ToString;
28 import javax.annotation.Nonnull;
29 import javax.annotation.Nullable;
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;
37 * Base implementation for {@link HttpClientPreferences}
39 * @author Rajiv Singla
42 @ToString(exclude = "password")
44 public abstract class BaseHttpClientPreferences implements HttpClientPreferences {
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;
55 public BaseHttpClientPreferences(@Nonnull final String requestURL) {
56 this.requestURL = requestURL;
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;