我正在使用 Jersey 框架(JAX-RS 实现)来构建 RESTful Web 服务。
我无法使用@DELETE REST 方法,因为当我尝试调用它时它会抛出异常。以下@DELETE 方法用于删除员工:
@Path("/employees")
public class EmpResource {
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
public Response deleteEmployee(JAXBElement<String> r) throws ClassNotFoundException, SQLException {
String name = r.getValue();
String response = DAOaccess.deleteEmp(name);
return Response.noContent().build();
}
我正在使用以下代码块来调用服务:
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);
当我运行我的客户端时,它会引发以下异常:
Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: java.net.ProtocolException: HTTP method DELETE doesn't support output
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.delete(WebResource.java:599)
如果有人可以指导我如何解决它会很棒吗?