使用Google Eclipse插件干扰Google Cloud Endpoints

时间:2021-01-04 20:21:33

I am experiencing a strange behavior while generating endpoints using the Google Appengine Eclipse plugin. I have an endpoint class with over 20 endpoint methods. When I first tried generating the endpoints for android I get the error

使用Google Appengine Eclipse插件生成端点时,我遇到了一种奇怪的行为。我有一个端点类,有超过20个端点方法。当我第一次尝试为android生成端点时,我得到了错误

 Generating Cloud Endpoint has encountered errors and is not complete

By way of troubleshooting, I comment out all the methods to find the culprits. What I found is a bit baffling. After uncommenting the 16th method, I get the error again. There are two methods that are interfering with each other! If I comment out one or the other the endpoint is generated fine. But if I have both uncommented, I get the error above.

通过故障排除,我注释掉所有找到罪魁祸首的方法。我发现有点莫名其妙。取消注释第16个方法后,我再次收到错误。有两种方法相互干扰!如果我注释掉一个或另一个端点生成正常。但如果我同时取消注释,我会得到上面的错误。

Does anyone know what may be causing this interference?

有谁知道可能导致这种干扰的原因是什么?

@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;
}

I have edited the methods down to their stubs as shown above and still get the same interference problem.

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

1 个解决方案

#1


34  

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

首先,当您收到有关令人讨厌的不良消息的错误时:

Generating Cloud Endpoint has encountered errors and is not complete

生成Cloud Endpoint遇到错误但未完成

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:

所以,问题是你的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 {
    //...
}

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:

注意:由于您没有为方法设置路径,因此GPE会自动生成它们。似乎GPE为这两种方法生成相同的路径,用于形成HTTP方法(POST)和返回值(facelist)的路径,这与Google Cloud Endpoints文档中的内容不一致:

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

“path:用于访问此方法的URI路径。如果未设置此路径,则根据Java方法名称使用默认路径。”

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.

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

#1


34  

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

首先,当您收到有关令人讨厌的不良消息的错误时:

Generating Cloud Endpoint has encountered errors and is not complete

生成Cloud Endpoint遇到错误但未完成

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:

所以,问题是你的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 {
    //...
}

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:

注意:由于您没有为方法设置路径,因此GPE会自动生成它们。似乎GPE为这两种方法生成相同的路径,用于形成HTTP方法(POST)和返回值(facelist)的路径,这与Google Cloud Endpoints文档中的内容不一致:

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

“path:用于访问此方法的URI路径。如果未设置此路径,则根据Java方法名称使用默认路径。”

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.

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