I have a JAX-RS resource class that can return a 404 response when a certain request is made. Unfortunately, even though the operation's method is annotated @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
, a 404 Response object always results in Tomcat shoving its own "not found" HTML error page into the body.
This is breaking clients that expect XML/JSON responses. How do I shut Tomcat up in these cases?
My code looks like this now:
@GET
@Path("isbn/{isbn}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response isbn(@PathParam("isbn") String isbn) {
ProductSearchDO productSearch = ProductSvc.find( isbn );
if (productSearch == null)
return Responses.notFound().build();
return Response.ok( productSearch ).tag( String.valueOf( productSearch.hashCode() ) ).build();
}