Is it possible to create a PNG image and output it straight to the browser as part of a JAX-RS resource?
Something like this:
@Path("img/{externalId}")
@Stateless
@Produces({"image/png"})
public class MyImgResource {
@GET
public Response (@PathParam("externalId") String externalId) {
// create image, write to buffered output stream
return Response.ok().entity(stream).build();
}
}
Would this work? Do I have to take care of the correct headers (Content-Type), or is this done by the @Produces
annotation? Can output an image as a Response
? Can I build a Response
from a stream?