i solved this issue, by not getting GWT-RPC in middle.
Instead just a plain servlet, that returns images with appropriate
content-type.
The img tag, src attribute points to the ImageServlet, which serves the
image.

I am also interested to know if someone has solved this problem of different
content-type, using GWT-RPC mechanism.

Thanks,
Subhro.

On Thu, Apr 15, 2010 at 8:18 PM, Ahmet <[email protected]> wrote:

> Hi everyone,
>
> My application has an upload file feature and allow users to upload
> image files to the server using an httpServlet. That part works fine,
> the file gets uploaded and placed in the WEB-INF folder (I don't want
> public access), required url and other info is filled into the
> database using Hibernate.
>
> The problem is when I want to retrieve the image on the client side.
> My user pojo knows the url of its image, but I can't instantiate an
> Image object and send it over an RPC call since it is not
> serializable. I decided to transform the image file, a jpg, into a
> byte[] on the server side and then transfer the byte[] over the RPC
> call, however, I it doesn't work.
>
> I get no errors on the server side, the RPC call returns, but my
> client reports a failure:
>
> SEVERE: Exception while dispatching incoming RPC call
> java.lang.RuntimeException: java.lang.ClassCastException: [B cannot be
> cast to [Ljava.lang.Object;
>
> My service code:
> public byte[] getImageByUrl(String url) {
>
>                ByteArrayOutputStream baos = new ByteArrayOutputStream();
>                try{
>                        File file = new File(url);
>                        ObjectOutputStream oos = new
> ObjectOutputStream(baos);
>                        oos.writeObject(file);
>                }catch(Exception ioe){
>                        ioe.getMessage();
>                }
>                return baos.toByteArray();
> }
>
> My client code:
> service.getImageByUrl(url, new AsyncCallback<byte[]>() {
>                                        @Override
>                                        public void onFailure(Throwable
> arg0) {
>                                                log("getImageByUrl failed");
>                                                log(arg0.getMessage());
>                                        }
>                                        @Override
>                                        public void onSuccess(byte[] arg0) {
>                                                //reconstruct file
>                                        }
> }
>
> I send a byte[] and recieve a byte[], I checked the contents of the
> array from the server side, it is not null and gets returned, however
> the client side can not accept it... Why can this be ?
>
> I have done some research and it seems like using an httpServlet is
> better than using an RPC call when making a binary data transfer,
> therefore I am inclined to using the httpServlet for downloading the
> image, however what I ultimately achive is not having to save the file
> on my client side to access its content. Is it possible to transfer
> the Image object over the httpServlet to dynamically use it as it is
> recieved on the client side ?
>
> I am not sure about using data://url s as they are not supported by
> all browsers, but seems as the simplest solution.
>
> Thank you for your opinions..
>
>
> Regards,
> Ahmet
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to