Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从服务器下载大型(1gb)文件会导致请求超时_Java_Spring_File_Webclient - Fatal编程技术网

Java 从服务器下载大型(1gb)文件会导致请求超时

Java 从服务器下载大型(1gb)文件会导致请求超时,java,spring,file,webclient,Java,Spring,File,Webclient,因此,我正在开发两种服务。一个服务处理文件系统上的文件,并通过REST接口返回它们。 服务A: File zipFile = new File(folderDownload.getZipPath()); try { final InputStream inputStream = new BufferedInputStream(new FileInputStream(zipFile)); return Respons

因此,我正在开发两种服务。一个服务处理文件系统上的文件,并通过REST接口返回它们。 服务A:

        File zipFile = new File(folderDownload.getZipPath());
        try {
            final InputStream inputStream = new BufferedInputStream(new FileInputStream(zipFile));

            return ResponseEntity
            .status(HttpStatus.OK)
            .eTag(folderDownload.getDownloadId())
            .contentLength(zipFile.length())
            .lastModified(Instant.ofEpochMilli(zipFile.lastModified()))
            .body(new InputStreamResource(inputStream));

        } catch (Exception e) {
            throw new DownloadException(zipFile.getName(), e.getMessage(), 400);
        }
ServiceB是一个面向公众的API,它接收请求并验证请求,如果请求有效,它将从serviceA检索文件并将其返回给客户端。出于安全原因,serviceA只能与serviceB交互,所以除了通过2个服务发送文件外,没有其他方法

        WebClient client = WebClient.create(STORAGE_HOST);

        // Request service to get file data
        Flux<DataBuffer> fileDataStream = client.get().uri(uriBuilder -> uriBuilder.path("folders/zip/download").queryParam("requestId", requestId).build())
                .accept(MediaType.APPLICATION_OCTET_STREAM).retrieve()
                .bodyToFlux(DataBuffer.class);

        // Streams the stream from response instead of loading it all in memory
        DataBufferUtils.write(fileDataStream, outputStream).map(DataBufferUtils::release).then().block();
另外,我觉得奇怪的是,当直接从serviceA下载时,我没有得到加载指示器

在过去的一周里,我一直在研究这个问题,我正在慢慢失去理智。请帮忙:(

种类视为-,可能重复。参考-Sir-metavirit的答案可能重复-。参考-Sir-metavirit的答案
2020-04-09 13:40:24.138  WARN 4106 --- [io-8081-exec-10] s.a.s.e.CustomGlobalExceptionHandler     : Async request timed out
2020-04-09 13:40:24.138  WARN 4106 --- [io-8081-exec-10] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.context.request.async.AsyncRequestTimeoutException]