package org.col.dw.jersey.filter;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.net.HttpURLConnection;

/**
 * Filter that returns a 404 instead of 204 for null results with GET requests.
 */
public class Null404ResponseFilter implements ContainerResponseFilter {

  @Override
  public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException {
    if (!response.hasEntity()
          && request.getMethod() != null && "get".equalsIgnoreCase(request.getMethod())
          && (response.getStatusInfo() == null || response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL))
    ) {
      response.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
    }
  }
}

@@ -28,16 +28,54 @@
 ilter;%0A%0A
+import javax.ws.rs.NotFoundException;%0A
 import j
@@ -294,43 +294,8 @@
 ion;
-%0Aimport java.net.HttpURLConnection;
 %0A%0A/*
@@ -841,59 +841,36 @@
     
-response.setStatus(HttpURLConnection.HTTP_NOT_FOUND
+throw new NotFoundException(
 );%0A 

Throw exception instead of returning 404 manually to get the standard json