How to RPC-serialize data manually on client?

29 views
Skip to first unread message

Andrey

unread,
Nov 6, 2009, 6:15:49 AM11/6/09
to Google Web Toolkit
Hi,

I want to create a servlet that is downloading some file to client.
So, I cannot use RPC services for that. Servlet will take a lot of
data from client, so request should be POST. I want to use built-in
RPC serialization mechanizm to encode my parameters. On server, I can
use com.google.gwt.user.server.rpc.RPC class to decode the request and
get the parameters. But how can I encode them on client? I've been
unable to fetch SerializationStreamWriter instances or something.

In short, I want RPC-request without RPC-response (servlet will be
writing a file in output stream instead).

Hope, I've been clear enough..

Thanks in advance,
Andrey

Andrey

unread,
Nov 6, 2009, 6:16:17 AM11/6/09
to Google Web Toolkit
I'm using GWT 1.7

Sripathi Krishnan

unread,
Nov 6, 2009, 8:48:27 AM11/6/09
to google-we...@googlegroups.com
Can't do it via GWT RPC. As you said, you can bypass things on the server, but GWT doesn't have any client side hooks to get raw bytes.

In fact, I am not sure if you can do that using a XmlHttpRequest. How will the user save the file, if the data is available as a javascript variable?

There is an older discussion on this group - someone wanted to download an image from the servlet but pass in parameters using GWTs RPC request. The conclusion was similar - it can't be done.

--Sri


2009/11/6 Andrey <razumovs...@gmail.com>

Jason Essington

unread,
Nov 6, 2009, 12:16:07 PM11/6/09
to google-we...@googlegroups.com
Actually, the process would be to construct a form post (not a XHR) since that is the only way in Javascript/html to upload a file. you could have a field that contained the serialized rpc style data ...

then on the server break out the fields ... handle the files and deserialize the other bits. then serialize a response and return it.

on the client, the target iframe would have to handle the returned text as RPC data and deserialize it.

I don't think that any of this is built into GWT at the moment, but it would be possible to create it.

I have created form posts with RPC responses in the past, so it is a short hop to add the rpc style request parameters.

-jason

Andrey

unread,
Nov 6, 2009, 3:34:57 PM11/6/09
to Google Web Toolkit
Jason,

this is exactly what I was thinking of. My question is how to do this
part: "have a field that contained the serialized rpc style data"? How
can I rpc-serialize it?
BTW I want to download the file not to upload it. So I will not need
to decode on client, only encode on client and decode on server

On 6 ноя, 20:16, Jason Essington <jas...@GreenRiverComputing.com>
wrote:
> Actually, the process would be to construct a form post (not a XHR)  
> since that is the only way in Javascript/html to upload a file. you  
> could have a field that contained the serialized rpc style data ...
>
> then on the server break out the fields ... handle the files and  
> deserialize the other bits. then serialize a response and return it.
>
> on the client, the target iframe would have to handle the returned  
> text as RPC data and deserialize it.
>
> I don't think that any of this is built into GWT at the moment, but it  
> would be possible to create it.
>
> I have created form posts with RPC responses in the past, so it is a  
> short hop to add the rpc style request parameters.
>
> -jason
>
> On Nov 6, 2009, at 6:48 AM, Sripathi Krishnan wrote:
>
> > Can't do it via GWT RPC. As you said, you can bypass things on the  
> > server, but GWT doesn't have any client side hooks to get raw bytes.
>
> > In fact, I am not sure if you can do that using a XmlHttpRequest.  
> > How will the user save the file, if the data is available as a  
> > javascript variable?
>
> > There is an older discussion on this group - someone wanted to  
> > download an image from the servlet but pass in parameters using GWTs  
> > RPC request. The conclusion was similar - it can't be done.
>
> > --Sri
>
> > 2009/11/6 Andrey <razumovsky.and...@gmail.com>

Paul Robinson

unread,
Nov 9, 2009, 8:25:06 AM11/9/09
to google-we...@googlegroups.com
You can achieve the same result a different way, but with two network
calls. The first, a regular RPC call that uploads the data and returns
some unique ID. The second is an HTTP call that goes to your non-GWT
servlet and passes in the ID from the first call as a parameter, and the
file is returned for the browser to handle as normal.

HTH
Paul

Andrey

unread,
Nov 10, 2009, 9:19:30 AM11/10/09
to Google Web Toolkit
Actually right now I'm doing just that. First call "shares" the file
(and contains in the path sessionID, so no other user can access it)
and returns URL to access it. Why I want to rewrite the function is
because file is copied two times (once from source to disk then from
disk to servlet stream).
Guess I'll rewrite it so that first call will store parameters in some
session storage and return an id. This is much easier that trying to
pass complex RPC parameters through normal POST.
Thanks!
Reply all
Reply to author
Forward
0 new messages