I have this service with RESTeasy:
@GET
@Path("/{name}")
@Produces("image/jpeg")
public BufferedImage get(@PathParam("name") String name) {
Monitor m = Monitor.getMonitor(name);
if (m == null) {
return null;
}
return m.getImage();
}
then I get after request
Could not find MessageBodyWriter for response object of type: java.awt.image.BufferedImage of media type: image/jpeg
Is there any "direct way" to get the image into the response ?
Thanks to @Robert for directions. Here working code:
@GET
@Path("/{name}")
@Produces("image/jpeg")
public byte[] get(@PathParam("name") String name) {
Monitor m = Monitor.getMonitor(name);
if (m == null) {
return null;
}
ByteArrayOutputStream bo = new ByteArrayOutputStream(2048);
try {
ImageIO.write(m.getImage(),"jpeg",bo);
} catch (IOException ex) {
return null;
}
return bo.toByteArray();
}
You should try to
BufferedImage
as JPG. Take a look at class javax.imageio.ImageIO
byte[]
java.awt.headless=true
(i.e. no graphics subsystem)Please let us know if that works, cause I have no idea if it will and can't try it myself right now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With