views:

61

answers:

1

Consider 3 Jpeg files

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

For a given URL and a set of parameters, I would like the server 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!

A: 

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. :-)

Jan
Could you please go into details? I don't really understand you issue. What you have written seems fine to me, I would have done it the same way.
If you would have done it the same way, that's good information too. I wasn't even sure to use a WS in the first place (See initial Question). Thx.
Jan
Is this using spring mvc?
Steven
The example above is plain JEE6 JAX-RS (http://wikis.sun.com/display/Jersey/Overview+of+JAX-RS+1.0+Features)
Jan