Configurable option to load models via Gizmo
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / restclient / AaiRestClient.java
index 7d2ab09..a2a4c5b 100644 (file)
@@ -1,27 +1,26 @@
 /**
- * ============LICENSE_START==========================================
+ * ============LICENSE_START=======================================================
  * org.onap.aai
- * ===================================================================
+ * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ===================================================================
+ * Copyright © 2017-2018 European Software Marketing Ltd.
+ * ================================================================================
  * 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
+ *       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.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * ============LICENSE_END============================================
+ * ============LICENSE_END=========================================================
  */
 package org.onap.aai.modelloader.restclient;
 
 import com.sun.jersey.core.util.MultivaluedMapImpl; // NOSONAR
-// import edu.emory.mathcs.backport.java.util.Collections;
 import java.io.IOException;
 import java.io.StringReader;
 import java.net.URI;
@@ -91,7 +90,7 @@ public class AaiRestClient {
      * @return operation result
      */
     public OperationResult putResource(String url, String payload, String transId, MediaType mediaType) {
-       logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload);
+        logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload);
         return setupClient().put(url, payload, buildHeaders(transId), mediaType, mediaType);
     }
 
@@ -106,7 +105,7 @@ public class AaiRestClient {
      * @return ClientResponse
      */
     public OperationResult postResource(String url, String payload, String transId, MediaType mediaType) {
-       logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload);
+        logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload);
         return setupClient().post(url, payload, buildHeaders(transId), mediaType, mediaType);
     }
 
@@ -134,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;
         }
 
@@ -152,7 +151,7 @@ public class AaiRestClient {
 
 
     public boolean useBasicAuth() {
-        return (config.getAaiAuthenticationUser() != null) && (config.getAaiAuthenticationPassword() != null);
+        return config.getAaiAuthenticationUser() != null && config.getAaiAuthenticationPassword() != null;
     }
 
     private RestClient setupClient() {
@@ -162,7 +161,9 @@ public class AaiRestClient {
         restClient.validateServerHostname(false)
                 .validateServerCertChain(false)
                 .clientCertFile(config.getAaiKeyStorePath())
-                .clientCertPassword(config.getAaiKeyStorePassword());
+                .clientCertPassword(config.getAaiKeyStorePassword())
+                .connectTimeoutMs(120000)
+                .readTimeoutMs(120000);
         // @formatter:on
 
         if (useBasicAuth()) {
@@ -180,7 +181,6 @@ public class AaiRestClient {
      * @param transId
      * @return map of headers
      */
-    @SuppressWarnings("unchecked")
     private Map<String, List<String>> buildHeaders(String transId) {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         headers.put(HEADER_TRANS_ID, Collections.singletonList(transId));