Google Cloud Endpoints从随机API版本返回值

时间:2022-04-17 19:40:16

I've create a simple API with Google Cloud Endpoints. Now, I want to create a new version for this API.

我已经使用Google Cloud Endpoints创建了一个简单的API。现在,我想为此API创建一个新版本。

I have the following classes:

我有以下课程:

@Api(name = "helloworld",
    version = "v1")
public class HelloWorldApi {
    @ApiMethod(name = "sayHello", path = "/sayHello", httpMethod = "get")
    public HelloWorld SayHello(){
        return new HelloWorld("Hello World v1");
    }
}

and

@Api(name = "helloworld",
    version = "v2")
public class HelloWorldApiV2 {
    @ApiMethod(name = "sayHello", path = "/sayHello", httpMethod = "get")
    public HelloWorld SayHello(){
        return new HelloWorld("Hello World v2");
    }
}

I then deploy and go to [myapplication].appspot.com/_ah/api/explorer. Here, I can see both versions in "All Versions" with "v2" as the default.

然后我部署并转到[myapplication] .appspot.com / _ah / api / explorer。在这里,我可以在“所有版本”中看到两个版本,默认为“v2”。

The problem is that it doesn't matter which one I use. They both return either "Hello World v1" or "Hello World v2" randomly.

问题是我使用哪一个并不重要。他们都随机返回“Hello World v1”或“Hello World v2”。

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


1  

Turns out that the problem was related to the path. I removed the path element from the api definition in both versions and it works fine.

事实证明问题与路径有关。我在两个版本中从api定义中删除了path元素,它工作正常。

I can now see that the calls are being made to http://localhost:8888/_ah/api/helloworld/v1/SayHello and http://localhost:8888/_ah/api/helloworld/v2/SayHello respectively. I guess the hard coded path removed the /v1 and /v2 and both versions would be called at the same time, returning only one of them.

我现在可以看到调用分别是http:// localhost:8888 / _ah / api / helloworld / v1 / SayHello和http:// localhost:8888 / _ah / api / helloworld / v2 / SayHello。我猜硬编码路径删除了/ v1和/ v2,两个版本将同时被调用,只返回其中一个版本。

#1


1  

Turns out that the problem was related to the path. I removed the path element from the api definition in both versions and it works fine.

事实证明问题与路径有关。我在两个版本中从api定义中删除了path元素,它工作正常。

I can now see that the calls are being made to http://localhost:8888/_ah/api/helloworld/v1/SayHello and http://localhost:8888/_ah/api/helloworld/v2/SayHello respectively. I guess the hard coded path removed the /v1 and /v2 and both versions would be called at the same time, returning only one of them.

我现在可以看到调用分别是http:// localhost:8888 / _ah / api / helloworld / v1 / SayHello和http:// localhost:8888 / _ah / api / helloworld / v2 / SayHello。我猜硬编码路径删除了/ v1和/ v2,两个版本将同时被调用,只返回其中一个版本。