java – Google Appengine和云存储:AppIdentity服务引发了意外错误

我正在尝试按照 sample from google

使用GcsExampleServlet.java设置Google端存储文件上传.我已完成所有步骤,但当我将项目部署到aggengine并尝试在GCS中上传简单文本时,它会失败并显示以下日志:

com.google.appengine.tools.cloudstorage.NonRetriableException: com.google.appengine.tools.cloudstorage.NonRetriableException: com.google.appengine.api.appidentity.AppIdentityServiceFailureException: 
The AppIdentity service threw an unexpected error. Details: 
at com.google.appengine.tools.cloudstorage.RetryHelper.doRetry(RetryHelper.java:120)
at com.google.appengine.tools.cloudstorage.RetryHelper.runWithRetries(RetryHelper.java:166)
at com.google.appengine.tools.cloudstorage.RetryHelper.runWithRetries(RetryHelper.java:156)
at com.google.appengine.tools.cloudstorage.GcsServiceImpl.createOrReplace(GcsServiceImpl.java:70)
at com.appart.storage.server.GcsExampleServlet.doPost(GcsExampleServlet.java:88)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
(...)

仍然,代码中没有任何复杂的…在web.xml中我已经配置了servlet:

<servlet>
  <servlet-name>GcsExample</servlet-name>
    <servlet-class>
      com.example.server.GcsExampleServlet
    </servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>GcsExample</servlet-name>
  <url-pattern>/gcs/*</url-pattern>
</servlet-mapping>

这是servlet GcsExampleServlet.java(与google示例完全相同):

@SuppressWarnings("serial")
public class GcsExampleServlet extends HttpServlet {

  private final GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder()
      .initialRetryDelayMillis(10)
      .retryMaxAttempts(10)
      .totalRetryPeriodMillis(15000)
      .build());     
  //...
  @Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException 
  {
    GcsOutputChannel outputChannel =
    gcsService.createOrReplace(getFileName(req), GcsFileOptions.getDefaultInstance());
    copy(req.getInputStream(), Channels.newOutputStream(outputChannel));
  }

  private void copy(InputStream input, OutputStream output) throws IOException {
    try {
      byte[] buffer = new byte[BUFFER_SIZE];
      int bytesRead = input.read(buffer);
      while (bytesRead != -1) {
        output.write(buffer, 0, bytesRead);
        bytesRead = input.read(buffer);
      }
    } finally {
      input.close();
      output.close();
    }
  }
}

这是我的upload.html文件:

<form action="/upload.html" enctype="text/plain" method="get" name="putFile" id="putFile">
   <div>
        Bucket: <input type="text" name="bucket" />
        File Name: <input type="text" name="fileName" />
        <br /> File Contents: <br />
        <textarea name="content" id="content" rows="3" cols="60"></textarea>
        <br />
        <input type="submit" onclick='uploadFile(this)' value="Upload Content" />
   </div>
</form>
<script>

  function uploadFile() {
    var bucket = document.forms["putFile"]["bucket"].value;
    var filename = document.forms["putFile"]["fileName"].value;
    if (bucket == null || bucket == "" || filename == null || filename == "") {
      alert("Both Bucket and FileName are required");
      return false;
    } else {
      var postData = document.forms["putFile"]["content"].value;
      document.getElementById("content").value = null;

      var request = new XMLHttpRequest();
      request.open("POST", "/gcs/" + bucket + "/" + filename, false);
      request.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
      request.send(postData);
    }
  }
</script>

我启用了Billing,创建了一个存储桶但仍然出现了AppIdentity错误.我没有Oauth,云存储API已启用,用于上传的appengine帐户具有对存储桶的写入权限.我甚至试过了

gsutil acl ch -u warm-particle-718@appspot.gserviceaccount.com:WRITE gs://ctrlxbucket

确保用户具有对我的存储桶的写入权限.

请帮我弄清楚这个错误是什么意思,我坚持这里几天:(

非常感谢

PS:如果你只有一些GCS的工作样本(不是google的样本),我也会很开心,因为围绕这个话题没有很多东西.

原文 

https://codeday.me/bug/20190111/504389.html

本站部分文章源于互联网,本着传播知识、有益学习和研究的目的进行的转载,为网友免费提供。如有著作权人或出版方提出异议,本站将立即删除。如果您对文章转载有任何疑问请告之我们,以便我们及时纠正。

PS:推荐一个微信公众号: askHarries 或者qq群:474807195,里面会分享一些资深架构师录制的视频录像:有Spring,MyBatis,Netty源码分析,高并发、高性能、分布式、微服务架构的原理,JVM性能优化这些成为架构师必备的知识体系。还能领取免费的学习资源,目前受益良多

转载请注明原文出处:Harries Blog™ » java – Google Appengine和云存储:AppIdentity服务引发了意外错误

赞 (0)
分享到:更多 ()

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址