微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – Google Cloud Endpoints中使用Google Eclipse插件的方法干扰

在使用Google Appengine Eclipse插件生成端点时,我遇到了一个奇怪的行为.我有一个具有20个端点方法的端点类.当我第一次尝试为android生成端点时,我得到错误
Generating Cloud Endpoint has encountered errors and is not complete

通过故障排除,我会注释出所有的方法来找到罪魁祸首.我发现有点令人困惑取消注册第16个方法后,我再次收到错误.有两种方法相互干扰!如果我注释一个或另一个端点生成罚款.但是如果我没有注释,我会收到上面的错误.

有谁知道可能造成这种干扰?

@ApiMethod(name = "getorangers",httpMethod = HttpMethod.POST)
public FaceList getorangers(UserRequest request) throws NotFoundException {
    FaceList list = new FaceList();
    return list;
}

@ApiMethod(name = "getMangoers",httpMethod = HttpMethod.POST)
public FaceList getMangoers(UserRequest request) throws NotFoundException {
    FaceList list = new FaceList();
    return list;
}

我已经将方法编辑到他们的存根,如上所示,仍然得到相同的干扰问题.

解决方法

首先,当你发现这个令人讨厌的不必要的消息时出错:

Generating Cloud Endpoint has encountered errors and is not complete

您应该检查窗口下的错误日志 – >显示视图 – >错误日志获取更多信息.

我这样做,我发现实际的例外是:

java.lang.IllegalArgumentException: 
  Multiple methods with same rest path "POST facelist": "getorangers" and "getMangoers"

所以问题是你的2种方法有相同的路径!明确添加方法的路径将解决问题:

@ApiMethod(name="getorangers",path="get_oranges",httpMethod=HttpMethod.POST)
public FaceList getorangers(UserRequest request) throws NotFoundException {
    //...
}

@ApiMethod(name="getMangoers",path="get_mangoers",httpMethod=HttpMethod.POST)
public FaceList getMangoers(UserRequest request) throws NotFoundException {
    //...
}

注意:由于您没有为方法设置路径,因此GPE会自动生成.似乎GPE正在为2种方法生成相同的路径,用于形成HTTP方法(POST)和返回值(facelist)的路径,这与Google Cloud Endpoints Documentation中所说的不一致:

path: The URI path to use to access this method. If you don’t set
this,a default path is used based on the Java method name.”

它表示路径是使用方法名称自动生成的,在这种情况下,您不会收到任何错误,因为您的两个方法具有明显不同的名称.所以我想这在Endpoints中一定是一个bug(和许多人一样).

原文地址:https://www.jb51.cc/java/122429.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐