【发布时间】:2014-05-14 20:28:40
【问题描述】:
我正在尝试使用 HTTP GET 方法:
curl http://localhost:8888/_ah/api/birra/v1/beer
它返回给我的当前列表是正常和预期的:
{
"items" : [ {
"id" : "1",
"beerName" : "Bud"
}, {
"id" : "2",
"beerName" : "Steve"
}, {
"id" : "3",
"beerName" : "Ankur"
} ]
}
但是当我像这样进行 HTTP POST 时:
curl -X POST -H "Content-Type: application/json" -H "Accept:application/json" -d "{\"beerName\": \"asdf\"}" http://localhost:8888/_ah/api/birra/v1/beer
它给我的错误是:
{
"error" : {
"message" : "javax.jdo.JDOFatalInternalException: The key value passed to construct a SingleFieldIdentity of type \"class javax.jdo.identity.LongIdentity\" for class \"class com.samples.Beer\" is null.\nNestedThrowables:\norg.datanucleus.exceptions.NucleusException: The key value passed to construct a SingleFieldIdentity of type \"class javax.jdo.identity.LongIdentity\" for class \"class com.samples.Beer\" is null.",
"code" : 503,
"errors" : [ {
"domain" : "global",
"reason" : "backendError",
"message" : "javax.jdo.JDOFatalInternalException: The key value passed to construct a SingleFieldIdentity of type \"class javax.jdo.identity.LongIdentity\" for class \"class com.samples.Beer\" is null.\nNestedThrowables:\norg.datanucleus.exceptions.NucleusException: The key value passed to construct a SingleFieldIdentity of type \"class javax.jdo.identity.LongIdentity\" for class \"class com.samples.Beer\" is null."
} ]
}
}
我目前正在研究提供的 Google Cloud Endpoints 示例: Cloud Endpoint by Google Developers
我正在使用 Eclipse IDE 和在 Jetty 上运行的服务器 localhost。
有什么解决办法吗?
【问题讨论】:
-
输入 JSON 中不需要
id吗? -
不,我在我的代码中使用“beerName”作为键,所以我将一个值作为“asdf”传递给它。你在哪里使用id?另外,请查看我提供的链接中的代码,它与教程中的内容相同。
-
只是一个疯狂的猜测.. 异常包含
javax.jdo.identity.LongIdentity。我认为LongIdentity意味着它必须与id相关,因为它必须是Javalong值 -
您确定即使不提供
id也会构造一个新的Beer对象?另外,据我了解您链接中的代码,我认为id是关键,而不是beerName。如果您看到getBeer服务端点,它正在接受id而不是beerName -
不,在 getBeer() 中,它所采用的 'id' 是从服务器检索数据。如果我们这样做: curl localhost:8888/_ah/api/birra/v1/beer/1 它将返回带有'id' = '1'的实体请查看insertBeer(),我只会在做 HTTP POST。 HTTP GET 工作正常。
标签: java google-app-engine curl jdo google-cloud-endpoints