繁体   English   中英

从Google储存区读取时com.google.api.client.googleapis.json.GoogleJsonResponseException

[英]com.google.api.client.googleapis.json.GoogleJsonResponseException while reading from google bucket

我正在尝试列出Google存储桶中一个目录中的所有文件,并从每个文件中读取数据,某些存储桶正在工作,但有一个存储桶则抛出错误

引起原因:com.google.api.client.googleapis.json.GoogleJsonResponseException:500内部服务器错误{“代码”:500,“错误”:[{“域”:“全局”,“消息”:“内部错误” ,“ reason”:“ responseTooLarge”}],“ message”:“内部错误”

stacktrace:线程“ main”中的异常com.google.cloud.storage.StorageException:com.google.cloud处com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:220)处的内部错误。 storage.spi.v1.HttpStorageRpc.list(HttpStorageRpc.java:346)位于com.google.cloud.storage.StorageImpl $ 8.call(StorageImpl.java:299)位于com.google.cloud.storage.StorageImpl $ 8.call( com.google.api.gax.retrying.DirectRetryingExecutor.submit(com.google.cloud.RetryHelper.run(RetryHelper.java:74)处的StorageImpl.java:296)com.google.cloud.RetryHelper.runWithRetries(RetryHelper) .java:51),位于com.google.cloud.storage.StorageImpl.listBlobs(StorageImpl.java:295),位于com.google.cloud.storage.StorageImpl.list(StorageImpl.java:262),位于WriteToGs.main(WriteToGs)。 Java的:22)

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class WriteToGs {
    static PGPContainer pgpContainer = new PGPContainer();
    final static Storage storage = StorageOptions.getDefaultInstance().getService();
    public static void main(String[] args) throws Exception {
        final DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
        final Date date = new Date();
        final String destinationDirectory=args[2];
        final String flowname=args[3];

        final String num_threads=args[4];

        Iterable<Blob> blobs = storage.list(args[0], Storage.BlobListOption.prefix(args[1])).iterateAll();
        ExecutorService executorService = Executors.newFixedThreadPool(Integer.parseInt(num_threads));
        for (Blob blob : blobs) {
            System.out.println("Blob name:"+blob.getName());
            final String destinationFilename=blob.getName();
            final Blob contentBlob=blob;

            executorService.execute(new Runnable() {
                public void run() {
                    String fileContent = new String(contentBlob.getContent());
                    BlobId newblobId = BlobId.of(destinationDirectory,"xyz/fds" + flowname + "/"
                            + dateFormat.format(date) + "/" + destinationFilename.replace(".txt",".pgp"));
                    BlobInfo blobInfo = BlobInfo.newBuilder(newblobId).setContentType("text/plain").build();
                    try {

                        System.out.println("Blob name deleted:"+contentBlob.getName());
                        storage.delete(contentBlob.getBlobId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }




                }
            });
        }
        executorService.shutdown();
    }

}

好吧,假设第22行(​​错误的出处)就是其中之一:

System.out.println("Blob name:"+blob.getName());

blob中的属性“ name”可能足够大,足以破坏应用程序。 但是我几乎可以确定这不是应用程序中断的地方。

基于类似的问题, GoogleJsonResponseException:500内部服务器错误:响应太大而无法返回 ,我建议您创建一个错误,因为这可能是与Google库直接相关的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM