Java 将API方法添加到应用程序引擎会导致NullPointerException
我正在使用本地应用程序引擎,并且我有一个工作端点,但是当我添加以下API时,当JavaScript控制台有一个未处理的异常时,API Explorer()不会加载Java 将API方法添加到应用程序引擎会导致NullPointerException,java,google-app-engine,rest,google-cloud-endpoints,Java,Google App Engine,Rest,Google Cloud Endpoints,我正在使用本地应用程序引擎,并且我有一个工作端点,但是当我添加以下API时,当JavaScript控制台有一个未处理的异常时,API Explorer()不会加载 @ApiMethod(name = "getClientByPublicId") public Client getClientByPublicId(@Named("publicId") String publicId) { EntityManager mgr = getEntityManager(); Client
@ApiMethod(name = "getClientByPublicId")
public Client getClientByPublicId(@Named("publicId") String publicId) {
EntityManager mgr = getEntityManager();
Client client = null;
client = mgr.find(Client.class, publicId);
mgr.close();
return client;
}
在ChromeJavaScript控制台中,它没有提供任何有用的东西,因为它被最小化了
Uncaught java.lang.NullPointerException
(anonymous function)
(anonymous function)
h
(anonymous function)
F.(anonymous function).z.(anonymous function).z.(anonymous function)
_.T.K.__cb
h
c
整个API浏览器页面都是空白的
我已经在调试模式下运行了它,并在添加的API中设置了一个断点,但它没有被触发
如果我在http://localhost:8888/_ah/api/discovery/v1/apis/clientendpoint/v1/rest
,它会失败,并出现以下响应
{
"error" : {
"message" : ""
}
}
如果我删除了这个新的API,尽管没有新的API,但一切都很好
有人知道这是什么原因吗
更新
我无意中发现了,听起来可能有路径冲突,我还不明白,但我现在要尝试这个想法
如果这可能是一个问题,相关的API是
@ApiMethod(name = "getClient")
public Client getClient(@Named("id") Long id) {
EntityManager mgr = getEntityManager();
Client client = null;
try {
client = mgr.find(Client.class, id);
} finally {
mgr.close();
}
return client;
}
我会尝试一下并回答我的问题,除非有人知道不同的情况。找到后,我了解到您必须包含一条新路径
例如,我能够将ApiMethod更改为
现在效果很好
@ApiMethod(
name = "getClientByPublicId",
path = "client/publicId/{publicId}",
httpMethod = "GET"
)