500 Internal Server Error on one of my cloud endpoint methods when deployed

时光怂恿深爱的人放手 提交于 2019-12-19 04:26:20

问题


All of my Cloud Endpoints methods work locally, and all but one work when the app is deployed. Here is the method:

@ApiMethod(name = "listUrl", path ="article/urls", httpMethod = HttpMethod.GET)
public String[] listUrl() {
    List<Article> articles = getArticleList();
    String[] urlArray = new String[articles.size()];
    int i = 0;
    for (Article article : articles)
        urlArray[i++] = article.getUrl(); 
    return urlArray;
}

I know that the three accepted return types are "a POJO, an array or a Collection." But I thought that perhaps the String[] was causing the error, so tried returning a collection of Strings instead.

@ApiMethod(name = "listUrl", path ="article/urls", httpMethod = HttpMethod.GET)
public CollectionResponse<String>/*String[]*/ listUrl() {
    List<Article> articles = getArticleList();
    List<String> urls = new ArrayList<String>();
    //String[] urlArray = new String[articles.size()];
    //int i = 0;
    for (Article article : articles)
        urls.add(article.getUrl());
        //urlArray[i++] = article.getUrl(); 
    return /*urlArray*/ CollectionResponse.<String> builder().setItems(urls).build();
}

But to no avail. I continue to get "500 Internal Server Error."

The most bizarre part is that when I look at the logs in the admin console, it states that the request went through fine:
2013-09-22 22:08:00.715 /_ah/spi/com.example.hiserver.ArticleEndpoint.listUrl 200 55ms 0kb Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0

xx.xxx.xx.xxx(my IP) - - [22/Sep/2013:22:08:00 -0700] "POST /_ah/spi/com.example.hiserver.ArticleEndpoint.listUrl HTTP/1.1" 200 129 - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0" "hylyt-it.appspot.com" ms=56 cpu_ms=21 cpm_usd=0.000014 app_engine_release=1.8.4 instance=00c61b117cdf561948b997f4ec6be2ca72c139d1

回答1:


Based on willmas comment i fiddled around with my code and found out that you cannot use generics as return parameter. That actually makes sense when you think about how appengine should go about and serialize that stuff to json. Then again it doesn't when it works on local devserver. Anyhow, in my case i used a List which worked fine on local dev server but not when deployed. The solution was to create a

public class StringResult {
    private String result;
    /* getters and setters */ 
}

In your case you could use

public class StringArrayResult {
    private String[] result;
    /* getters and setters */
}

Thank you @willma for pointing into the right direction.



来源:https://stackoverflow.com/questions/18952299/500-internal-server-error-on-one-of-my-cloud-endpoint-methods-when-deployed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!