users@jersey.java.net

RenderedImageProvider added to trunk

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 23 Jan 2009 13:24:45 +0100

Hi,

I have added message body reader/writer provider support for
java.awt.image.RenderedImage and update the Sparklines sample to
remove its own rendered image provider.

See end of email for a unit test case. Note that the Apple JDK does
not come with support to write out GIF files (hence only the
production of "image/png" in the resource class, i am not sure if this
is the case or not for other platforms).

Paul.

public class RenderedImageTypeTest extends AbstractResourceTester {

     public RenderedImageTypeTest(String testName) {
         super(testName);
     }

     @Path("/")
     public class ImageResource {

         @Consumes("image/gif")
         @Produces("image/png")
         @POST
         public RenderedImage postGif(RenderedImage image) {
             return image;
         }

         @Consumes("image/png")
         @Produces("image/png")
         @POST
         public RenderedImage postPng(RenderedImage image) {
             return image;
         }

         @Path("sub")
         @Consumes("application/octet-stream")
         @Produces("image/png")
         @POST
         public RenderedImage postUndefined(BufferedImage image) {
             return image;
         }

     }

     public void testPostPng() throws Exception {
         initiateWebApplication(ImageResource.class);
         WebResource r = resource("/");

         InputStream in =
this.getClass().getResourceAsStream("Jersey_yellow.png");
         RenderedImage image = r.type("image/
png").post(RenderedImage.class, in);

         image = r.type("image/png").post(RenderedImage.class, image);
     }

     public void testPostGif() throws Exception {
         initiateWebApplication(ImageResource.class);
         WebResource r = resource("/");

         InputStream in =
this.getClass().getResourceAsStream("duke_rocket.gif");
         RenderedImage image = r.type("image/
gif").post(RenderedImage.class, in);

         image = r.type("image/png").post(RenderedImage.class, image);
     }

     public void testPostUndefined() throws Exception {
         initiateWebApplication(ImageResource.class);
         WebResource r = resource("/");

         InputStream in =
this.getClass().getResourceAsStream("duke_rocket.gif");
         RenderedImage image = r.path("sub").post(RenderedImage.class,
in);

         image = r.type("image/png").post(RenderedImage.class, image);
     }

}