When you return an error status, Jersey delegates the response to your container's error processing via sendError
. When sendError
is called, the container will serve up an error page. This process is outlined in the Java Servlet Specification §10.9 Error Handling.
I suspect what you are seeing is your container's default error page for a 405 response. You could probably resolve your issue by specifying a custom error page (which could be empty). Alternatively, Jersey won't use sendError
if you provide an entity in your response. You could give it an empty string like this:
@POST
@Path("/path")
public Response createNullEntity() {
return Response.status(405).entity("").build();
}
The above results in Content-Length
of 0