Hi
I've looked at BufferedImage JavaDocs ant it appears that indeed, using StreamingOutput (which can be simpler than doing a custom
MessageBodyWriter) can offer the best option, at least for a start.
Ex.
@Path("/images")
public ImagesResource {
@Path("{id}")
public StreamingOutput getImage(@PathParam("id") int id) {
BufferedImage image = retrieveImage(id);
retrun new StreamingOutputImpl(image);
}
}
private static class StreamingOutputImpl implements StreamingOutput {
private BufferedImage image;
public StreamingOutputImplBufferedImage image ) {
this.image = image;
}
public void write(OutputStream output) throws IOException,
WebApplicationException {
// just guessing here :-), the idea is to stream the BufferdImage instance to
the output
ImageProducer ip = image.getImageProducer();
im.addImageConsumer(new ImageConsumerImpl(output));
ip.startProduction();
}
hope it helps, Sergey
Hello,
I am brand new to CXF and somewhat new to Java. I have a requirement to
write a REST webservice that returns a streamed image. My dynamically
created image is of type BufferedImage. I don't want to persist the image
but simply stream it to the browser. Can anyone help guide me down the
right path?
I'm able to write the REST webservice, but I'm unsure what annotations to
use and what return type to specify on my REST webservice method. I've
looked over the forum a bit and it looks like I should attempt to use the
StreamingOutput class, but the implementation details are a little vague.
Any guidance would be greatly appreciated!
-Colin
--
View this message in context:
http://old.nabble.com/Return-an-Image-from-a-REST-webservice-api-tp26160563p26160563.html
Sent from the cxf-user mailing list archive at Nabble.com.