exception translation

123 views
Skip to first unread message

klemensr

unread,
Jan 10, 2011, 7:48:59 AM1/10/11
to Google Web Toolkit
Hi!

Is there any possibility to prevent that GWT is translating any
unchecked exception to an "InvocationException"?

For example a ServletException is thrown - GWT is translating this
exception into an InvocationException and capsulates the
ServletException in the message body as html text.

So is there a way to control this translation mechanism manually?

(I am using GWT 2.0)

cheers

Paul Robinson

unread,
Jan 10, 2011, 9:07:33 AM1/10/11
to google-we...@googlegroups.com
For GWT RPC, the only control you have is to catch all exceptions, and re-throw as an exception that's declared in your RPC interface.

Paul

klemensr

unread,
Feb 17, 2011, 6:19:41 AM2/17/11
to Google Web Toolkit
Thanks for the response.

Yeah, thats exactly what I'd like to do. But where can I catch these
exceptions and turn them into declared exceptions?

(It is not that easy because I am using an Servlet Filter - The
exception is not directly occuring in the RPC but in the doFilter
function which only raises ServletExceptions)

Thomas Broyer

unread,
Feb 17, 2011, 6:32:07 AM2/17/11
to google-we...@googlegroups.com
In that case, aren't you getting a StatusCodeException? You can then look at the getStatusCode (e.g. if 401 => sign the user in) and the getEncodedResponse (you can then include some "magic number", or JSON, etc. in your response; instead of using the default servlet error pages)

klemensr

unread,
Feb 17, 2011, 9:45:07 AM2/17/11
to Google Web Toolkit
I am getting a StatusCodeException. May I am a bit more specific: I
have to check concurrency problems. In case of a concurrency the GUI
has to show a user dialog. The StatusCodeException just give me the
ErrorCode 500 (Internal Server Error) but this is to unspecific. This
error code can occour in other cases as well so that I need another
identifier.

The original exception is capsulated in the message body of the
StatusCodeException with HTML tags. A dirty solution would be to make
a String RegEx and search for a pattern which identify the concurreny
exception in the exception message. But there must be a more elegant
way of doing this?!

So how can I do this better without an RegEx or string search?

This would be the message of the StatusCodeException:

<html>
<head>
<title>JBossWeb/2.0.1.GA - Error report</title>
<style>
<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-
color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-
serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-
family:Tahoma,Arial,sans-serif;color:white;background-
color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-
serif;color:black;background-color:white;} B {font-
family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;}
P {font-family:Tahoma,Arial,sans-
serif;background:white;color:black;font-size:12px;}A {color : black;}
A.name {color : black;}HR {color : #525D76;}-->
</style>
</head>
<body>
<h1>HTTP Status 500 - </h1>
<HR size="1" noshade="noshade">
<p><b>type</b> Exception report</p>
<p>
<b>message</b>
<u></u>
</p>
<p>
<b>description</b>
<u>The server encountered an internal error () that prevented it
from fulfilling this request.</u>
</p>
<p>
<b>exception</b>
<pre>javax.servlet.ServletException: !!!ConcurrencyException!!!
com.kapdion.mdm.server.servlets.filter.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:
47)
com.kapdion.mdm.server.servlets.filter.ServletFilter.doFilter(ServletFilter.java:
53)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:
96) </pre>
</p>
<p>
<b>note</b>
<u>The full stack trace of the root cause is available in the
JBossWeb/2.0.1.GA logs.</u>
</p>
<HR size="1" noshade="noshade">
<h3>JBossWeb/2.0.1.GA</h3>
</body>
</html>

Thomas Broyer

unread,
Feb 17, 2011, 12:15:26 PM2/17/11
to google-we...@googlegroups.com
I'm not sure what you mean by "concurrency" here, but how about returning a 409 (Conflict) status code instead of 500?

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10

500 means "internal server error", i.e. something the client cannot do anything about.

klemensr

unread,
Feb 21, 2011, 6:37:07 AM2/21/11
to Google Web Toolkit
With concurrency I mean something like this:
http://en.wikipedia.org/wiki/Optimistic_concurrency_control

I am not setting the error code by myself. The thing is that GWT is
shomewhere translating the original exception created through
hibernate (concurrency detected) to the excetion postet above. In this
step the error code is set automatically.

Because of the fact that the ServletException is an unchecked
exception GWT has to make a translation to a standard exception (in
this case InvocationException/StatusCodeException).

So I think I should modify this translation machanism - but does
anybody know how to do this? Is there any better way of doing that?

I really appreciate your help!

ep

unread,
Feb 21, 2011, 8:53:18 AM2/21/11
to Google Web Toolkit
GWT needs to wrap any exception to make it serializable and prevent
the server from answering a 500 http status code. that is, GWT moves
exception handling from HTTP layer to each own and the exception is
handled on the client, which first tries to parse the exception and
rethrows it, thats how RPC handles it.

however, you can give your implementation of RemoteServiceServlet and
handle, maybe some special exceptions, your way, and even return them
to the client if you want without having RPC stack to handle them
Reply all
Reply to author
Forward
0 new messages