我有一个编译良好的 App-Engine 应用程序,我使用本地主机上的 Google APIs Explorer 测试方法调用(https://developers.google.com/apis-explorer/?base=http://localhost:8888/_ah /api#p/)它工作正常,我可以使用 API 资源管理器界面测试我的 api 方法,但是只要我添加一个新的 Apimethod,比如
@ApiMethod(name = "users.insertrandomuserv4")
public User insertrandomuserv4() {
User user = new User("234","myfirstname","mysecondname");
return user;
}
我在本地重新部署了我的应用程序,Apis Explorer 没有向我显示不同 api 方法的列表。为什么?(仅供参考:当我删除新方法时,它会再次起作用)
编辑:这是我的课程的其余部分(是的,我使用 PersistentManager 和 DataStoreService 但它只是用于测试):
public class UserEndpoint {
@ApiMethod(name = "users.get")
public User get(@Named("key") String key) {
//Key k = KeyFactory.createKey(User.class.getSimpleName(), key);
PersistenceManager pm = getPersistenceManager();
User user = pm.getObjectById(User.class, key);
pm.close();
return user;
}
@ApiMethod(name = "users.list")
public List<User> list() {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Query query = new Query("User");
//query.setKeysOnly();
PreparedQuery pq = datastore.prepare(query);
List<Entity> ls = pq.asList(FetchOptions.Builder.withLimit(500));
List<User> flist = new ArrayList<User>();
for (Entity user : ls) {
User u = new User(user);
flist.add(u);
}
return flist;
}
@ApiMethod(name = "users.insert")
public User insert(User user) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Entity ent = user.toEntity();
datastore.put(ent);
return user;
}
@ApiMethod(name = "users.insertrandomuserv4")
public User insertrandomuserv4() {
User user = new User("234","myfirstname","mysecondname");
return user;
}
@ApiMethod(name = "users.getuserswithsamehometown")
public List<User> getUsersWithSameHometown(@Named("home")String home) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Query query = new Query("User");
//query.addProjection(new PropertyProjection("firstname", User.class));
query.setFilter(new Query.FilterPredicate("hometown",FilterOperator.EQUAL,home));
PreparedQuery pq = datastore.prepare(query);
List<Entity> ls = pq.asList(FetchOptions.Builder.withLimit(500));
List<User> flist = new ArrayList<User>();
for (Entity ent : ls) {
User u = new User(ent);
flist.add(u);
}
return flist;
}
private static PersistenceManager getPersistenceManager() {
return JDOHelper.getPersistenceManagerFactory("transactions-optional").getPersistenceManager();
}
}