Add model-loader integration tests
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / restclient / AaiRestClient.java
index 5576ea9..45f84d6 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
@@ -42,6 +42,7 @@ import org.onap.aai.modelloader.service.ModelLoaderMsgs;
 import org.onap.aai.restclient.client.OperationResult;
 import org.onap.aai.restclient.client.RestClient;
 import org.onap.aai.restclient.enums.RestAuthenticationMode;
+import org.springframework.stereotype.Component;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -52,6 +53,7 @@ import org.xml.sax.SAXException;
  * Wrapper around the standard A&AI Rest Client interface. This currently uses Jersey client 1.x
  *
  */
+@Component
 public class AaiRestClient {
 
     public static final String HEADER_TRANS_ID = "X-TransactionId";
@@ -133,7 +135,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 +153,24 @@ 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)
+                .connectTimeoutMs(config.getClientConnectTimeoutMs())
+                .readTimeoutMs(config.getClientReadTimeoutMs());
+
+        //Use certs only if SSL is enabled
+        if (config.useHttpsWithAAI())
+        {// @formatter:off
+            restClient
                 .clientCertFile(config.getAaiKeyStorePath())
                 .clientCertPassword(config.getAaiKeyStorePassword());
-        // @formatter:on
+            // @formatter:on
+        }
 
         if (useBasicAuth()) {
             restClient.authenticationMode(RestAuthenticationMode.SSL_BASIC);