为Java客户端生成Google Cloud端点 [英] Generating Google Cloud endpoints for Java client

查看:129
本文介绍了为Java客户端生成Google Cloud端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于使用来自Java客户端的Google Cloud端点没有多少文字。有迹象表明,它可以在各种文件中完成,但很少写入它。第一个问题:是否有一些关于如何从Java使用Google Cloud Endpoint的文档或示例?有关如何使用Google Cloud Endpoint的文档或示例,请参见http://go.microsoft.com/fwlink/?客户端?



我正在使用GPE来生成端点客户端库。输出是用一堆东西创建endpoint-libs目录。文档说:生成的服务特定的库可以在zip文件的顶级目录中找到:google-api-services-mayapp-v1-rev20140417180959-1.16.0-rc.jar。使用我的GPE版本(3.5.1),没有创建这样的JAR文件。



这个井字游戏例子的视频(进入23分钟标记)显示了一些源文件正在从endpoint-libs目录复制到Android客户端应用程序中。



https://www.youtube.com/watch?v=NU_wNR_UUn4



第二个问题:是关于创建上述JAR文件的文档错误?有没有关于生成的源文件以及如何使用它们的文档?也许有一些关于构建Android应用程序的文档,但我不知道Android。在任何情况下,我都浏览了一些Android客户端代码。



视频继续显示用于引用端点的服务对象。

  MyApp.Builder builder = new MyApp.Builder(new NetHttpTransport(new NetHttpTransport ),新的GsonFactory(),null); 
service = builder.build();
Method1 method1 = service.getEndpointMethod1();
method1.execute();

Android示例使用AndroidHttp.newCompatibleTransport()创建一个HttpTransport作为MyApp.Builder的第一个参数();

第三个问题:我用于为Java客户端创建HttpTransport的方法是什么?



第四个问题:有多少Android客户端文档适用于从Java客户端使用端点 - 因为它们都是Java客户端?什么不适用?

解决方案

(OP:请参阅下面的无Maven,因为您说你没有使用Maven )

使用Maven



My Cloud Endpoints项目pom.xml包含插件配置:

 < plugin> 
< groupId> com.google.appengine< / groupId>
< artifactId> appengine-maven-plugin< / artifactId>
< version> $ {appengine.version}< / version>
<配置>
< enableJarClasses> false< / enableJarClasses>
< version> $ {app.version}< / version>
< / configuration>
<执行次数>
<执行>
<目标>
<! - 在编译阶段生成发现文档和客户端库
。 - >
< goal> endpoints_get_discovery_doc< / goal>
< goal> endpoints_get_client_lib< / goal>
< /目标>
< /执行>
< /执行次数>
< / plugin>注意< goal> endpoints_get_client_lib< / goal> 入口,它没有被包含在原始框架中,并且是这里的重要部分。



对于我来说,这会生成并安装一个名为<$ c $的jar C> {myApiName} -v1-1.21.0-SNAPSHOT.jar 。请参阅下面的结果,了解我在.jar中看到的内容。



没有Maven



Maven似乎正在使用alex @ 指向的机制之一, endpoints.sh 文档)。当我在终端模块上运行mvn install时,会看到如下消息:

 执行终端命令= [get-client- lib,
-cp,{很多.jar文件},-o,{输出WEB-INF dir的路径},
-w,{生成文件工作目录的路径?},-l, java,
-bs,maven,com.example.MyApi]

我猜这是一个它传递给 endpoints.sh 的参数列表,虽然我没有检查过。



结果



生成的.jar文件如下所示:顶级客户端MyApiName类,一些支持类和从发现文档生成的模型类: p>

  META-INF / MANIFEST.MF 
META-INF / maven / com.example / myApiName / pom.properties
META-INF / maven / com.example / myApiName / pom.xml
com / example / myApiName / MyApi $ AddBatch.class
com / example / myApiName / MyApi $ Builder.class
com / example / myApiName / MyApi.class
com / example / myApiName / MyApi Request.class
com / example / myApiName / MyApiRequestInitializer.class
com / example / myApiName / MyApiScopes.class
com / example / myApiName / model / Thing.class
com / example / myApiName / model / OtherThing.class


Not much written about using Google Cloud endpoints from a Java client. There are hints that it can be done in various documents but very little written about it. I've been able to get it work but there are some questions.

First question: Is there some documentation or an example about how to use Google Cloud Endpoint from a Java client?

I'm using the GPE to generate an endpoints client library. The output is the creation of endpoint-libs directory with a bunch of stuff. Documentation says, "The generated service-specific library can be found in the top level directory of the zip file: google-api-services-mayapp-v1-rev20140417180959-1.16.0-rc.jar". With my version of the GPE (3.5.1) there is no such JAR file created.

This video of the tic-tac-toe example (go to the 23 min mark) shows some source files being copied from the endpoint-libs directory into an Android client app.

https://www.youtube.com/watch?v=NU_wNR_UUn4

Second question: Is the documentation wrong regarding the creating of the above mentioned JAR file? Is there any documentation about the generated sources files and how to use them? Perhaps there is some documentation in regards to building an Android app, but I don't know Android. In any case, I sifted through some of the Android client code.

The video goes on to show a "service" object being used to reference the endpoints. I've adapted the code to work with a Java client.

MyApp.Builder builder = new MyApp.Builder( new NetHttpTransport(), new GsonFactory(), null );
service = builder.build();
Method1 method1 = service.getEndpointMethod1();
method1.execute();

The Android sample uses AndroidHttp.newCompatibleTransport() to create an HttpTransport as the first argument to MyApp.Builder();

Third question: Is the method I used for creating an HttpTransport proper for a Java client?

Fourth question: How much of the Android client documentation applies to use of an endpoint from a Java client - since they are both Java clients? What wouldn't apply?

解决方案

(OP: see "Without Maven" below, since you say you're not using Maven)

With Maven

My Cloud Endpoints project pom.xml include the plugin config:

<plugin>
  <groupId>com.google.appengine</groupId>
  <artifactId>appengine-maven-plugin</artifactId>
  <version>${appengine.version}</version>
  <configuration>
    <enableJarClasses>false</enableJarClasses>
    <version>${app.version}</version>
  </configuration>
  <executions>
    <execution>
      <goals>
        <!-- Generates the discovery document and client library
             during the compile phase. -->
        <goal>endpoints_get_discovery_doc</goal>
        <goal>endpoints_get_client_lib</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Note the <goal>endpoints_get_client_lib</goal> entry, which was not included in the original skeleton, and is the important piece here.

For me, this produces and installs a jar named {myApiName}-v1-1.21.0-SNAPSHOT.jar. See "Results" below for what I see in the .jar.

Without Maven

Under the hood, Maven seems to be using one of the mechanisms that alex@ pointed to, endpoints.sh (docs). When I run "mvn install" on my Endpoints module, I see a message like

Executing endpoints Command=[get-client-lib,
  -cp, {lots of .jar files}, -o, {path to output WEB-INF dir},
  -w, {path to generated file working dir?}, -l, java,
  -bs, maven, com.example.MyApi]

I'm guessing that this is a list of the args that it's passing to endpoints.sh, though I haven't checked.

Results

The resulting .jar file looks like this, with the top-level client MyApiName class, some supporting classes, and model classes generated from the discovery document:

META-INF/MANIFEST.MF
META-INF/maven/com.example/myApiName/pom.properties
META-INF/maven/com.example/myApiName/pom.xml
com/example/myApiName/MyApi$AddBatch.class
com/example/myApiName/MyApi$Builder.class
com/example/myApiName/MyApi.class
com/example/myApiName/MyApiRequest.class
com/example/myApiName/MyApiRequestInitializer.class
com/example/myApiName/MyApiScopes.class
com/example/myApiName/model/Thing.class
com/example/myApiName/model/OtherThing.class

这篇关于为Java客户端生成Google Cloud端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆