How do I use Explorer with a local HTTP API?
https://developers.google.com/explorer-help/#hitting_local_api

2016年2月16日火曜日 23時15分14秒 UTC+9 Deepesh Mathuria:
>
>
>
>
>
>
> I  have the following endpoints API code, I was trying to test it on my 
> local server but when I open the API explorer it shows no API method? Is 
> there anything wrong with the code. I've used Objectify 4.0.1 to store the 
> data to datastore
>
>
> package spi;
>
> import com.google.api.server.spi.config.Api;
> import com.google.api.server.spi.config.ApiMethod;
> import com.google.api.server.spi.config.ApiMethod.HttpMethod;
> import com.google.api.server.spi.response.UnauthorizedException;
> import com.google.appengine.api.users.User;
> import consts.Constants;
> import profile.*;
> import static com.googlecode.objectify.ObjectifyService.ofy;
> import com.googlecode.objectify.Key;
>
> @Api(name = "mniterp", version = "v1", scopes = { Constants.EMAIL_SCOPE }, 
> clientIds = {
> Constants.WEB_CLIENT_ID, Constants.API_EXPLORER_CLIENT_ID }, description = 
> "API for the MNIT ERP Backend application.")
> public class ErpEndPoints {
>
> private String mainEmail;
> private String genId;
> private String userId;
> private String displayName;
>
> private static String extractID(String email) {
> return email == null ? null : email.substring(0, email.indexOf("@"));
> }
>
> @ApiMethod(name = "loadStudentProfile", path = "loadStudent", httpMethod = 
> HttpMethod.GET)
> public StudentProfile loadStudentProfile(final User user) {
> Key<StudentProfile> key = Key.create(StudentProfile.class,
> user.getUserId());
> StudentProfile sp = (StudentProfile) ofy().load().key(key).get();
> return sp;
> }
>
> @ApiMethod(name = "loadFacultyProfile", path = "loadFaculty", httpMethod = 
> HttpMethod.GET)
> public FacultyProfile loadFacultyProfile(final User user) {
> Key<FacultyProfile> key = Key.create(FacultyProfile.class,
> user.getUserId());
> FacultyProfile fp = (FacultyProfile) ofy().load().key(key).get();
> return fp;
> }
>
> @ApiMethod(name = "checkUser", path = "user", httpMethod = HttpMethod.GET)
> private boolean checkUser(final User user) {
> displayName = extractID(user.getEmail());
> if (displayName.substring(0, 3).equals("prof")) {
> return true;
> }
> return false;
> }
> /* public void getProfile(final User user) throws UnauthorizedException {
> if (user == null) {
> throw new UnauthorizedException("Authentication failed!!");
> }
> if (!checkUser(user)) {
> StudentProfile sp = loadStudentProfile(user);
> //return sp;
> } else {
> FacultyProfile fp = loadFacultyProfile(user);
> }
> }
> */
> @ApiMethod(name = "saveFacultyProfile", path = "profile", httpMethod = 
> HttpMethod.POST)
> public FacultyProfile saveFacultyProfile(final User user)
>  throws UnauthorizedException {
>
> if (user == null) {
> throw new UnauthorizedException(
> "Authentication Required for logging in");
> }
>
> mainEmail = user.getEmail();
> genId = user.getUserId();
> userId = extractID(mainEmail);
>
> FacultyProfile fp = new FacultyProfile(mainEmail,genId,userId);
> // saves faculty profile object in datastore
> ofy().save().entity(fp).now();
> return fp;
>
> }
>
> @ApiMethod(name = "saveStudentProfile", httpMethod = HttpMethod.POST, 
> path="student")
> public StudentProfile saveStudentProfile(User user)
> throws UnauthorizedException {
>
> if (user == null) {
> throw new UnauthorizedException(
> "Authentication Required for logging in");
> }
>
> mainEmail = user.getEmail();
> genId = user.getUserId();
> userId = extractID(mainEmail);
>
> StudentProfile sp = (StudentProfile) ofy().load()
> .key(Key.create(StudentProfile.class, genId)).get();
> if (sp == null) {
> sp = new StudentProfile(mainEmail, genId, userId);
> } else {
>                  //do nothing
> }
> // saves student profile object in datastore
> ofy().save().entity(sp).now();
> return sp;
> }
> }
>
>
>
> Here's the web.xml file
> <?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="
> http://java.sun.com/xml/ns/javaee"; xmlns:web="
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"; xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance"; version="2.5" 
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";>
> <servlet>
> <servlet-name>MnitERP</servlet-name>
> <servlet-class>erp.MnitERPServlet</servlet-class>
> </servlet>
> <servlet-mapping>
> <servlet-name>MnitERP</servlet-name>
> <url-pattern>/mniterp</url-pattern>
> </servlet-mapping>
> <welcome-file-list>
> <welcome-file>index.html</welcome-file>
> </welcome-file-list>
>  <servlet>
>   <servlet-name>SystemServiceServlet</servlet-name>
>   
> <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
>   <init-param>
>    <param-name>services</param-name>
>    <param-value>spi.ErpEndPoints</param-value>
>   </init-param>
>  </servlet>
>  <servlet-mapping>
>   <servlet-name>SystemServiceServlet</servlet-name>
>   <url-pattern>/_ah/spi/*</url-pattern>
>  </servlet-mapping>
> </web-app>
>
> The log says : 
> INFO: The admin console is running at http://localhost:8888/_ah/admin
> Feb 16, 2016 7:24:17 PM 
> com.google.appengine.tools.development.DevAppServerImpl doStart
> INFO: Dev App Server is now running
> Feb 16, 2016 7:24:21 PM com.google.api.server.spi.SystemServiceServlet init
> INFO: SPI restricted: true
>
> I'm using app engine SDK 1.9.20. Please help me out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/bd541507-156f-4cb2-a912-4af1a7ba69b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to