aboutsummaryrefslogtreecommitdiffstats
path: root/common-app-api/src/main/java/org/openecomp/sdc/common/http
diff options
context:
space:
mode:
Diffstat (limited to 'common-app-api/src/main/java/org/openecomp/sdc/common/http')
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/ComparableHttpRequestRetryHandler.java7
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClient.java71
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClientConfigImmutable.java58
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClientFactory.java26
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpConnectionMngFactory.java47
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpExecuteException.java10
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java69
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequestHandler.java32
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpResponse.java10
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/Responses.java6
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/RestUtils.java4
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/RetryHandlers.java13
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/config/BasicAuthorization.java42
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java50
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ExternalServiceConfig.java8
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/config/HttpClientConfig.java14
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/config/HttpRequestConfig.java14
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/config/Timeouts.java59
18 files changed, 275 insertions, 265 deletions
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/ComparableHttpRequestRetryHandler.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/ComparableHttpRequestRetryHandler.java
index 21c0f45e24..7273a04bd0 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/ComparableHttpRequestRetryHandler.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/ComparableHttpRequestRetryHandler.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,10 +19,11 @@
*/
package org.openecomp.sdc.common.http.client.api;
+
import org.apache.http.client.HttpRequestRetryHandler;
public interface ComparableHttpRequestRetryHandler extends HttpRequestRetryHandler {
- public default <T extends HttpRequestRetryHandler> boolean compare(T handler) {
+ default <T extends HttpRequestRetryHandler> boolean compare(T handler) {
return (handler != null && getClass() == handler.getClass());
}
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClient.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClient.java
index d384893d1d..9ed3efde11 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClient.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClient.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,7 +29,13 @@ import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.methods.*;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPatch;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
@@ -46,16 +52,18 @@ import java.net.URI;
import java.util.Properties;
public class HttpClient {
- private static final Logger logger = Logger.getLogger(HttpClient.class.getName());
-
+ private static final Logger LOGGER = Logger.getLogger(HttpClient.class.getName());
+ public static final int HTTPS_PORT = 443;
+ public static final int HTTP_PORT = 80;
+
private final CloseableHttpClient client;
private final HttpClientConfigImmutable configImmutable;
-
+
HttpClient(CloseableHttpClient client, HttpClientConfigImmutable configImmutable) {
this.client = client;
- this.configImmutable = configImmutable;
+ this.configImmutable = configImmutable;
}
-
+
<T> HttpResponse<T> get(String url, Properties headers, FunctionThrows<CloseableHttpResponse, HttpResponse<T>, Exception> responseBuilder) throws HttpExecuteException {
HttpGet httpGet = new HttpGet(url);
return execute(httpGet, headers, responseBuilder);
@@ -83,18 +91,17 @@ public class HttpClient {
HttpDelete httpDelete = new HttpDelete(url);
return execute(httpDelete, headers, responseBuilder);
}
-
+
void close() {
try {
client.close();
- }
- catch (IOException e) {
- logger.debug("Close http client failed with exception ", e);
+ } catch (IOException e) {
+ LOGGER.debug("Close http client failed with exception ", e);
}
}
-
+
private <T> HttpResponse<T> execute(HttpRequestBase request, Properties headers, FunctionThrows<CloseableHttpResponse, HttpResponse<T>, Exception> responseBuilder) throws HttpExecuteException {
- if(configImmutable.getHeaders() != null) {
+ if (configImmutable.getHeaders() != null) {
configImmutable.getHeaders().forEach(request::addHeader);
}
@@ -103,31 +110,30 @@ public class HttpClient {
}
HttpClientContext httpClientContext = null;
- if(request.getHeaders(HttpHeaders.AUTHORIZATION).length == 0) {
+ if (request.getHeaders(HttpHeaders.AUTHORIZATION).length == 0) {
httpClientContext = createHttpContext(request.getURI());
}
- logger.debug("Execute request {}", request.getRequestLine());
+ LOGGER.debug("Execute request {}", request.getRequestLine());
try (CloseableHttpResponse response = client.execute(request, httpClientContext)) {
return responseBuilder.apply(response);
- }
- catch (Exception e) {
- String description = String.format("Execute request %s failed with exception: %s", request.getRequestLine(), e.getMessage());
+ } catch (Exception e) {
+ String description = String.format("Execute request %s failed with exception: %s", request.getRequestLine(), e.getMessage());
BeEcompErrorManager.getInstance().logInternalFlowError("ExecuteRestRequest", description, ErrorSeverity.ERROR);
- logger.debug("{}: ",description, e);
+ LOGGER.debug("{}: ", description, e);
throw new HttpExecuteException(description, e);
- }
+ }
}
private HttpClientContext createHttpContext(URI uri) {
- if(StringUtils.isEmpty(configImmutable.getBasicAuthUserName()) || StringUtils.isEmpty(configImmutable.getBasicAuthPassword())) {
+ if (StringUtils.isEmpty(configImmutable.getBasicAuthUserName()) || StringUtils.isEmpty(configImmutable.getBasicAuthPassword())) {
return null;
}
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
int port = getPort(uri);
- credentialsProvider.setCredentials(new AuthScope(uri.getHost(), port),
+ credentialsProvider.setCredentials(new AuthScope(uri.getHost(), port),
new UsernamePasswordCredentials(configImmutable.getBasicAuthUserName(), configImmutable.getBasicAuthPassword()));
HttpClientContext localContext = HttpClientContext.create();
@@ -141,18 +147,15 @@ public class HttpClient {
}
private int getPort(URI uri) {
- int port = uri.getPort();
- if(port < 0) {
- if(Constants.HTTPS.equals(uri.getScheme())) {
- port = 443;
- }
- else
- if (Constants.HTTP.equals(uri.getScheme())) {
- port = 80;
- }
- else {
+ int port = uri.getPort();
+ if (port < 0) {
+ if (Constants.HTTPS.equals(uri.getScheme())) {
+ port = HTTPS_PORT;
+ } else if (Constants.HTTP.equals(uri.getScheme())) {
+ port = HTTP_PORT;
+ } else {
port = AuthScope.ANY_PORT;
- logger.debug("Protocol \"{}\" is not supported, set port to {}", uri.getScheme(), port);
+ LOGGER.debug("Protocol \"{}\" is not supported, set port to {}", uri.getScheme(), port);
}
}
return port;
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClientConfigImmutable.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClientConfigImmutable.java
index 2b31d49539..f0fe09fe7c 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClientConfigImmutable.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClientConfigImmutable.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -36,14 +36,14 @@ final class HttpClientConfigImmutable {
private final ClientCertificate clientCertificate;
private final Timeouts timeouts;
/*
- * use ComparableHttpRequestRetryHandler.compare instead of default generated equals
+ * use ComparableHttpRequestRetryHandler.compare instead of default generated equals
*/
private final ComparableHttpRequestRetryHandler retryHandler;
private final int numOfRetries;
-
+
static HttpClientConfigImmutable getOrCreate(HttpClientConfig httpClientConfig) {
// TODO: retrieve from a pool if exist, otherwise create new
- return new HttpClientConfigImmutable(httpClientConfig);
+ return new HttpClientConfigImmutable(httpClientConfig);
}
HttpClientConfigImmutable(HttpClientConfig httpClientConfig) {
@@ -62,7 +62,7 @@ final class HttpClientConfigImmutable {
int getNumOfRetries() {
return numOfRetries;
}
-
+
String getBasicAuthPassword() {
return basicAuthorization != null ? basicAuthorization.getPassword() : null;
}
@@ -82,7 +82,7 @@ final class HttpClientConfigImmutable {
ClientCertificate getClientCertificate() {
return clientCertificate != null ? new ClientCertificate(clientCertificate) : null;
}
-
+
int getReadTimeoutMs() {
return timeouts.getReadTimeoutMs();
}
@@ -113,43 +113,51 @@ final class HttpClientConfigImmutable {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
HttpClientConfigImmutable other = (HttpClientConfigImmutable) obj;
if (basicAuthorization == null) {
- if (other.basicAuthorization != null)
+ if (other.basicAuthorization != null) {
return false;
- }
- else if (!basicAuthorization.equals(other.basicAuthorization))
+ }
+ } else if (!basicAuthorization.equals(other.basicAuthorization)) {
return false;
+ }
if (clientCertificate == null) {
- if (other.clientCertificate != null)
+ if (other.clientCertificate != null) {
return false;
- }
- else if (!clientCertificate.equals(other.clientCertificate))
+ }
+ } else if (!clientCertificate.equals(other.clientCertificate)) {
return false;
+ }
if (headers == null) {
- if (other.headers != null)
+ if (other.headers != null) {
return false;
- }
- else if (!headers.equals(other.headers))
+ }
+ } else if (!headers.equals(other.headers)) {
return false;
+ }
if (retryHandler == null) {
- if (other.retryHandler != null)
+ if (other.retryHandler != null) {
return false;
- }
- else if (!retryHandler.compare(other.retryHandler))
+ }
+ } else if (!retryHandler.compare(other.retryHandler)) {
return false;
+ }
if (timeouts == null) {
- if (other.timeouts != null)
+ if (other.timeouts != null) {
return false;
- }
- else if (!timeouts.equals(other.timeouts))
+ }
+ } else if (!timeouts.equals(other.timeouts)) {
return false;
+ }
return true;
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClientFactory.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClientFactory.java
index 729bc1a0a0..24e2f909bc 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClientFactory.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpClientFactory.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,26 +32,26 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
public class HttpClientFactory {
- private static final Logger logger = Logger.getLogger(HttpClientFactory.class.getName());
- private static final UserTokenHandler userTokenHandler = context -> null;
+ private static final Logger LOGGER = Logger.getLogger(HttpClientFactory.class.getName());
+ private static final UserTokenHandler USER_TOKEN_HANDLER = context -> null;
private final HttpConnectionMngFactory connectionMngFactory;
-
+
HttpClientFactory(HttpConnectionMngFactory connectionMngFactory) {
this.connectionMngFactory = connectionMngFactory;
}
HttpClient createClient(String protocol, HttpClientConfigImmutable config) {
- logger.debug("Create {} client based on {}", protocol, config);
+ LOGGER.debug("Create {} client based on {}", protocol, config);
- ClientCertificate clientCertificate = Constants.HTTPS.equals(protocol) ? config.getClientCertificate() : null;
+ ClientCertificate clientCertificate = Constants.HTTPS.equals(protocol) ? config.getClientCertificate() : null;
HttpClientConnectionManager connectionManager = connectionMngFactory.getOrCreate(clientCertificate);
RequestConfig requestConfig = createClientTimeoutConfiguration(config);
CloseableHttpClient client = HttpClients.custom()
- .setDefaultRequestConfig(requestConfig)
- .setConnectionManager(connectionManager)
- .setUserTokenHandler(userTokenHandler)
- .setRetryHandler(resolveRetryHandler(config))
- .build();
+ .setDefaultRequestConfig(requestConfig)
+ .setConnectionManager(connectionManager)
+ .setUserTokenHandler(USER_TOKEN_HANDLER)
+ .setRetryHandler(resolveRetryHandler(config))
+ .build();
return new HttpClient(client, config);
}
@@ -59,7 +59,7 @@ public class HttpClientFactory {
private HttpRequestRetryHandler resolveRetryHandler(HttpClientConfigImmutable config) {
return config.getNumOfRetries() > 0 ? config.getRetryHandler() : null;
}
-
+
private RequestConfig createClientTimeoutConfiguration(HttpClientConfigImmutable config) {
return RequestConfig.custom()
.setConnectTimeout(config.getConnectTimeoutMs())
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpConnectionMngFactory.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpConnectionMngFactory.java
index c5634eaf8c..d5d03329bb 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpConnectionMngFactory.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpConnectionMngFactory.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -48,43 +48,42 @@ public class HttpConnectionMngFactory {
private static final String P12_KEYSTORE_EXTENTION = ".p12";
private static final String PFX_KEYSTORE_EXTENTION = ".pfx";
private static final String JKS_KEYSTORE_EXTENTION = ".jks";
-
+
private static final String P12_KEYSTORE_TYPE = "pkcs12";
private static final String JKS_KEYSTORE_TYPE = "jks";
-
- private static final Logger logger = Logger.getLogger(HttpConnectionMngFactory.class.getName());
+
+ private static final Logger LOGGER = Logger.getLogger(HttpConnectionMngFactory.class.getName());
private static final int DEFAULT_CONNECTION_POOL_SIZE = 30;
private static final int DEFAULT_MAX_CONNECTION_PER_ROUTE = 5;
private static final int VALIDATE_CONNECTION_AFTER_INACTIVITY_MS = 10000;
-
+
private Map<ClientCertificate, HttpClientConnectionManager> sslClientConnectionManagers = new ConcurrentHashMap<>();
private HttpClientConnectionManager plainClientConnectionManager;
-
+
HttpConnectionMngFactory() {
plainClientConnectionManager = createConnectionMng(null);
}
HttpClientConnectionManager getOrCreate(ClientCertificate clientCertificate) {
- if(clientCertificate == null) {
+ if (clientCertificate == null) {
return plainClientConnectionManager;
}
return sslClientConnectionManagers.computeIfAbsent(clientCertificate, k -> createConnectionMng(clientCertificate));
}
-
+
private HttpClientConnectionManager createConnectionMng(ClientCertificate clientCertificate) {
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
SSLConnectionSocketFactory sslsf = null;
try {
sslContextBuilder.loadTrustMaterial(new TrustSelfSignedStrategy());
-
- if(clientCertificate != null) {
+
+ if (clientCertificate != null) {
setClientSsl(clientCertificate, sslContextBuilder);
}
sslsf = new SSLConnectionSocketFactory(sslContextBuilder.build(), NoopHostnameVerifier.INSTANCE);
- }
- catch (GeneralSecurityException e) {
- logger.debug("Create SSL connection socket factory failed with exception, use default SSL factory ", e);
+ } catch (GeneralSecurityException e) {
+ LOGGER.debug("Create SSL connection socket factory failed with exception, use default SSL factory ", e);
sslsf = SSLConnectionSocketFactory.getSocketFactory();
}
@@ -106,13 +105,12 @@ public class HttpConnectionMngFactory {
char[] keyStorePassword = clientCertificate.getKeyStorePassword().toCharArray();
KeyStore clientKeyStore = createClientKeyStore(clientCertificate.getKeyStore(), keyStorePassword);
sslContextBuilder.loadKeyMaterial(clientKeyStore, keyStorePassword);
- logger.debug("#setClientSsl - Set Client Certificate authentication");
- }
- catch (IOException | GeneralSecurityException e) {
- logger.debug("#setClientSsl - Set Client Certificate authentication failed with exception, diasable client SSL authentication ", e);
+ LOGGER.debug("#setClientSsl - Set Client Certificate authentication");
+ } catch (IOException | GeneralSecurityException e) {
+ LOGGER.debug("#setClientSsl - Set Client Certificate authentication failed with exception, diasable client SSL authentication ", e);
}
}
-
+
private KeyStore createClientKeyStore(String keyStorePath, char[] keyStorePassword) throws IOException, GeneralSecurityException {
KeyStore keyStore = null;
try (InputStream stream = new FileInputStream(keyStorePath)) {
@@ -121,15 +119,14 @@ public class HttpConnectionMngFactory {
}
return keyStore;
}
-
+
private String getKeyStoreType(String keyStore) {
- if(!StringUtils.isEmpty(keyStore)) {
- if(keyStore.endsWith(P12_KEYSTORE_EXTENTION) || keyStore.endsWith(PFX_KEYSTORE_EXTENTION)) {
+ if (!StringUtils.isEmpty(keyStore)) {
+ if (keyStore.endsWith(P12_KEYSTORE_EXTENTION) || keyStore.endsWith(PFX_KEYSTORE_EXTENTION)) {
return P12_KEYSTORE_TYPE;
- }
- else if(keyStore.endsWith(JKS_KEYSTORE_EXTENTION)) {
+ } else if (keyStore.endsWith(JKS_KEYSTORE_EXTENTION)) {
return JKS_KEYSTORE_TYPE;
- }
+ }
}
return KeyStore.getDefaultType();
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpExecuteException.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpExecuteException.java
index 8487e1ff72..2b2e7a4f12 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpExecuteException.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpExecuteException.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,17 +25,17 @@ public class HttpExecuteException extends Exception {
private static final long serialVersionUID = 1L;
public HttpExecuteException(String message) {
- super (message);
+ super(message);
}
public HttpExecuteException(String message, Throwable cause) {
- super (message, cause);
+ super(message, cause);
}
public HttpExecuteException(Throwable cause) {
super(cause);
}
-
+
@Override
public Throwable getCause() {
Throwable cause = super.getCause();
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java
index 57e5cb2bed..b418ce744e 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,27 +28,34 @@ import java.util.Properties;
//TODO- remove all static and use instance methods for better testing
public abstract class HttpRequest {
- static final Properties defaultHeaders = null;
- static final HttpClientConfig defaultConfig = new HttpClientConfig();
-
+ private static final Properties DEFAULT_HEADERS = null;
+ private static final HttpClientConfig DEFAULT_CONFIG = new HttpClientConfig();
private HttpRequest() {
}
+ public static Properties getDefaultHeaders() {
+ return DEFAULT_HEADERS;
+ }
+
+ public static HttpClientConfig getDefaultConfig() {
+ return DEFAULT_CONFIG;
+ }
+
/*
* GET response as string
*/
public static HttpResponse<String> get(String url) throws HttpExecuteException {
- return get(url, defaultHeaders, defaultConfig);
+ return get(url, DEFAULT_HEADERS, DEFAULT_CONFIG);
}
public static HttpResponse<String> get(String url, Properties headers) throws HttpExecuteException {
- return get(url, headers, defaultConfig);
+ return get(url, headers, DEFAULT_CONFIG);
}
-
+
public static HttpResponse<String> get(String url, HttpClientConfig config) throws HttpExecuteException {
- return get(url, defaultHeaders, config);
+ return get(url, DEFAULT_HEADERS, config);
}
public static HttpResponse<String> get(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
@@ -59,15 +66,15 @@ public abstract class HttpRequest {
* GET response as byte array
*/
public static HttpResponse<byte[]> getAsByteArray(String url) throws HttpExecuteException {
- return getAsByteArray(url, defaultHeaders, defaultConfig);
+ return getAsByteArray(url, DEFAULT_HEADERS, DEFAULT_CONFIG);
}
public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers) throws HttpExecuteException {
- return getAsByteArray(url, headers, defaultConfig);
+ return getAsByteArray(url, headers, DEFAULT_CONFIG);
}
public static HttpResponse<byte[]> getAsByteArray(String url, HttpClientConfig config) throws HttpExecuteException {
- return getAsByteArray(url, defaultHeaders, config);
+ return getAsByteArray(url, DEFAULT_HEADERS, config);
}
public static HttpResponse<byte[]> getAsByteArray(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
@@ -78,15 +85,15 @@ public abstract class HttpRequest {
* PUT
*/
public static HttpResponse<String> put(String url, HttpEntity entity) throws HttpExecuteException {
- return put(url, defaultHeaders, entity, defaultConfig);
+ return put(url, DEFAULT_HEADERS, entity, DEFAULT_CONFIG);
}
public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
- return put(url, headers, entity, defaultConfig);
+ return put(url, headers, entity, DEFAULT_CONFIG);
}
-
+
public static HttpResponse<String> put(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
- return put(url, defaultHeaders, entity, config);
+ return put(url, DEFAULT_HEADERS, entity, config);
}
public static HttpResponse<String> put(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
@@ -97,59 +104,59 @@ public abstract class HttpRequest {
* POST
*/
public static HttpResponse<String> post(String url, HttpEntity entity) throws HttpExecuteException {
- return post(url, defaultHeaders, entity, defaultConfig);
+ return post(url, DEFAULT_HEADERS, entity, DEFAULT_CONFIG);
}
public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
- return post(url, headers, entity, defaultConfig);
+ return post(url, headers, entity, DEFAULT_CONFIG);
}
-
+
public static HttpResponse<String> post(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
- return post(url, defaultHeaders, entity, config);
+ return post(url, DEFAULT_HEADERS, entity, config);
}
public static HttpResponse<String> post(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
return HttpRequestHandler.get().post(url, headers, entity, config);
}
-
+
/*
* PATCH
*/
public static HttpResponse<String> patch(String url, HttpEntity entity) throws HttpExecuteException {
- return patch(url, defaultHeaders, entity, defaultConfig);
+ return patch(url, DEFAULT_HEADERS, entity, DEFAULT_CONFIG);
}
public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity) throws HttpExecuteException {
- return patch(url, headers, entity, defaultConfig);
+ return patch(url, headers, entity, DEFAULT_CONFIG);
}
-
+
public static HttpResponse<String> patch(String url, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
- return patch(url, defaultHeaders, entity, config);
+ return patch(url, DEFAULT_HEADERS, entity, config);
}
public static HttpResponse<String> patch(String url, Properties headers, HttpEntity entity, HttpClientConfig config) throws HttpExecuteException {
return HttpRequestHandler.get().patch(url, headers, entity, config);
}
-
+
/*
* DELETE
*/
public static HttpResponse<String> delete(String url) throws HttpExecuteException {
- return delete(url, defaultHeaders, defaultConfig);
+ return delete(url, DEFAULT_HEADERS, DEFAULT_CONFIG);
}
public static HttpResponse<String> delete(String url, Properties headers) throws HttpExecuteException {
- return delete(url, headers, defaultConfig);
+ return delete(url, headers, DEFAULT_CONFIG);
}
-
+
public static HttpResponse<String> delete(String url, HttpClientConfig config) throws HttpExecuteException {
- return delete(url, defaultHeaders, config);
+ return delete(url, DEFAULT_HEADERS, config);
}
public static HttpResponse<String> delete(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
return HttpRequestHandler.get().delete(url, headers, config);
}
-
+
public static void destroy() {
HttpRequestHandler.get().destroy();
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequestHandler.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequestHandler.java
index 73f0f15354..e4747f4308 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequestHandler.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpRequestHandler.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,10 +38,10 @@ public class HttpRequestHandler {
private static HttpRequestHandler handlerInstance = new HttpRequestHandler();
private static final String HTTPS_PREFIX = "https://";
private static final String HTTP_PREFIX = "http://";
-
+
private Map<HttpClientConfigImmutable, HttpClient> clients = new ConcurrentHashMap<>();
private HttpClientFactory clientFactory;
-
+
private FunctionThrows<CloseableHttpResponse, HttpResponse<byte[]>, Exception> byteResponseBuilder = (CloseableHttpResponse httpResponse) -> {
HttpEntity entity = httpResponse.getEntity();
byte[] response = null;
@@ -51,8 +51,8 @@ public class HttpRequestHandler {
response = IOUtils.toByteArray(content);
}
}
- return new HttpResponse<>(response,
- httpResponse.getStatusLine().getStatusCode(),
+ return new HttpResponse<>(response,
+ httpResponse.getStatusLine().getStatusCode(),
httpResponse.getStatusLine().getReasonPhrase());
};
@@ -62,7 +62,7 @@ public class HttpRequestHandler {
if (entity != null) {
response = EntityUtils.toString(entity);
}
- return new HttpResponse<>(response,
+ return new HttpResponse<>(response,
httpResponse.getStatusLine().getStatusCode(),
httpResponse.getStatusLine().getReasonPhrase());
};
@@ -71,7 +71,7 @@ public class HttpRequestHandler {
HttpConnectionMngFactory connectionMngFactory = new HttpConnectionMngFactory();
clientFactory = new HttpClientFactory(connectionMngFactory);
}
-
+
public static HttpRequestHandler get() {
return handlerInstance;
}
@@ -81,7 +81,7 @@ public class HttpRequestHandler {
return client.<String>get(url, headers, stringResponseBuilder);
}
- public HttpResponse<byte []> getAsByteArray(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
+ public HttpResponse<byte[]> getAsByteArray(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
HttpClient client = getOrCreateClient(url, config);
return client.<byte[]>get(url, headers, byteResponseBuilder);
}
@@ -102,15 +102,15 @@ public class HttpRequestHandler {
}
public HttpResponse<String> delete(String url, Properties headers, HttpClientConfig config) throws HttpExecuteException {
- HttpClient client = getOrCreateClient(url, config != null ? config : HttpRequest.defaultConfig);
+ HttpClient client = getOrCreateClient(url, config != null ? config : HttpRequest.getDefaultConfig());
return client.<String>delete(url, headers, stringResponseBuilder);
}
-
+
public void destroy() {
clients.forEach((k, v) -> v.close());
clients.clear();
}
-
+
private HttpClient getOrCreateClient(String url, HttpClientConfig config) throws HttpExecuteException {
String protocol = getProtocol(url);
HttpClientConfigImmutable httpClientConfigImmutable = HttpClientConfigImmutable.getOrCreate(config);
@@ -129,12 +129,10 @@ public class HttpRequestHandler {
private String getProtocol(String url) throws HttpExecuteException {
if (url.startsWith(HTTPS_PREFIX)) {
return Constants.HTTPS;
- }
- else if (url.startsWith(HTTP_PREFIX)) {
+ } else if (url.startsWith(HTTP_PREFIX)) {
return Constants.HTTP;
- }
- else {
+ } else {
throw new HttpExecuteException(String.format("Failed to create http client. Requested protocol is not supported \"%s\"", url));
- }
+ }
}
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpResponse.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpResponse.java
index c6061cf1c2..b3a4a96b2f 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpResponse.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/HttpResponse.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,7 +32,7 @@ public class HttpResponse<T> {
this.statusCode = statusCode;
this.description = StringUtils.EMPTY;
}
-
+
public HttpResponse(T response, int statusCode, String description) {
this.response = response;
this.statusCode = statusCode;
@@ -63,6 +63,6 @@ public class HttpResponse<T> {
builder.append("]");
return builder.toString();
}
-
-
+
+
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/Responses.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/Responses.java
index 71f9ac2629..88c4a4fe87 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/Responses.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/Responses.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,7 +24,7 @@ import org.apache.http.HttpStatus;
public final class Responses {
public static final HttpResponse<String> INTERNAL_SERVER_ERROR = new HttpResponse<>("Internal server error", HttpStatus.SC_INTERNAL_SERVER_ERROR);
-
+
private Responses() {
}
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/RestUtils.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/RestUtils.java
index 7b39e3f8c9..efac5c18ef 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/RestUtils.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/RestUtils.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/RetryHandlers.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/RetryHandlers.java
index bbcd815e75..f611ad6eba 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/RetryHandlers.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/client/api/RetryHandlers.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,14 +27,15 @@ import java.io.IOException;
public class RetryHandlers {
- private static final Logger logger = Logger.getLogger(RetryHandlers.class.getName());
+ private static final Logger LOGGER = Logger.getLogger(RetryHandlers.class.getName());
- private RetryHandlers(){}
+ private RetryHandlers() {
+ }
public static ComparableHttpRequestRetryHandler getDefault(int numOfRetries) {
return (IOException exception, int executionCount, HttpContext context) -> {
- logger.debug("failed sending request with exception", exception);
- logger.debug("try request number: {}", executionCount);
+ LOGGER.debug("failed sending request with exception", exception);
+ LOGGER.debug("try request number: {}", executionCount);
return executionCount <= numOfRetries;
};
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/BasicAuthorization.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/BasicAuthorization.java
index efd1b558c2..47338b77e7 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/BasicAuthorization.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/BasicAuthorization.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -53,19 +53,17 @@ public class BasicAuthorization {
return password;
}
-
+
private void setPassword(String password, boolean isEncoded) {
validate(password);
- if(isEncoded) {
+ if (isEncoded) {
Either<String, String> passkey = SecurityUtil.INSTANCE.decrypt(password);
- if(passkey.isLeft()) {
+ if (passkey.isLeft()) {
this.password = passkey.left().value();
- }
- else {
+ } else {
throw new IllegalArgumentException(passkey.right().value());
}
- }
- else {
+ } else {
this.password = password;
}
}
@@ -81,26 +79,28 @@ public class BasicAuthorization {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
BasicAuthorization other = (BasicAuthorization) obj;
if (password == null) {
- if (other.password != null)
+ if (other.password != null) {
return false;
- }
- else if (!password.equals(other.password))
+ }
+ } else if (!password.equals(other.password)) {
return false;
+ }
if (userName == null) {
- if (other.userName != null)
- return false;
+ return other.userName == null;
+ } else {
+ return userName.equals(other.userName);
}
- else if (!userName.equals(other.userName))
- return false;
- return true;
}
@Override
@@ -113,7 +113,7 @@ public class BasicAuthorization {
}
private void validate(String str) {
- if(StringUtils.isEmpty(str)) {
+ if (StringUtils.isEmpty(str)) {
throw new IllegalArgumentException("BasicAuthorization username and/or password cannot be empty");
}
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java
index 6ce2a38553..259d965b0d 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -35,7 +35,7 @@ public class ClientCertificate {
setKeyStore(clientCertificate.getKeyStore());
setKeyStorePassword(clientCertificate.getKeyStorePassword(), false);
}
-
+
public void setKeyStore(String keyStore) {
validate(keyStore);
this.keyStore = keyStore;
@@ -47,16 +47,14 @@ public class ClientCertificate {
private void setKeyStorePassword(String keyStorePassword, boolean isEncoded) {
validate(keyStorePassword);
- if(isEncoded) {
+ if (isEncoded) {
Either<String, String> passkey = SecurityUtil.INSTANCE.decrypt(keyStorePassword);
if (passkey.isLeft()) {
this.keyStorePassword = passkey.left().value();
- }
- else {
+ } else {
throw new IllegalArgumentException(passkey.right().value());
}
- }
- else {
+ } else {
this.keyStorePassword = keyStorePassword;
}
}
@@ -68,7 +66,7 @@ public class ClientCertificate {
public String getKeyStorePassword() {
return keyStorePassword;
}
-
+
@Override
public int hashCode() {
final int prime = 31;
@@ -80,39 +78,37 @@ public class ClientCertificate {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
ClientCertificate other = (ClientCertificate) obj;
if (keyStore == null) {
- if (other.keyStore != null)
+ if (other.keyStore != null) {
return false;
- }
- else if (!keyStore.equals(other.keyStore))
+ }
+ } else if (!keyStore.equals(other.keyStore)) {
return false;
+ }
if (keyStorePassword == null) {
- if (other.keyStorePassword != null)
- return false;
+ return other.keyStorePassword == null;
+ } else {
+ return keyStorePassword.equals(other.keyStorePassword);
}
- else if (!keyStorePassword.equals(other.keyStorePassword))
- return false;
- return true;
}
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("ClientCertificate [keyStore=");
- builder.append(keyStore);
- builder.append("]");
- return builder.toString();
+ return "ClientCertificate [keyStore=" + keyStore + "]";
}
-
+
private void validate(String str) {
- if(StringUtils.isEmpty(str)) {
+ if (StringUtils.isEmpty(str)) {
throw new IllegalArgumentException("ClientCertificate keystore and/or kestorePassword cannot be empty");
}
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ExternalServiceConfig.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ExternalServiceConfig.java
index dcc9b73bcd..2af8e74447 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ExternalServiceConfig.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ExternalServiceConfig.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,14 +21,14 @@
package org.openecomp.sdc.common.http.config;
public class ExternalServiceConfig {
-
+
private HttpRequestConfig httpRequestConfig;
private HttpClientConfig httpClientConfig;
public HttpRequestConfig getHttpRequestConfig() {
return httpRequestConfig;
}
-
+
public void setHttpRequestConfig(HttpRequestConfig httpRequestConfig) {
this.httpRequestConfig = httpRequestConfig;
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/HttpClientConfig.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/HttpClientConfig.java
index e19d1c99d1..3ed3b7c86c 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/HttpClientConfig.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/HttpClientConfig.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,9 +33,9 @@ public class HttpClientConfig {
private Map<String, String> headers;
private int numOfRetries;
- public HttpClientConfig() {
+ public HttpClientConfig() {
}
-
+
public HttpClientConfig(Timeouts timeouts) {
setTimeouts(timeouts);
}
@@ -81,11 +81,11 @@ public class HttpClientConfig {
public void setClientCertificate(ClientCertificate clientCertificate) {
this.clientCertificate = clientCertificate;
}
-
+
public Map<String, String> getHeaders() {
return headers;
}
-
+
public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}
@@ -93,7 +93,7 @@ public class HttpClientConfig {
public int getNumOfRetries() {
return numOfRetries;
}
-
+
public void setNumOfRetries(int numOfRetries) {
this.numOfRetries = numOfRetries;
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/HttpRequestConfig.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/HttpRequestConfig.java
index 040d068dfe..89e3532a10 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/HttpRequestConfig.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/HttpRequestConfig.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,22 +27,22 @@ public class HttpRequestConfig {
private String serverRootUrl;
private Map<String, String> resourceNamespaces;
-
+
public String getServerRootUrl() {
return serverRootUrl;
}
-
+
public void setServerRootUrl(String serverRootUrl) {
this.serverRootUrl = serverRootUrl;
}
-
+
public Map<String, String> getResourceNamespaces() {
- if(resourceNamespaces == null) {
+ if (resourceNamespaces == null) {
resourceNamespaces = new HashMap<>();
}
return resourceNamespaces;
}
-
+
public void setResourceNamespaces(Map<String, String> resourceNamespaces) {
this.resourceNamespaces = resourceNamespaces;
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/Timeouts.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/Timeouts.java
index 39ef8555ad..e8711f4d12 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/Timeouts.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/Timeouts.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,8 +28,9 @@ public class Timeouts {
private int connectPoolTimeoutMs = DEFAULT_TIMEOUT_MS;
public static final Timeouts DEFAULT;
+
static {
- DEFAULT = new Timeouts();
+ DEFAULT = new Timeouts();
}
private Timeouts() {
@@ -49,30 +50,30 @@ public class Timeouts {
public int getConnectTimeoutMs() {
return connectTimeoutMs;
}
-
+
public void setConnectTimeoutMs(int connectTimeoutMs) {
validate(connectTimeoutMs);
this.connectTimeoutMs = connectTimeoutMs;
}
-
+
public int getReadTimeoutMs() {
return readTimeoutMs;
}
-
+
public void setReadTimeoutMs(int readTimeoutMs) {
validate(readTimeoutMs);
this.readTimeoutMs = readTimeoutMs;
}
-
+
public int getConnectPoolTimeoutMs() {
return connectPoolTimeoutMs;
}
-
+
public void setConnectPoolTimeoutMs(int connectPoolTimeoutMs) {
validate(connectPoolTimeoutMs);
this.connectPoolTimeoutMs = connectPoolTimeoutMs;
}
-
+
@Override
public int hashCode() {
final int prime = 31;
@@ -82,40 +83,38 @@ public class Timeouts {
result = prime * result + readTimeoutMs;
return result;
}
-
+
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Timeouts other = (Timeouts) obj;
- if (connectPoolTimeoutMs != other.connectPoolTimeoutMs)
- return false;
- if (connectTimeoutMs != other.connectTimeoutMs)
+ if (connectPoolTimeoutMs != other.connectPoolTimeoutMs) {
return false;
- if (readTimeoutMs != other.readTimeoutMs)
+ }
+ if (connectTimeoutMs != other.connectTimeoutMs) {
return false;
- return true;
+ }
+ return readTimeoutMs == other.readTimeoutMs;
}
-
+
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Timeouts [connectTimeoutMs=");
- builder.append(connectTimeoutMs);
- builder.append(", readTimeoutMs=");
- builder.append(readTimeoutMs);
- builder.append(", connectPoolTimeoutMs=");
- builder.append(connectPoolTimeoutMs);
- builder.append("]");
- return builder.toString();
+ return "Timeouts [connectTimeoutMs=" + connectTimeoutMs
+ + ", readTimeoutMs=" + readTimeoutMs
+ + ", connectPoolTimeoutMs=" + connectPoolTimeoutMs
+ + "]";
}
-
+
private void validate(int timeout) {
- if(timeout <= 0) {
+ if (timeout <= 0) {
throw new IllegalArgumentException("Timeout values cannot be less than zero");
}
}