简体   繁体   English

Google App Engine的云端点在哪里?

[英]Where are Google App Engine's Cloud Endpoints?

I'm working on a project which uses the Google App Engine to store application data remotely. 我正在研究一个使用Google App Engine远程存储应用程序数据的项目。 So far, I've created a simple class GenericEntity and used Google's tools to generate a supporting Cloud Endpoint. 到目前为止,我已经创建了一个简单的类GenericEntity并使用Google的工具来生成支持的Cloud Endpoint。

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class GenericEntity {

/* Define the UniqueID as persistent and unique. Allow JDO to assign the value of UniqueId when uploaded with a null id. */
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long mUniqueId; // Value must be 'Long' and not a primitive 'long'!

@Persistent
private String mData;
[...]

I can also successfully create and delete instances of GenericEntity in the GenericEntityEndpoint using the API Explorer. 我也可以成功地创建和删除的情况下GenericEntityGenericEntityEndpoint使用API浏览器。

Request: 请求:

POST 

Content-Type:  application/json
X-JavaScript-User-Agent:  Google APIs Explorer

{
"data": "hello SO!"
}

Response: 响应:

200 OK

The issue is that I would like to control these endpoints from a local Desktop application, but I'm confused as to how this is supposed to be done. 问题是我想从本地桌面应用程序控制这些终结点,但是我对应该如何实现感到困惑。 I imagine that the PersistenceManagerFactory is local only to Google's servers, and subsequently can't be accessed directly by my application. 我认为PersistenceManagerFactory仅在Google服务器本地,随后无法被我的应用程序直接访问。 Is there a final step I'm missing which will allow high-level interaction with these generated Endpoints over a network, or do I need to implement my own interface with the server using HttpUrlRequest functions? 我是否还没有最后一步可以通过网络与这些生成的端点进行高层交互,还是我需要使用HttpUrlRequest函数与服务器实现自己的接口?

Cloud endpoint sends JSON data using REST or RPC over HTTP and authentication is managed using OAuth2 so you can either write your desktop application from scratch or you can use the various Google libraries to connect to your endpoint. 云端点使用REST或RPC over HTTP发送JSON数据,并使用OAuth2管理身份验证,因此您可以从头开始编写桌面应用程序,也可以使用各种Google库连接到端点。 For Java applications I usually use the Android cloud endpoint library which you can generate using the endpoint.sh, I use the classes generated for Android to call the cloud endpoint from any other Java apps: 对于Java应用程序,我通常使用可以使用endpoint.sh生成的Android云终结点库,我使用为Android生成的类从任何其他Java应用程序调用云终结点:

appengine-java-sdk-x.x.x/bin/endpoints.sh <command> <options> [class-name]

more details here ( https://cloud.google.com/appengine/docs/java/endpoints/endpoints_tool ) 此处有更多详细信息( https://cloud.google.com/appengine/docs/java/endpoints/endpoints_tool

Once the source jar is generated by endpoint.sh I usually expand it into my client Java project. 一旦端点.sh生成了源jar,我通常会将其扩展到我的客户端Java项目中。 Otherwise you can compile the generated classes and bundle them as a binary jar. 否则,您可以编译生成的类并将其捆绑为二进制jar。 Once this is done you need to take care of the authentication part. 完成此操作后,您需要注意身份验证部分。 This can be done by using the OAuth2 Java client library ( https://developers.google.com/api-client-library/java/apis/oauth2/v1 ) see the provided example oauth2-cmdline-sample 这可以通过使用OAuth2 Java客户端库( https://developers.google.com/api-client-library/java/apis/oauth2/v1 )完成,请参见提供的示例oauth2-cmdline-sample

Once you have an OAuth2 token calling the cloud endpoint form your desktop application is no different to calling any other Google API, the Service Object and Builder patterns are all the same eg depending on the name of your endpoint API you can create a service object from the endpoint.sh generated classes as follows 一旦您有OAuth2令牌从桌面应用程序调用云终结点就与调用任何其他Google API一样,则服务对象和构建器模式都相同,例如,根据终结点API的名称,您可以从中创建服务对象endpoint.sh生成的类如下

Endpoint endpoint = Endpoint.Builder(
                        HTTP_TRANSPORT, JSON_FACTORY, getCredential()).build();

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

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