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 in response?
Thanks @Robert for the directions. Here's the 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(); }
PeterMmm
source share