users@jersey.java.net

[Jersey] Re: two calls while getting the image.

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Wed, 09 Mar 2011 16:46:51 +0100

Hello Rahul,

can you try requesting that image with jersey client? Or can you enable
LoggingFilter [1] on server side to see what is really happening? It
might be browser specific behavior.. you might want to try cur/wget or
something like it. And.. to answer your question - no, that method
should not be called twice.

Regards,
Pavel

[1]
http://jersey.java.net/nonav/apidocs/1.5/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html

On 03/01/2011 12:15 AM, Rahul Babbar wrote:
> 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
>
>