Skip to content

Commit

Permalink
Don't skip the handling and forwarding of 404 Responses with content …
Browse files Browse the repository at this point in the history
…to downstream WebServer filters (oracle#390) (helidon-io#512)

* Only skip the handling and forwarding of 404 Responses in io.helidon.webserver.jersey.ResponseWriter if there is no content
  • Loading branch information
Holubow authored and romain-grecourt committed Mar 19, 2019
1 parent b007881 commit f8802e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public OutputStream writeResponseStatusAndHeaders(long contentLength, ContainerR
//
// TODO also check that nothing was written an nothing was read
//
if (context.getStatus() == 404) {
if (context.getStatus() == 404 && contentLength == 0) {
whenHandleFinishes.thenRun(() -> {
LOGGER.finer("Skipping the handling and forwarding to downstream WebServer filters.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -204,4 +205,11 @@ public String pathEncoding1(@PathParam("id") String param) {
public String pathEncoding2(@PathParam("id") String param) {
return param;
}

@DELETE
@Path("notfound")
public Response deleteNotFound(@Context UriInfo uriInfo) {
throw new WebApplicationException(Response.status(404).entity("Not Found").build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ public void simplePostNotFound() throws Exception {
doAssert(response, "", Response.Status.NOT_FOUND);
}

@Test
public void notFoundResponse() throws Exception {
Response response = delete("jersey/first/notfound");

doAssert(response, "Not Found", Response.Status.NOT_FOUND);
}

/**
* In this test, we need to properly end the connection because the request data won't be fully consumed.
*/
Expand Down Expand Up @@ -307,6 +314,12 @@ private Response post(String path) {
.post(Entity.entity("my-entity", MediaType.TEXT_PLAIN_TYPE));
}

private Response delete(String path) {
return webTarget.path(path)
.request()
.delete();
}

private void doAssert(Response response, String expected) {
try {
assertEquals(Response.Status.Family.SUCCESSFUL, response.getStatusInfo().getFamily(),
Expand Down

0 comments on commit f8802e9

Please sign in to comment.