W
W
wikiwana2018-01-16 15:42:32
Java
wikiwana, 2018-01-16 15:42:32

Why is the DELETE request being ignored?

There is a Dynamic Web Project - Java EE7 REST API project on eclipse.
Implemented it with Jersey and Tomcat 8.5 server. Everything works, but it was required to run it easier using mvn exec:java:(
I downloaded Apache Maven 3.5.2, without thinking I did this:

mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false -DgroupId=com.wkwn -DartifactId=rest-example-Dpackage=com.wkwn.rest.example -DarchetypeVersion=2.22.2

I also tried mvn clean compileit mvn installin the created folder rest-example .
Then I opened this folder in IntellIj IDEA, uncommented the line for json support in pom.xml, added my .java files from the old project on eclipse to the project, tweaked something, and made a marathon.
Launch.
I send requests: GET, POST and PUT work perfectly, correctly, and DELETE does not seem to see at all, but it is there! It is also in the generated localhost:8080/ application.wadl file.
It's just that the DELETE request receives an empty response "Response 400 Bad Request" (I send requests to RESTer - a browser extension).
If anything, then here is the request DELETE function:
@DELETE
    @Produces(MediaType.APPLICATION_JSON)
    public Response deleteNote(Note note) {
        if (note.getId() == null)
            return MyResponse.badNullId();
        else if (NoteArray.removeNoteById(note.getId()))
            return MyResponse.goodDelete(note.getId());
        else
            return MyResponse.badNotFoundId(note.getId());
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wikiwana, 2018-01-16
@wikiwana

server.getServerConfiguration().setAllowPayloadForUndefinedHttpMethods(true);

S
Sergey Gornostaev, 2018-01-16
@sergey-gornostaev

Oh hey, a DELETE request with a body! Do not do it this way.

@DELETE @Path("{id}")
public Response deleteNote(@PathParam Long id) {
    if (NoteArray.removeNoteById(id))
        return MyResponse.goodDelete(id);
    else
        return MyResponse.badNotFoundId(id);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question