【发布时间】:2016-07-22 09:41:59
【问题描述】:
我正在尝试从我的本地计算机用 Java 连接到 Google App Engine 的数据存储区。我不会将服务与 GAE 上的应用程序一起使用,它将在 AWS 上。
我尝试了什么
我尝试使用
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();,但我认为它适用于应用程序托管在 GAE 上的情况。
现在,我使用系统变量 GOOGLE_APPLICATION_CREDENTIALS 获取的 json 凭据文件启动并运行 Google Storage。连接工作正常,所以我的猜测是我可能需要做一些类似于 Storage 的事情。 我为存储做了这样的事情:
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);
}
Storage client = new Storage.Builder(transport, jsonFactory, credential)
.setApplicationName("APPLICATION_NAME")
.build();
问题
所以我的问题是:如何从 Google App Engine 外部连接到 Google App Engine Datastore?
感谢您的帮助!
【问题讨论】:
标签: java google-app-engine google-cloud-datastore