Java – Jersey client response status 204

I am using Jersey service and client When I try to call the service, I receive this error:

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)

I don't understand why

This is a service:

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

This is the customer:

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

I really don't know what the problem may be I know another problem, seemingly the same theme, but they are not

If I miss something or you need any additional information, please let me know

Solution

204 is the HTTP response status code, which notifies the client that there is no content returned

JSONArray array = new JSONArray(); // should fix the issue :)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>