2013-09-23 2 views
2

내 클라우드 엔드 포인트 방법의 모든 로컬 작업을 전개 할 때, 하나의 작업을하지만, 모든 응용 프로그램은 배포 될 때. 방법은 다음과 같습니다.500 내부 서버 오류가

@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; 
} 

3 가지 허용되는 반환 유형은 "POJO, 배열 또는 컬렉션"입니다. 하지만 아마도 String[]이 오류를 일으킨 것으로 생각하여 대신 String 개를 반환하려고 시도했습니다.

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

하지만 아무 소용이 없습니다. 나는 계속해서 "500 Internal Server Error"를 얻는다. willmas을 바탕으로

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 
+0

메소드에 몇 가지 [추가 로깅] (https://developers.google.com/appengine/articles/logging)을 추가하고 확인할 수 있습니다. –

+0

해당 메소드의 모든 단일 행에 로깅을 추가 했으므로 모든 것이 작동합니다 메서드 내에서 예상대로 나는 심지어 관리 콘솔 로그에서 200을 얻지 만 클라이언트 측에서는 오류 500을 표시합니다. – willlma

+0

그 이유는 Cloud Endpoints의 경우 [반환 값 유형이 String 또는 int와 같은 단순 유형이 될 수 없다는 것입니다. 반환 값은'POJO's **의 (POJO, 배열 또는 콜렉션) (https://developers.google.com/eclipse/docs/endpoints-addentities) (암묵적으로) **이어야합니다. – willlma

답변

0

난 내 코드 주변에 바이올린을 발견 코멘트 :

500: Internal Server Error 가장 이상한 부분은 내가 관리 콘솔에서 로그를 볼 때,이 요청이 잘 통해 갔다 상태이다 제네릭을 반환 매개 변수로 사용할 수 없습니다. Appengine이 어떻게 진행되어야 하는지를 생각하고 json에게 그러한 것들을 직렬화하면 실제로 의미가 있습니다. 그런 다음 다시 로컬 디스크 서버에서 작동합니다. 어쨌든, 제 경우에는 로컬 dev 서버에서는 잘 작동하지만, 배포 할 때는 List를 사용하지 않았습니다. 이 솔루션은

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

당신이 올바른 방향으로 가리키는 위해 @willma 감사 사용할 수 있습니다 귀하의 경우에서

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

을 만드는 것이 었습니다.

+0

걱정할 필요가 없습니다. 이것은 내가 결국 끝낸 것입니다. Google의 Dan Holevoet은 [제 질문 중 하나에 대한 답변] (http://stackoverflow.com/a/20196518/1720014)의 의견에 제네릭 컬렉션을 반환 할 수 없음을 확인했습니다. – willlma

관련 문제