[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-10251?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16359535#comment-16359535
 ] 

ASF GitHub Bot commented on CLOUDSTACK-10251:
---------------------------------------------

rhtyd closed pull request #2424: CLOUDSTACK-10251: HTTPS downloader for Direct 
Download templates failure
URL: https://github.com/apache/cloudstack/pull/2424
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/agent/src/com/cloud/agent/direct/download/HttpsDirectTemplateDownloader.java 
b/agent/src/com/cloud/agent/direct/download/HttpsDirectTemplateDownloader.java
index 436303f71cf..664181fbda3 100644
--- 
a/agent/src/com/cloud/agent/direct/download/HttpsDirectTemplateDownloader.java
+++ 
b/agent/src/com/cloud/agent/direct/download/HttpsDirectTemplateDownloader.java
@@ -21,6 +21,9 @@
 
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.Script;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@@ -33,6 +36,9 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
 import java.security.KeyManagementException;
 import java.security.KeyStore;
 import java.security.KeyStoreException;
@@ -79,11 +85,32 @@ private SSLContext getSSLContext() throws 
KeyStoreException, NoSuchAlgorithmExce
 
     @Override
     public boolean downloadTemplate() {
+        CloseableHttpResponse response;
         try {
-            httpsClient.execute(req);
+            response = httpsClient.execute(req);
         } catch (IOException e) {
             throw new CloudRuntimeException("Error on HTTPS request: " + 
e.getMessage());
         }
-        return performDownload();
+        return consumeResponse(response);
     }
+
+    /**
+     * Consume response and persist it on getDownloadedFilePath() file
+     */
+    protected boolean consumeResponse(CloseableHttpResponse response) {
+        if (response.getStatusLine().getStatusCode() != 200) {
+            throw new CloudRuntimeException("Error on HTTPS response");
+        }
+        try {
+            HttpEntity entity = response.getEntity();
+            InputStream in = entity.getContent();
+            OutputStream out = new FileOutputStream(getDownloadedFilePath());
+            IOUtils.copy(in, out);
+        } catch (Exception e) {
+            s_logger.error("Error parsing response for template " + 
getTemplateId() + " due to: " + e.getMessage());
+            return false;
+        }
+        return true;
+    }
+
 }
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> HTTPS downloader for Direct Download templates failure 
> -------------------------------------------------------
>
>                 Key: CLOUDSTACK-10251
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10251
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>    Affects Versions: 4.11.0.0
>            Reporter: Nicolas Vazquez
>            Assignee: Nicolas Vazquez
>            Priority: Major
>
> Failure on HTTPS downloader for Direct Download templates on KVM.
> Reason: Incorrect request caused NullPointerException getting the response 
> InputStream



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to