Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get status for a PUT request on Jersey client

I have a webservice defined with Jersey in the server side like this:

@POST
@Consumes(MediaType.APPLICATION_XML)
@Path("/foo")
public Response bar(List<Foo> listFoo) {    
 try {
        //save the resource
        } catch (Exception e) {
        log.error("Error saving", e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
    }
    return Response.status(Status.OK).build();
}

I am trying to get the server status in my Jersey client like this:

Response response = ws.type(MediaType.APPLICATION_XML).post(Response.class,list);

But I get the error:

A message body reader for Java class javax.ws.rs.core.Response, and Java type class javax.ws.rs.core.Response, and MIME media type application/xml was not found javax.ws.rs.core.Response

I don't really need the Response object, just the status code, how could I get it?

like image 924
Eugenio Cuevas Avatar asked Jun 07 '12 16:06

Eugenio Cuevas


1 Answers

Ok, I solved it by changing the request response type:

Response response = ws.type(MediaType.APPLICATION_XML).post(Response.class,list);

with

ClientResponse response = ws.type(MediaType.APPLICATION_XML).post(ClientResponse.class,list);

being ClientResponse a com.sun.jersey.api.client.ClientResponse

like image 139
Eugenio Cuevas Avatar answered Oct 09 '22 01:10

Eugenio Cuevas