开发者

REST WebService to serve images dynamically?

Consider 3 Jpeg files

  • image1.jpg
  • image2.jpg
  • image3.jpg

For a given URL and a set of parameters, I would like the s开发者_如何学Cerver to select and return one of those images.

I'm working in a JEE6 environment. What approach would you recommend?

  • A JSF redirect?
  • A REST WebService?
  • A good old servlet?
  • ... ?

Any suggestions welcome!


This is what I brewed so far:

import org.apache.commons.io.IOUtils;

@Path("/item")
public class MyResource {

  @GET
  @Path("/object/{id}")
  @Produces("image/jpeg")
  public byte[] getImageRepresentation(@PathParam("id") int id) {
     byte[] bytes = null;
     switch (id) {
        case 1: bytes = IOUtils.toByteArray(this.getClass().getResourceAsStream("/img/image01.jpg"));break;
        case 2: bytes = IOUtils.toByteArray(this.getClass().getResourceAsStream("/img/image02.jpg"));
      }
      return bytes;
  }

}

Still curious about alternative approaches! Thank you! J. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜