我的Jersey API如下:
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Result<String> delete(@HeaderParam(AUTH_TOKEN) String auth_token,
ParamBean bean) {
Node node = new Node();
node.setId(bean.getId());
service.deleteNode(auth_token, node);
return new Result("Deleted");
}
当我从Rest Client调用它时,它可以正常工作,并从数据库中删除该条目。
http://localhost:8080/backend/api/node
带头
auth_token: 4F+qKpd58rU
和参数:
{ "id" : "0121387b-c0c0-4452-bf45-cfc4770e3b6b" }
但是,当从angular js调用时,它返回410 Gone错误。
并且tomcat日志显示:
[http-bio-8080-exec-5] ERROR c.t.c.e.h.GlobalExceptionHandler - GlobalExceptionHandler: null
javax.ws.rs.WebApplicationException
at com.sun.jersey.server.impl.uri.rules.TerminatingRule.accept(TerminatingRule.java:66)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
Angular JS代码:
控制器功能:
params = {};
params.data = {
"id" : h.id
};
params.headers = {
auth_token : authService.session.token
};
hubService.remove(params,function(data,status){
alert(data);
});
服务内容:
remove: function(params,callback)
{
params.url = "http://localhost:8080/backend/api/node"
params.method="DELETE";
dao.call(params,function(data,status){
callback(data,status);
});
},
道:
angular.module('httpService',[]).service("dao",function($http){
return {
call: function(params,callback)
{
var httpSetting = {};
httpSetting.method = params.method;
httpSetting.url = params.url;
if(params.headers)
{
httpSetting.headers=params.headers;
delete params.headers;
}
if(params.method==="GET") {
httpSetting.params=params.data;
}
if(params.method==="POST") {
httpSetting.data = params.data;
}
if(params.method==="DELETE") {
httpSetting.data = params.data;
}
$http(httpSetting).success(function(data,status){
callback(data,status);
}).error(function(data,status){
callback(data,status);
});;
}
};
});
最佳答案
DELETE
方法不能带实体。它们不会通过HTTP发送,也不会被服务器使用。
关于java - 删除其余端点返回410 Gone,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27226615/