Google APis Explorer从我的应用程序引擎应用程序中找不到我可用的ApiMethod [英] Google APis Explorer didn't found my available ApiMethod from my app-engine app

查看:88
本文介绍了Google APis Explorer从我的应用程序引擎应用程序中找不到我可用的ApiMethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个App-Engine应用程序,可以很好地进行编译,并且我可以使用localhost上的Google Apis Explorer(

I have an App-Engine app that compile fine and i test the methods calls using the Google Apis Explorer on localhost (https://developers.google.com/apis-explorer/?base=http://localhost:8888/_ah/api#p/) It works fine and i can test my api method using the Apis Explorer interface but as soon as i add a new Apimethod like

@ApiMethod(name = "users.insertrandomuserv4")
public User insertrandomuserv4() {
    User user = new User("234","myfirstname","mysecondname");
    return user;
}

并且我在本地重新部署了我的应用程序,Apis Explorer没有向我显示其他api方法的列表. 为什么? (供参考:当我删除新方法时,它又可以工作了)

and i redeploy locally my application, the Apis Explorer didn't show me the list of the different api method. Why? (FYI:When i remove the new method, it works again)

这是我课程的其余部分(是的,我使用PersistentManager和DataStoreService,但仅用于测试):

Here is the rest of my class(yes I use PersistentManager and DataStoreService but it just for testing):

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();
}
}

推荐答案

是的,这里发生了路径冲突.从我对您的代码的审查中,我相信有两个冲突:users.getusers.getuserswithsamehometown碰撞,而users.insertusers.insertrandomuserv4碰撞.

Yeah, there are path collisions going on here. From my review of your code, I believe there are two collisions: users.get collides with users.getuserswithsamehometown and users.insert collides with users.insertrandomuserv4.

您使用的命名约定可以防止API客户端库中的冲突,但不能防止用于调用API的实际路径中的冲突.例如,两个.get调用都映射到GET users/{string},两个.insert调用都映射到POST users.

The naming conventions you are using prevent collisions in the API client libraries, but not in the actual paths used to call the APIs. For example, both .get calls map to GET users/{string} and both .insert calls map to POST users.

您应该做的是在每对冲突的方法之一中添加一个路径参数.例如,users.getuserswithsamehometown您可以更新为:

What you should do is add a path parameter to one of the conflicting methods in each pair. For instance, users.getuserswithsamehometown you could update to:

@ApiMethod(
  name = "users.getuserswithsamehometown",
  path = "users/hometown/{home}",
  httpMethod = "GET"
)

这将为该方法提供一条不再与您的其他users.get方法冲突的路径.您可以为冲突的.insert呼叫重复该过程,例如:

This will give the method a path that no longer conflicts with your other users.get method. You can repeat the process for your conflicting .insert calls, e.g.:

@ApiMethod(
  name = "users.insertrandomuserv4",
  path = "users/random/",
  httpMethod = "POST"
)

为了方便起见,我添加了httpMethod声明.在开始修改路径的其他部分时,通常最好声明它们.

I've added httpMethod declarations for good measure. It's generally a good idea to declare these when you start modifying other parts of the path.

这篇关于Google APis Explorer从我的应用程序引擎应用程序中找不到我可用的ApiMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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