Reputation: 1909
I run endpoints.sh
get-client-lib com.my.app.FooService
and successfully generate the files for Google Cloud Endpoints[1] (2 .discovery
files, 1 .api
file and 1 .zip
file).
The script doesn't add anything to my war
folder, so I assume server-side is already handled by magic configured in web.xml
and @Api
annotations (a'la Spring Framework).
But http://localhost:8080/_ah/api/explorer
redirects me to a blank Google cloud console. Uploading my app yields the same result.
Am I missing something? I think the documentation is a bit lacking, it doesn't even explain what the generated files are for.
I'm using Google App Engine Java.
[1] https://developers.google.com/appengine/docs/java/endpoints/gen_clients
Upvotes: 1
Views: 1257
Reputation: 1435
To make the endpoints work, need follow the steps stated in the Google GAE page
Write your API backend code first.
Annotate your API backend code, so classes and client libraries can be generated from it. (Alternatively, use the Google Plugin for Eclipse, which annotates automatically for you.)
Generate the client library using the endpoints.sh utility. (Alternatively, use the Google Plugin for Eclipse to generate the client library.)
Write your client app, using the client library when making calls to the API backend.
But the above steps miss out some important steps, which the Google Plugins (Google Plugin for Eclipse) will generated for you automatically.
Configure the servlet in your web.xml. (Replace the your-full-class-name with your own class name)
<servlet>
<servlet-name>com.google.api.server.spi.SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>your-full-class-name</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>com.google.api.server.spi.SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
you need ensure the file (.api) generated by the endpoints.sh is copied into the folder WEB-INF in your web app root folder.
For better understanding, you can invoke the endpoints.sh to see all the available options as the following
Available commands: get-client-lib: Generates a client library usage: get-client-lib ... Options: --classpath=CLASSPATH Additional class path entries -cp CLASSPATH (default: ./war/WEB-INF/classes). --language=LANGUAGE The target output programming language -l LANGUAGE (java) (default: java). --output=OUTPUT_DIR The directory to store output files -o OUTPUT_DIR (default: ./). --war=WAR_PATH The path to a directory or .war with a WAR -w WAR_PATH directory layout (default: ./war). gen-api-config: Generates API configuration files from service classes usage: gen-api-config ... Options: --classpath=CLASSPATH Additional class path entries -cp CLASSPATH (default: ./war/WEB-INF/classes). --output=OUTPUT_DIR The directory to store output files -o OUTPUT_DIR (default: ./). --war=WAR_PATH The path to a directory or .war with a WAR -w WAR_PATH directory layout (default: ./war). gen-discovery-doc: Generates API Discovery document usage: gen-discovery-doc Options: --format=FORMAT The requested API protocol type (rest|rpc) -f FORMAT (default: rest). --output=OUTPUT_DIR The directory to store output files -o OUTPUT_DIR (default: ./). gen-client-lib: Generates a client library usage: gen-client-lib Options: --language=LANGUAGE The target output programming language -l LANGUAGE (java) (default: java). --output=OUTPUT_DIR The directory to store output files -o OUTPUT_DIR (default: ./).
Then you are able to view the services in the explorer UI as the following.
when you access the http: //localhost:8080/_ah/api/explorer, it will be redirected to the developers.google.com first. But the contents is from the localhost.
You can always rely on your normal Google APE local development server. For example, IntelliJ Google APE plugin start the Google APE local server also can support the "_ah/api/explorer" access
Upvotes: 1
Reputation: 1909
As mentioned by Dan Holevoet in the comment, the script needs to be ran from war
. As for my case, I just need to copy the files into that directory.
Upvotes: 0