Method interference in Google Cloud Endpoints with Google Eclipse Plugin
Asked Answered
T

1

9

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

 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.

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.

Teriteria answered 8/6, 2013 at 19:33 Comment(0)
W
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.

Weswesa answered 9/6, 2013 at 0:47 Comment(3)
Wow! I hope your reply gets a LOT! of up votes. Window -> Show View -> Error Log alone is amazing! Thank you so much! +1 and Check! When I asked that question I actually had no hope of getting an answer. I just asked anyway since I was completely stuck.Teriteria
No problem @learner, I'm happy it helped! I had already suggested that trick before (#15946054) And in fact it was [at]bossylobster who suggested it to me (#15685337) As for the upvotes I'd like that, but I don't think so, since these tags don't have too much followers :)Weswesa
Complementing: cloud.google.com/appengine/docs/java/endpoints/…Earthbound

© 2022 - 2024 — McMap. All rights reserved.