You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2021/12/08 20:53:04 UTC

[incubator-streampipes] 01/01: [STREAMPIPES-482] New File API does not work with large files

This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch STREAMPIPES-482
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 0622a8df6514d10fb121c648479484fe32e6b42c
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Wed Dec 8 21:52:43 2021 +0100

    [STREAMPIPES-482] New File API does not work with large files
---
 .github/workflows/cypress-test.yml                           |  2 +-
 .../main/java/org/apache/streampipes/client/api/FileApi.java |  6 ++++++
 .../java/org/apache/streampipes/client/http/HttpRequest.java | 12 ++++++++++++
 .../streampipes/connect/iiot/utils/FileProtocolUtils.java    |  4 ++--
 4 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/cypress-test.yml b/.github/workflows/cypress-test.yml
index 860db99..ee84b9b 100644
--- a/.github/workflows/cypress-test.yml
+++ b/.github/workflows/cypress-test.yml
@@ -49,7 +49,7 @@ jobs:
       - name: Build and run streampipes
         run: docker-compose up --build -d
 
-      - name: Wait 30 seconds
+      - name: Wait 70 seconds
         working-directory: ./installer/compose
         run: sleep 70
 
diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/FileApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/FileApi.java
index 973cd90..3c592d5 100644
--- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/FileApi.java
+++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/FileApi.java
@@ -22,6 +22,8 @@ import org.apache.streampipes.client.http.BinaryGetRequest;
 import org.apache.streampipes.client.model.StreamPipesClientConfig;
 import org.apache.streampipes.client.util.StreamPipesApiPath;
 
+import java.io.InputStream;
+
 public class FileApi extends AbstractClientApi {
 
     public FileApi(StreamPipesClientConfig clientConfig) {
@@ -32,6 +34,10 @@ public class FileApi extends AbstractClientApi {
        return new BinaryGetRequest(clientConfig, getBaseResourcePath(fileName), null).executeRequest();
     }
 
+    public InputStream getFileContentAsStream(String fileName) {
+        return new BinaryGetRequest(clientConfig, getBaseResourcePath(fileName), null).executeStreamRequest();
+    }
+
     protected StreamPipesApiPath getBaseResourcePath(String fileName) {
         return StreamPipesApiPath.fromBaseApiPath()
                 .addToPath("files")
diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/http/HttpRequest.java b/streampipes-client/src/main/java/org/apache/streampipes/client/http/HttpRequest.java
index 6701dbd..1651aeb 100644
--- a/streampipes-client/src/main/java/org/apache/streampipes/client/http/HttpRequest.java
+++ b/streampipes-client/src/main/java/org/apache/streampipes/client/http/HttpRequest.java
@@ -29,6 +29,7 @@ import org.apache.streampipes.client.util.StreamPipesApiPath;
 import org.apache.streampipes.commons.exceptions.SpRuntimeException;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -102,6 +103,17 @@ public abstract class HttpRequest<SO, DSO, DT> {
     }
   }
 
+  public InputStream executeStreamRequest() throws SpRuntimeException {
+    Request request = makeRequest(serializer);
+    try {
+      return request.execute().returnContent().asStream();
+    } catch (NoHttpResponseException e) {
+      throw new SpRuntimeException("Could not connect to the StreamPipes API - please check that StreamPipes is available at " + makeUrl(false));
+    } catch (IOException e) {
+      throw new SpRuntimeException(e.getMessage());
+    }
+  }
+
   protected String entityAsString(HttpEntity entity) throws IOException {
     return EntityUtils.toString(entity);
   }
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/utils/FileProtocolUtils.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/utils/FileProtocolUtils.java
index 3662335..2063e02 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/utils/FileProtocolUtils.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/utils/FileProtocolUtils.java
@@ -52,10 +52,10 @@ public class FileProtocolUtils {
 
         StreamPipesClient client = new StreamPipesClientResolver().makeStreamPipesClientInstance();
 
-        byte[] res = client.fileApi().getFileContent(selectedFilename);
+        InputStream res = client.fileApi().getFileContentAsStream(selectedFilename);
 
         File file = new File(makeFileLoc(selectedFilename));
-        FileUtils.writeByteArrayToFile(file, res);
+        FileUtils.copyInputStreamToFile(res, file);
     }
 
     private static  String makeServiceStorageDir() {