Chillax Chillax - 1 year ago 251
Java Question

Not able to invoke an @DELETE web service in REST/JERSEY

I am using Jersey Framework (JAX-RS implementation) for building RESTful Web Services.

I'm not able to use the @DELETE REST method, since its throwing an exception when I try to invoke it.The following @DELETE method is used to delete an Employee:

public class EmpResource {

public Response deleteEmployee(JAXBElement<String> r) throws ClassNotFoundException, SQLException {

String name = r.getValue();
String response = DAOaccess.deleteEmp(name);
return Response.noContent().build();


And I'm using the following block of code to invoke the service:

Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/RestApp/sample/employees");
String input = "{\"name\":\"John\"}";
ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).delete(ClientResponse.class,input);

When I run my client, it throws the following exception:

Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: HTTP method DELETE doesn't support output
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(
at com.sun.jersey.api.client.Client.handle(
at com.sun.jersey.api.client.WebResource.handle(
at com.sun.jersey.api.client.WebResource.access$200(
at com.sun.jersey.api.client.WebResource$Builder.delete(

It would be great if someone could guide me on how to resolve it?

Answer Source

For me it helped to remove input parameter from delete() method on client

ClientResponse response = webResource.type(MediaType.APPLICATION_JSON).delete(ClientResponse.class);

and send it over @pathParam instead:

public String delete(@PathParam("input") String input){...}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download