users@jersey.java.net

[Jersey] two calls while getting the image.

From: Rahul Babbar <rahul.babbar1_at_gmail.com>
Date: Mon, 28 Feb 2011 15:15:04 -0800

Hello all,

I am using Jersey API to fetch and display some images to the browser.

However, i can see that two API calls are made on single request from the
browser for displaying the image(the second call is made just after the
image is displayed on the browser).

All other APIs which do not get the images work well.

The piece of code in Jersey is written something like


@GET
@Path("/{id}/content")
 public Response getImageContent(@PathParam("imageId") long imageId) {

 CustomFile file = null ; // somehow get file here
 byte[] contentBytes = file.getContents();
 if(contentBytes == null) {
logger.info("Null contents found ");
 throw new WebApplicationException(Response.Status.NOT_FOUND);
}
 InputStream stream = new ByteArrayInputStream(contentBytes);
     return Response.ok().entity(stream).header(HttpHeaders.CONTENT_TYPE,
file.getMimeType()).build();
}


Is it the normal way or am i missing something.

Rahul