@GET @Path("{objectid}") public Response getImage( @PathParam("objectid") String objectId, @HeaderParam("If-Modified-Since") String modified) { GridFSDBFile mongoFile = imageRepository.getImage(objectId); if (mongoFile != null) { if (modified != null) { if (new Date(modified).before(mongoFile.getUploadDate())) { return Response.status(Status.NOT_MODIFIED).build(); } } return Response.ok(mongoFile.getInputStream(), mongoFile.getContentType()) .lastModified(mongoFile.getUploadDate()) .build(); } return Response.status(Status.NOT_FOUND).build(); }