繁体   English   中英

Google App Engine和存储API身份验证错误

[英]Google App Engine & Storage API auth error

我有一个网络应用程序,该应用程序会接收文件,然后尝试将其添加到在Google App Engine上运行的Google Cloud Storage中。 这是我得到的错误:

com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'memcache' or call 'Get()' was not found.
at com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:173)
at com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:171)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88)
at com.google.appengine.api.memcache.MemcacheServiceImpl.quietGet(MemcacheServiceImpl.java:26)
at com.google.appengine.api.memcache.MemcacheServiceImpl.get(MemcacheServiceImpl.java:49)
at com.google.appengine.api.appidentity.AppIdentityServiceImpl.getAccessToken(AppIdentityServiceImpl.java:286)
at com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential.intercept(AppIdentityCredential.java:98)
at com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential$AppEngineCredentialWrapper.intercept(AppIdentityCredential.java:243)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859)

这在我的LOCAL机器上可以正常工作(具有gutil和所有设置)。 部署到GAE时,以上操作失败。 已检查权限,它显示了对所有Google Cloud API的访问权限。 这段代码是直接从( https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/storage/json-api/src/main/java/StorageFactory.java )的Google示例中失败的部分。

 private static Storage buildService() throws IOException, GeneralSecurityException {
HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);

if (credential.createScopedRequired()) {
  Collection<String> bigqueryScopes = StorageScopes.all();
  credential = credential.createScoped(bigqueryScopes);
}

return new Storage.Builder(transport, jsonFactory, credential)
    .setApplicationName("GCS Samples")
    .build();
}

为了完整起见,这是使用上面的buildService的代码(同样来自上面的github示例链接)

            Storage client = StorageFactory.getService();
        Storage.Objects.Insert insertRequest = client.objects().insert(
                bucketName, objectMetadata, contentStream);
        insertRequest.execute();

pom.xml的deps部分

  <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
 <dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>com.google.appengine.tools</groupId>
  <artifactId>appengine-gcs-client</artifactId>
  <version>RELEASE</version>
</dependency>

GAE控制台显示它正在使用GAE v1.9.35。 这是实例显示的编辑信息,底部显示可用的烫发

Module & version
Module: default
Version: 20160405t155800
App Engine version: 1.9.35
Managed by
Google
Availability
...
GAE managed VM for module: default, version: 20160405t155800
Tags
None
Machine type

g1-small (1 vCPU, 1.7 GB memory)
CPU platform

Intel Haswell
Zone

us-central1-c

IP forwarding

off
Boot disk and local disks

Name    Size (GB)   Type    Mode    
redacted
10  
Standard persistent disk
Boot, read/write

Delete boot disk when instance is deleted
Additional disks


Preemptibility  
Off (recommended)
Automatic restart   
Off
On host maintenance 
Terminate VM instance
Service account
-----
Cloud API access scopes

This instance has full API access to all Google Cloud services.    

同样,该应用程序可在本地运行,并将文件上传发送到Google Cloud Storage。 尝试过几次将应用程序上载到GAE,但没有任何运气。 此应用已部署到GAE Flexible版本,它显示了以下内容:

latest: Pulling from google_appengine/openjdk8

另外,使用GcsService库会以不同的方式失败,但是我怀疑这是因为由于某些原因,我的应用未在GAE上正确识别为具有适当授权的GAE应用:

Caused by: java.io.IOException: java.lang.NullPointerException
at com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService$BlobStorageAdapter.getInstance(LocalRawGcsService.java:186)
at com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService$BlobStorageAdapter.access$000(LocalRawGcsService.java:109)
at com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService.ensureInitialized(LocalRawGcsService.java:194)
at com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService.beginObjectCreation(LocalRawGcsService.java:249)
at com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService.beginObjectCreation(LocalRawGcsService.java:92)
at com.google.appengine.tools.cloudstorage.GcsServiceImpl$1.call(GcsServiceImpl.java:74)
at com.google.appengine.tools.cloudstorage.GcsServiceImpl$1.call(GcsServiceImpl.java:70)

码:

                GcsOutputChannel outputChannel = gcsService.createOrReplace(fileName, GcsFileOptions.getDefaultInstance());
            InputStream inputStream = uploadfile.getInputStream();
            copy(inputStream, Channels.newOutputStream(outputChannel));

您只能在支持GAE标准API的基本运行时上使用它(例如本例中的com.google.appengine.api.memcache)。 列表在那里: https : //cloud.google.com/appengine/docs/flexible/custom-runtimes/build#base_images

您使用的基本运行时是google_appengine / openjdk8,它不支持GAE标准环境API。

现在,您可以通过以下gcloud-java库使用新的Java Cloud API(包括GCS存储访问权限): https : //github.com/GoogleCloudPlatform/gcloud-java

暂无
暂无

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

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