9

我在使用 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;
}

如上所示,我已将方法编辑到它们的存根,但仍然遇到相同的干扰问题。

4

1 回答 1

34

Firstly, when you get an error with that annoying undescriptive message:

Generating Cloud Endpoint has encountered errors and is not complete

you should check the Error Log under Window -> Show View -> Error Log to get more info.


I did so, and I found that the actual exception is:

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

So, the problem is that your 2 methods have the same path! Adding explicitly a path for your methods will solve the problem:

@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 {
    //...
}

NOTE: As you didn't set paths for your methods, GPE is generating them automatically. It seems that GPE is generating the same path for the 2 methods, using to form the path the HTTP method (POST) and the returned value (facelist), which doesn't correspond with what is said in 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."

It says that the path is automatically generated using the method name, and in that case you'd not getting any error, since your 2 methods have obviously different names. So I guess it must be a bug (as many others) in Endpoints.

于 2013-06-09T00:47:29.107 回答