Fix issues in so-cloudify-client 33/94733/2
authorParshad Patel <pars.patel@samsung.com>
Mon, 2 Sep 2019 06:02:28 +0000 (15:02 +0900)
committerParshad Patel <pars.patel@samsung.com>
Mon, 2 Sep 2019 10:05:34 +0000 (19:05 +0900)
Annotate the "CloudifyClientConnector" interface with the @FunctionalInterface annotation
Make this field final
Either log or rethrow this exception
Make "response" transient or serializable

Issue-ID: SO-1841
Change-Id: I13fa6b911d8789aed26fd27da23318f6dbca3760
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientConnector.java
cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseException.java
cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientConnector.java
cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientResponse.java

index f031f10..652df6f 100644 (file)
@@ -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.
@@ -20,7 +20,7 @@
 
 package org.onap.so.cloudify.base.client;
 
-
+@FunctionalInterface
 public interface CloudifyClientConnector {
 
     public <T> CloudifyResponse request(CloudifyRequest<T> request);
index 966cc8f..0ca3212 100644 (file)
@@ -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.
@@ -26,11 +26,11 @@ public class CloudifyResponseException extends CloudifyBaseException {
 
     private static final long serialVersionUID = 7294957362769575271L;
 
-    protected String message;
-    protected int status;
+    private final String message;
+    private final int status;
 
     // Make the response available for exception handling (includes body)
-    protected CloudifyResponse response;
+    private final CloudifyResponse response;
 
     public CloudifyResponseException(String message, int status) {
         this.message = message;
index ba6a591..54519ba 100644 (file)
@@ -9,9 +9,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.
@@ -94,7 +94,7 @@ public class HttpClientConnector implements CloudifyClientConnector {
 
     public <T> CloudifyResponse request(CloudifyRequest<T> request) {
 
-        CloseableHttpClient httpClient = null; // HttpClients.createDefault();
+        CloseableHttpClient httpClient = null;
 
         if (request.isBasicAuth()) {
             // Use Basic Auth for this request.
@@ -211,11 +211,14 @@ public class HttpClientConnector implements CloudifyClientConnector {
         } catch (HttpResponseException e) {
             // What exactly does this mean? It does not appear to get thrown for
             // non-2XX responses as documented.
+            logger.error("Client HttpResponseException", e);
             throw new CloudifyResponseException(e.getMessage(), e.getStatusCode());
         } catch (UnknownHostException e) {
+            logger.error("Client UnknownHostException", e);
             throw new CloudifyConnectException("Unknown Host: " + e.getMessage());
         } catch (IOException e) {
             // Catch all other IOExceptions and throw as OpenStackConnectException
+            logger.error("Client IOException", e);
             throw new CloudifyConnectException(e.getMessage());
         } catch (Exception e) {
             // Catchall for anything else, must throw as a RuntimeException
@@ -227,7 +230,7 @@ public class HttpClientConnector implements CloudifyClientConnector {
                 try {
                     httpResponse.close();
                 } catch (IOException e) {
-                    logger.debug("Unable to close HTTP Response: " + e);
+                    logger.debug("Unable to close HTTP Response: ", e);
                 }
         }
 
index a96fdb6..f1aa06c 100644 (file)
@@ -9,9 +9,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.
@@ -39,7 +39,7 @@ public class HttpClientResponse implements CloudifyResponse {
 
     private static Logger logger = LoggerFactory.getLogger(HttpClientResponse.class);
 
-    private HttpResponse response = null;
+    private transient HttpResponse response = null;
     private String entityBody = null;
 
     public HttpClientResponse(HttpResponse response) {