Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Rest删除错误请求_Java_Rest_Extjs_Http Delete - Fatal编程技术网

Java Rest删除错误请求

Java Rest删除错误请求,java,rest,extjs,http-delete,Java,Rest,Extjs,Http Delete,你能解释一下为什么DELETE方法(Edit.js中的store.remove())抛出400个错误请求吗。其他方法效果很好。在标头中,请求url似乎是“ok” 我知道问题出在DELETE方法的有效负载中,store.remove()包含ID作为有效负载。我如何禁用它并发送没有正文的DELETE方法,因为ID已经在URL中了 休息服务 @Path("/notes") public class NoteRestService { @Context private UriInfo uriInfo;

你能解释一下为什么DELETE方法(Edit.js中的store.remove())抛出400个错误请求吗。其他方法效果很好。在标头中,请求url似乎是“ok”

我知道问题出在DELETE方法的有效负载中,store.remove()包含ID作为有效负载。我如何禁用它并发送没有正文的DELETE方法,因为ID已经在URL中了

休息服务

@Path("/notes")
public class NoteRestService {
@Context
private UriInfo uriInfo;
@Context
private HttpServletRequest request;



private NoteDaoImpl noteDao = new NoteDaoImpl();
@GET
@Produces("application/json")
public String getNotes(){
    String login = request.getSession(true).getAttribute("login").toString();
    List<Note> notes = noteDao.getUserNotes(login);
    return new Gson().toJson(notes);
}

@POST
@Consumes("application/json")
public Response postNote(Note note){
    String login = request.getSession(true).getAttribute("login").toString();
    note.setUser(login);
    noteDao.persist(note);
    URI noteUri = uriInfo.getAbsolutePathBuilder().path(Long.toString(note.getId())).build();
    return Response.created(noteUri).build();
}

@PUT
@Path("{id}")
@Consumes("application/json")
public Response updateNote(@PathParam("id") String id,Note note){
    String login = request.getSession(true).getAttribute("login").toString();
    Note editNote = noteDao.getNote(Long.parseLong(id));
    note.setCreated(editNote.getCreated());
    note.setUser(login);
    noteDao.update(note);
    return Response.ok().build();
}

@DELETE
@Path("{id}")
public Response deleteNote(@PathParam("id") String id){
    Note note = noteDao.getNote(Long.valueOf(id));
    if (note==null){
        throw new NotFoundException();
    }
    noteDao.delete(Long.parseLong(id));
    return Response.noContent().build();
}
}
UPD:Store

Ext.define('MVC.store.TestStore', {
extend: 'Ext.data.Store',

requires: [
    'MVC.model.Note'
],

storeId: 'TestStore',
model: 'MVC.model.Note',
autoLoad: false,
proxy: {
    type: 'rest',
    url: 'rest/notes',
    actionMethods: {
        create: 'POST',
        read: 'GET',
        update: 'PUT',
        destroy:' DELETE'
    },
    reader: {
        type: 'json',
        rootProperty: 'data'
    },
    writer: {
        type: 'json',
        writeAllFields: true
    }
}
});

如果TestStore是您正在使用的存储,我猜您的问题在这里:

我无法识别@DELETE注释,因此我不能100%确定,但如果您的控制器希望删除,并且您正在发送GET,这可以解释400错误。

您不能使用带有主体的HttpMethod.DELETE

RFC中没有明确说明这一点,但如果在delete方法中有一个主体,则某些代理服务器将拒绝该主体。Spring降低了标准,并将以错误请求拒绝您的查询

移除主体以及解决问题的答案

有关更多信息,请查看此项:

你能发布你的商店和代理配置吗?不,因为这个问题,我已经将DELETE改为GET。GET可以工作,但如果有DELETE则不行。可能是writeAllFields的错误。您是否尝试过删除它以查看它是否解决了删除问题?
Ext.define('MVC.store.TestStore', {
extend: 'Ext.data.Store',

requires: [
    'MVC.model.Note'
],

storeId: 'TestStore',
model: 'MVC.model.Note',
autoLoad: false,
proxy: {
    type: 'rest',
    url: 'rest/notes',
    actionMethods: {
        create: 'POST',
        read: 'GET',
        update: 'PUT',
        destroy:' DELETE'
    },
    reader: {
        type: 'json',
        rootProperty: 'data'
    },
    writer: {
        type: 'json',
        writeAllFields: true
    }
}
});
actionMethods: {
    create: 'POST',
    read: 'GET',
    update: 'PUT',
    destroy: 'GET'
},