API Explorer not showing the methods.

192 views
Skip to first unread message

Deepesh Mathuria

unread,
Feb 16, 2016, 9:15:14 AM2/16/16
to Google App Engine





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
<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.


tiger

unread,
Feb 16, 2016, 11:28:28 AM2/16/16
to Google App Engine

How do I use Explorer with a local HTTP API?


2016年2月16日火曜日 23時15分14秒 UTC+9 Deepesh Mathuria:

Deepesh Mathuria

unread,
Feb 17, 2016, 12:06:34 PM2/17/16
to Google App Engine
Thanks man, it worked. Actually I'd seen this solution earlier, but I was setting the flags in the wrong place, that's why it didn't work in the first place.  
Reply all
Reply to author
Forward
0 new messages