当前位置: 首页 > 面试题库 >

无法在REST / JERSEY中调用@DELETE Web服务

魏晨
2023-03-14
问题内容

我正在使用Jersey框架(JAX-RS实现)来构建RESTful Web服务。

我无法使用@DELETE REST方法,因为当我尝试调用它时会抛出异常。以下@DELETE方法用于删除Employee:

@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)

如果有人可以指导我解决该问题,那将是很好的?


问题答案:

对我来说,它有助于从客户端的delete()方法中删除输入参数

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

并通过@pathParam发送:

public String delete(@PathParam("input") String input){...}


 类似资料:
  • 我用Jersey REST webservice创建了一个应用程序Struts2,当执行URL时,Struts2应用程序运行良好,但REST webservice不工作 我得到了 没有为命名空间/resources/users/name和操作名manu映射的操作。-“未知位置” 因为我使用的是Struts2.1.6,所以Struts的版本会导致任何问题吗? 有谁能告诉我一些解决办法吗 : : :

  • 问题内容: 我使用球衣JAX-Rs作为Web服务来查询mysql。我尝试通过混合移动应用程序使用Web服务。 我指的是这个 http://coenraets.org/blog/2011/11/building-restful-services-with-java- using-jax-rs-and-jersey-sample- application/#comment-440541 在服务器端,以

  • 我使用CXF、REST服务和Apache Camel实现了以下API。 http://localhost:9090/api/compute http://localhost:9091/api/listaction null IllegalArgumentException:无效的URI:/API/ListAction/API/ListAction。如果您正在转发/桥接httpendpoint,则在

  • 这是我的spring控制器类KalamController Hibernate配置xml文件 EmployeeServiceImpl.Java档案 最后是 当我运行程序时,我得到以下错误 请告诉我哪里出了问题。我是否忘记了xml文件中的任何配置?我的意图是了解如何使用@AutoWired注释在controller中调用服务。

  • 资源 ComplexObject类只是一个带有字符串的类。当我点击URL:http://localhost:8080/simple-service-webapp/webapi/myresource/This work时,我得到的是“get it!” 但是当我点击:http://localhost:8080/simple-service-webapp/webapi/myresource/comple

  • 我需要根据以下场景格式化restful服务的输出(xml) 我有一个键值对如下的类。 假设我有这样的列表,由rest服务返回: 我想生成如下输出 但目前它提供了以下输出 有人能告诉我如何做到这一点吗?