Merge "Update model-loader dependencies"
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / restclient / AaiRestClient.java
index 5576ea9..29c0c70 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
@@ -133,7 +133,7 @@ public class AaiRestClient {
     public OperationResult getAndDeleteResource(String url, String transId) {
         // First, GET the model
         OperationResult getResponse = getResource(url, transId, MediaType.APPLICATION_XML_TYPE);
-        if ((getResponse == null) || (getResponse.getResultCode() != Response.Status.OK.getStatusCode())) {
+        if (getResponse == null || getResponse.getResultCode() != Response.Status.OK.getStatusCode()) {
             return getResponse;
         }
 
@@ -151,18 +151,29 @@ public class AaiRestClient {
 
 
     public boolean useBasicAuth() {
-        return (config.getAaiAuthenticationUser() != null) && (config.getAaiAuthenticationPassword() != null);
+        return config.getAaiAuthenticationUser() != null && config.getAaiAuthenticationPassword() != null;
     }
 
     private RestClient setupClient() {
         RestClient restClient = new RestClient();
 
-        // @formatter:off
-        restClient.validateServerHostname(false)
-                .validateServerCertChain(false)
-                .clientCertFile(config.getAaiKeyStorePath())
-                .clientCertPassword(config.getAaiKeyStorePassword());
-        // @formatter:on
+        //Use certs only if SSL is enabled
+        if (config.useHttpsWithAAI())
+        {// @formatter:off
+            restClient.validateServerHostname(false)
+                    .validateServerCertChain(false)
+                    .clientCertFile(config.getAaiKeyStorePath())
+                    .clientCertPassword(config.getAaiKeyStorePassword())
+                    .connectTimeoutMs(120000)
+                    .readTimeoutMs(120000);
+            // @formatter:on
+        }
+        else {
+            restClient.validateServerHostname(false)
+                    .validateServerCertChain(false)
+                    .connectTimeoutMs(120000)
+                    .readTimeoutMs(120000);
+        }
 
         if (useBasicAuth()) {
             restClient.authenticationMode(RestAuthenticationMode.SSL_BASIC);