【问题标题】:com.google.api.client.googleapis.json.GoogleJsonResponseException while reading from google bucketcom.google.api.client.googleapis.json.GoogleJsonResponseException 从谷歌存储桶读取
【发布时间】:2018-10-10 02:34:57
【问题描述】:

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

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

stacktrace:线程“main”中的异常 com.google.cloud.storage.StorageException:内部错误 com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:220) 在 com.google.cloud.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(StorageImpl.java:296) 在 com.google.api.gax.retrying.DirectRetryingExecutor.submit( 在 com.google.cloud.RetryHelper.run(RetryHelper.java:74) 在 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();
    }

}

【问题讨论】:

    标签: java google-cloud-platform


    【解决方案1】:

    好吧,假设第 22 行(这是错误的来源)是第 22 行:

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

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

    基于类似的问题GoogleJsonResponseException: 500 Internal Server Error : Response Too Large To Return,我建议您创建一个错误,因为这可能是与 Google 库直接相关的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      • 1970-01-01
      • 2020-07-02
      • 2020-10-22
      • 2019-02-09
      • 1970-01-01
      • 2020-12-06
      相关资源
      最近更新 更多