首页 文章

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

提问于
浏览
0

我有一个Web应用程序,它接收一个文件,然后尝试将其添加到Google Cloud 端存储,在Google App Engine上运行 . 这是我得到的错误:

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时,它失败了 . 已检查权限,并在(https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/storage/json-api/src/main/java/StorageFactory.java)显示对所有Google Cloud API 's. This code is the part that fails, directly from 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 端存储 . 多次尝试将应用程序上传到GAE而没有任何运气 . 此应用程序已部署到GAE Flexible版本,它显示了:

latest: Pulling from google_appengine/openjdk8

此外,使用GcsService lib会以不同的方式失败,但我怀疑是因为出于某种原因,我的应用程序在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));

1 回答

相关问题