jjzjj

android - GoogleJsonResponseException : 500 Internal Server Error

coder 2023-12-24 原文

我编写了一个在本地环境中运行的小应用程序,没有任何问题,但是在我将该应用程序部署到 Google App Engibe 之后,它停止运行了。这是客户端的代码:

    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();

    }   

我可以在服务器端的日志中看到在 return 语句之前没有问题,因为 System.out 打印了我想要的响应。但是我在 eclipse 上收到以下错误,而且有趣的是 Google 应用引擎管理控制台上没有错误日志

com.google.api.client.googleapis.json.GoogleJsonResponseException:500 内部服务器错误:

未设置应用程序名称。调用生成器#setApplicationName。 com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 内部服务器错误 { “代码”:500, “错误”:[{ “域”:“全局”, “消息”:“内部错误”, “原因”:“内部错误” } ], “消息”:“内部错误” } 在 com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113) 在 com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(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)

谢谢,

我已经找到了解决方案,我希望它能帮助面临同样问题的人:)

只是您不能使用 String 作为返回值。而已。 尽管它可以在开发环境中正常工作,但在部署后(在 Google 生产环境中)将无法正常工作。 为此,我创建了两个单独的对象,一个用于 String,另一个用于 String[],名为 StringObject 和 StringArrayObject,每当我想返回数组或字符串时,我都会使用这些方法。

最佳答案

消息“未设置应用程序名称”表明在 AppEngine 内部,一个旨在包含应用程序 ID 的变量可能包含一个空值。正如@nebulae 评论的那样,要检查的地方是 appengine-web.xml。但是应用程序已部署,因此应用程序 ID 可能不为空。在 Eclipse 中,要查看的位置当然是项目属性 -> Google -> AppEngine -> 部署。

问题第一句中的某些文本已损坏并提示字符集存在问题:“Google App Ebgşbe”而不是“Google App Engine”。现在,如果部署工作正常,但生产运行时崩溃,则应用程序 ID 中可能存在一些部署可以处理但运行时不能处理的字符。

因此,我建议您创建一个仅包含绝对安全字符的不同应用程序 ID,用它更新项目属性,然后再次尝试部署和运行。

关于android - GoogleJsonResponseException : 500 Internal Server Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22284544/

有关android - GoogleJsonResponseException : 500 Internal Server Error的更多相关文章

随机推荐