2012-02-25 3 views
6

서비스 및 클라이언트 모두에 대해 Jersey를 사용하고 있습니다. 나는 서비스를 호출하려고 할 때,이 오류가 발생합니다 :Jersey 클라이언트 응답 상태 204

Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: GET http://localhost:8080/Maze/rest/service/overview?countryid=1 returned a response status of 204 No Content 
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:528) 
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:506) 
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:674) 
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) 
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:503) 
at com.maze.client.MyClient.overviewTest(MyClient.java:34) 
at com.maze.client.MyClient.main(MyClient.java:64) 

그 이유를 이해하지 않습니다. 여기

는 서비스 :

@GET 
@Produces(MediaType.APPLICATION_JSON) 
@Path("/overview") 
public JSONArray getOverviewEntities(@QueryParam("countryid")String id){ 
    JSONArray array = null; 
    try{ 
    Integer countryId = Integer.parseInt(id); 
    ArrayList<Event> list = new ArrayList<Event>(); 
    EventService event = new EventService(); 
    EntityManagerSingleton.getInstance().getTransaction().begin(); 
    list.addAll(event.getList(countryId, "country", 5)); 
    EntityManagerSingleton.getInstance().getTransaction().commit(); 
    for(Event ev : list){ 
     array.add(EventService.toJSONObject(ev)); 
    } 
    } catch(Exception e){ 
     e.printStackTrace(); 
    } 
    return array; 
} 

이 클라이언트입니다 :

public static void overviewTest(){ 
    WebResource wbr; 
    Client client = Client.create(); 
    wbr = client.resource("http://localhost:8080/Maze/rest/service/overview"); 
    JSONArray result = wbr.queryParam("countryid", "1").accept(MediaType.APPLICATION_JSON).get(JSONArray.class); 
    System.out.println(result.toString()); 
} 

정말 문제가 될 수있는 일에 대해 아무 생각이 없습니다. 나는 여기에 겉으로보기에는 똑같은 주제로 또 다른 질문을 알고 있지만, 그렇지 않다.

내가 누락되었거나 추가 정보가 필요한 경우 알려주십시오.

답변

6

204는 반환 된 내용이 없음을 클라이언트에 알리는 HTTP 응답 상태 코드입니다. 클라이언트가 get (JSONArray.class)를 호출하면 데이터가 200이므로 예외가 발생합니다. 서버 구현에서 배열 변수가 인스턴스화되지 않으므로 목록이 비어 있지 않으면 array.add()의 NPE가 될 가능성이 있지만이 경우 목록이 비어있는 것처럼 보이므로 루프가 반복되지 않고 getOverviewEntities 메소드가 null을 리턴하므로 204 결과.

JSONArray array = new JSONArray(); // should fix the issue :) 
+0

네, 문제가 해결되었습니다. 이제 상태 500 (내부 서버 오류)이 표시됩니다. 그러나 그것은 또 하나의 질문입니다. 고마워요! – Dragos

관련 문제