我的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调用它时,它可以正常工作并从DB中删除条目。
http://localhost:8080/backend/api/node
带标题
auth_token: 4F+qKpd58rU
和Param:
{ "id" : "0121387b-c0c0-4452-bf45-cfc4770e3b6b" }
但是当从角度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);
});
},
DAO:
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);
});;
}
};
});
答案 0 :(得分:2)
DELETE
方法无法接受机构。它们不会通过HTTP发送,也不会被服务器使用。