Android GoogleJsonResponseException:500内部服务器错误
我编写了一个在本地环境下运行的小应用程序,没有任何问题,但在我将该应用程序部署到GoogleAppEngibe后,它停止了工作。以下是客户端的代码:Android GoogleJsonResponseException:500内部服务器错误,android,google-app-engine,Android,Google App Engine,我编写了一个在本地环境下运行的小应用程序,没有任何问题,但在我将该应用程序部署到GoogleAppEngibe后,它停止了工作。以下是客户端的代码: CollectionResponseLong asd = null; try { asd = getEndpoint().getClosePeople(id).execute(); } catch (IOException e1) { // TODO Auto-generated catch
CollectionResponseLong asd = null;
try {
asd = getEndpoint().getClosePeople(id).execute();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
我可以看到,它在服务器端也可以使用以下代码工作:
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "getClosePeople",path = "getClosePeople")
public CollectionResponse<Long> getClosePeople(@Named("id") Long id) {
PersistenceManager mgr = getPersistenceManager();
Cursor cursor = null;
List<Long> execute = null;
String cursorString = null;
Integer limit = null;
User user = mgr.getObjectById(User.class, id);
mgr = getPersistenceManager();
Query query = mgr.newQuery(User.class);
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
HashMap<String, Object> extensionMap = new HashMap<String, Object>();
extensionMap.put(JDOCursorHelper.CURSOR_EXTENSION, cursor);
query.setExtensions(extensionMap);
}
// query.setFilter("GeoHash == '" + user.getGeoHash() +"'" + " && Id != " + id);
query.setFilter("GeoHash == '" + user.getGeoHash() +"'" + " && Id != " + id);
query.setResult("Id");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
HashMap<String, Object> extensionMap = new HashMap<String, Object>();
extensionMap.put(JDOCursorHelper.CURSOR_EXTENSION, cursor);
query.setExtensions(extensionMap);
}
if (limit != null) {
query.setRange(0, limit);
}
execute = (List<Long>) query.execute();
cursor = JDOCursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();
for (Long obj : execute)
;
System.out.println("STRING " + execute.toString());
mgr.close();
System.out.println(CollectionResponse.<Long> builder().setItems(execute)
.setNextPageToken(cursorString).build().getItems().toString());
return CollectionResponse.<Long> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}
@SuppressWarnings({“未选中”、“未使用”})
@ApiMethod(name=“getClosePeople”,path=“getClosePeople”)
public CollectionResponse getClosePeople(@Named(“id”)长id){
PersistenceManager mgr=getPersistenceManager();
游标=空;
List execute=null;
字符串游标字符串=null;
整数限制=空;
User User=mgr.getObjectById(User.class,id);
mgr=getPersistenceManager();
Query Query=mgr.newQuery(User.class);
if(cursorString!=null&&cursorString!=“”){
cursor=cursor.fromWebSafeString(cursorString);
HashMap extensionMap=新的HashMap();
extensionMap.put(JDOCursorHelper.CURSOR\u扩展名,CURSOR);
setExtensions(extensionMap);
}
//query.setFilter(“GeoHash='”+user.getGeoHash()+“'”+“&&Id!=”+Id);
query.setFilter(“GeoHash='”+user.getGeoHash()+“'”+“&&Id!=”+Id);
query.setResult(“Id”);
if(cursorString!=null&&cursorString!=“”){
cursor=cursor.fromWebSafeString(cursorString);
HashMap extensionMap=新的HashMap();
extensionMap.put(JDOCursorHelper.CURSOR\u扩展名,CURSOR);
setExtensions(extensionMap);
}
如果(限制!=null){
query.setRange(0,限制);
}
execute=(List)query.execute();
cursor=JDOCursorHelper.getCursor(执行);
如果(光标!=null)
cursorString=cursor.towerbsafesting();
for(长对象:执行)
;
System.out.println(“字符串”+execute.toString());
经理关闭();
System.out.println(CollectionResponse.builder().setItems(执行)
.setNextPageToken(cursorString.build().getItems().toString());
return CollectionResponse.builder().setItems(执行)
.setNextPageToken(cursorString.build();
}
我可以在服务器端的日志中看到,在return语句之前没有问题,因为System.out打印了我想要的响应。但是我在eclipse上遇到了以下错误,有趣的是Google app engine管理控制台上没有错误日志
com.google.api.client.googleapis.json.googlejson响应异常:500内部服务器错误:
未设置应用程序名称。调用Builder#setApplicationName。
com.google.api.client.googleapis.json.googlejson响应异常:500内部服务器错误
{
“代码”:500,
“错误”:[{
“域”:“全局”,
“消息”:“内部错误”,
“原因”:“内部错误”
} ],
“消息”:“内部错误”
}
位于com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.NewExceptionError(AbstractGoogleJsonClientRequest.java:113)
位于com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.NewExceptionError(AbstractGoogleJsonClientRequest.java:40)
位于com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:312)
位于com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1045)
位于com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
位于com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
在com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)上
谢谢
我已经找到了解决方案,我希望它能帮助那些面临同样问题的人:)
简单地说,您不能使用字符串作为返回。就这样。
即使它在开发环境中工作没有任何问题,但在部署后(在Google生产环境中)也不会工作。
为此,我创建了两个独立的对象,一个用于字符串,另一个用于名为StringObject和StringArrayObject的String[],每当我想要返回数组或字符串时,我都会使用这些方法。消息“Application name is not set”(应用程序名称未设置)表明,在AppEngine内部,用于包含应用程序id的变量可能包含null。正如@nebulae所评论的,检查的地方应该是appengine-web.xml。但是,应用程序已部署,因此应用程序id可能不是空的。在Eclipse中,可以查看的地方当然是project Properties->Google->AppEngine->Deployment
问题第一句中的一些文字已损坏,并表明字符集存在问题:“谷歌应用程序Ebgşbe”而不是“谷歌应用程序引擎”。现在,如果部署工作正常,但生产运行时崩溃,那么应用程序id中可能有一些字符,部署可以处理,但运行时无法处理
因此,我建议您创建一个只包含绝对安全字符的不同应用程序id,用它更新项目属性,然后尝试重新部署和运行。我无法找到解决方案,因此我在
cloudEndpoint.getResult()方法上添加了3次重试。
每当它随机失败时,它主要在第二次重试时工作。appengine-web.xml文件中的应用程序id设置正确吗?我今天遇到了Google API 500错误,在等待了几个小时后又重新工作。