RPC.encode not working

148 views
Skip to first unread message

deanhiller

unread,
Dec 18, 2008, 12:55:29 AM12/18/08
to Google Web Toolkit
I have the following code in a servlet filter....

GwtSessionTimeout timeout = new GwtSessionTimeout(
"Session timed out. You need to redirect to the url in getUrl
function",
url);
try {
String payload = RPCServletUtils.readContentAsUtf8(request, true);
RPCRequest rpcRequest = RPC.decodeRequest(payload);
payload = RPC.encodeResponseForFailure(null, timeout);

boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request)
&& shouldCompressResponse(request, response, payload);

ServletContext servletContext = request.getSession
().getServletContext();
RPCServletUtils.writeResponse(servletContext, response, payload,
gzipEncode);

} catch (SerializationException e) {
throw new RuntimeException("Exception", e);
} catch (ServletException e) {
throw new RuntimeException("Exception",e);
}

The browser(firefox) says "This application is out of date, please
click the refresh button on your browser."

If I change
payload = RPC.encodeResponseForFailure(null, timeout);
to
payload = RPC.encodeResponseForFailure(rpcRequest.getMethod, timeout);

it fails with UnexpectedException like GwtSessionTimeout was not a
RuntimeException, but it is a RuntimeException so it should work and I
expect the aysncCallback.onFailure to be called, but it doesn't work.

Here is my GwtSessionTimeout....
public class GwtSessionTimeout extends RuntimeException implements
IsSerializable{
}

why isn't this working?
later,
Dean


Arthur Kalmenson

unread,
Dec 18, 2008, 9:06:27 AM12/18/08
to Google-We...@googlegroups.com
Hi Dean,

Are you trying to encode an exception to throw it back to the client
side? AFAIK, you can just throw a IsSerializable exception in your
code and GWT-RPC will transfer the said exception to the client side
for you.

--
Arthur Kalmenson

deanhiller

unread,
Dec 19, 2008, 1:10:46 PM12/19/08
to Google Web Toolkit
How does that work? I am doing the above code in a servlet filter so
there is no GWT code above the filter. All the GWT code is in the
RemoteServlet and ServletFilters run before the RemoteServlet code
does. I also want to throw a GwtSessionTimeoutException so I can pass
a url for the gwt clients to redirect to the correct location. I have
many GWT apps that will use this filter.
thanks,
Dean

On Dec 18, 7:06 am, "Arthur Kalmenson" <arthur.k...@gmail.com> wrote:
> Hi Dean,
>
> Are you trying to encode an exception to throw it back to the client
> side? AFAIK, you can just throw a IsSerializable exception in your
> code and GWT-RPC will transfer the said exception to the client side
> for you.
>
> --
> Arthur Kalmenson
>

Arthur Kalmenson

unread,
Dec 21, 2008, 5:59:35 PM12/21/08
to Google-We...@googlegroups.com
You should be able to throw your exception from anywhere on the server side and have it appear on the client side's onFailure (if the exception implements IsSerializable).

--
Arthur Kalmenson

deanhiller

unread,
Dec 30, 2008, 9:17:29 PM12/30/08
to Google Web Toolkit
I figured it out....in GWT, you HAVE to put throws XXXException on the
interface method even if the exception is just a RuntimeException.
Why is this? This should not be the case!!! The GWT code should
allow all RuntimeExceptions to be passed through...I was throwing a
RuntimeException(very specific case as I usually reserve runtime for
bugs, but this one is needed to apply to all methods without having to
add throws XXXException to all services developed in the future).

Dean

On Dec 21, 3:59 pm, "Arthur Kalmenson" <arthur.k...@gmail.com> wrote:
> You should be able to throw your exception from anywhere on the server side
> and have it appear on the client side's onFailure (if the exception
> implements IsSerializable).
>
> --
> Arthur Kalmenson
>
Reply all
Reply to author
Forward
0 new messages