Get Status for PUT Request on Jersey Client

I have a web service defined with server side jersey 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 server status from my client in Jersey as follows:

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 really don't need a Response object, just a status code, how can I get it?

+5
source share
2 answers

Ok, I solved this by changing the type of response to the request:

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

with

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

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

+4
source

Add the @Consumesannotation to your web serivce and parameter to your method bar(), because you are trying to put some kind of object named there list.

And I would recommend using it instead @POST, because canonical @PUTdoes not return a response.

UPD. , - @Produces Response .

UPD2. .accept(MediaType.APPLICATION_XML) .

+1

All Articles