Mike Watson wrote:
Hi Folks,

I'm trying to figure out how to return binary data from the REST plugin.

I'd like to be able to return images that are generated on the fly by
a REST request but looking at ContentTypeHandlerManager, it assumes
that we'll only ever want to return a string and so passes a
StringWriter as the output for implementers of
ContentTypeHandler.fromObject.


At first, don't create a custom ContentTypeHander.
Just have your Controller declare a StreamResult. The default ContentTypeHandler will drop through for result processing by XWork (as per a ServletRedirectResult).

eg. GET /namespace/image/21

@Result("stream", type = StreamResult.class, value="image")
class ImageController {
  public InputStream getImage() {}

 public String show() {
    // create the stream
return "stream"; }
}

See StreamResult for how to set the Content-type and other properties.

One that works, you could (potentially) register a ContentTypeHandler for each image content type you want to return (eg. register the jpg and png extensions). The ContentTypeHandler should do nothing except return a result name for XWork that is mapped to a StreamResult. The image retrieval would have to be performed in the Controller rather than the Handler though. There is probably a bit of work to do in the plugin to handle binary results better though.

Hope that gets you started.
Jeromy Evans



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to