users@jersey.java.net

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

From: Rahul Babbar <rahul.babbar1_at_gmail.com>
Date: Fri, 11 Mar 2011 15:18:19 -0800

Hi Pavel,

Yes, you are right. It is related to the browser only.

If i use wget or curl or write a simple java client to make the call, there
is only one call.

Thanks

Rahul


On Wed, Mar 9, 2011 at 7:46 AM, Pavel Bucek <pavel.bucek_at_oracle.com> wrote:

> 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
>>
>>
>>
>
>