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?
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
Add @Consumes
annotation to your web-serivce and the parameter to your bar()
method, because you are trying to put there some object named list
.
And I would recommend you to use @POST
instead, because canonical @PUT
does not return a response.
UPD. By the way, you have your entity empty - you should better remove your @Produces
annotation and just return Response
with its status set.
UPD2. and remove .accept(MediaType.APPLICATION_XML)
method from client side.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.