使用Google App Engine上的Java客户端API保存到Google云端存储时拒绝访问

时间:2015-10-03 10:37:34

标签: java google-app-engine google-cloud-storage

我按照Google App Engine示例在https://github.com/GoogleCloudPlatform/appengine-gcs-client/blob/master/java/example/src/com/google/appengine/demos/LocalExample.java#L79

将数据保存到Google云端存储

但我一直得到以下例外:

 Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "C:\Users\...\war\WEB-INF\appengine-generated\encoded_gs_key:L2dzL2NvZGVhdmVuZ2Vycy5hcHBzcG90LmNvbS90ZXN0MTQ6anM" "write")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
    at java.security.AccessController.checkPermission(AccessController.java:559)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:429)
    at java.lang.SecurityManager.checkWrite(SecurityManager.java:979)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    at com.google.appengine.api.blobstore.dev.FileBlobStorage.storeBlob(FileBlobStorage.java:46)
    ... 57 more

我不知道造成这种情况的原因。

我使用以下方法保存数据:

private final GcsService gcsService = GcsServiceFactory
      .createGcsService(RetryParams.getDefaultInstance());

  /**
   * Writes the provided object to the specified file using Java serialization.
   * One could use this same technique to write many objects, or with another
   * format such as Json or XML or just a DataOutputStream.
   *
   * Notice at the end closing the ObjectOutputStream is not done in a finally
   * block. See below for why.
   */
  private void writeObjectToFile(GcsFilename fileName, String content)
      throws IOException {
    GcsOutputChannel outputChannel = gcsService.createOrReplace(fileName,
        GcsFileOptions.getDefaultInstance());
    @SuppressWarnings("resource")
    ObjectOutputStream oout = new ObjectOutputStream(
        Channels.newOutputStream(outputChannel));
    oout.writeChars(content);
    oout.close();
  }

以下是调用该函数的代码:

GcsFilename filename = new GcsFilename("xxx.appspot.com", id + ":" + file);
          writeObjectToFile(filename, data);

0 个答案:

没有答案