how to post & handle RequestFactory server warnings/errors?

271 views
Skip to first unread message

A. Stevko

unread,
Mar 11, 2011, 6:57:43 PM3/11/11
to google-we...@googlegroups.com
(I posted this on stackoverflow and got a handful of views but no response)

I have a newly coded GWT/GAE app that uses RequestFactory and Editors on the client and a custom Objectify DAO Service on the back.

The flush() then persist() paths work fine on success. Client side JSR 303 works as well as can be expected too.

My question is how to trigger server warnings/errors and handle UI updates?

I am using Chandler's Generic DAO for Objectify 2 athttp://turbomanage.wordpress.com/2010/02/09/generic-dao-for-objectify-2/

my gwt activity is calling persist( myProxy ).fire( new Receiver<> )

my dao code is throwing IllegalArgumentException and other RuntimeExceptions for business logic situations like "Duplicate email address found - want to login instead?"

Receiver<>.onSuccess() works fine to track a successful outcome. neither Receiver<>.onFailure() nor Receiver<>.onViolation() report the RuntimeExceptions.

Is there a better way to do this? What exceptions should the DAO throw such that onViolation() or onFailure() report errors? How should the editor(s) handle and recover from the exception?


--
-- A. Stevko
===========
"If everything seems under control, you're just not going fast enough." M. Andretti





Thomas Broyer

unread,
Mar 12, 2011, 5:34:46 AM3/12/11
to google-we...@googlegroups.com
onFailure should containg the getMessage() of the exception you threw on the server side.

You can tweak it by providing your own ExceptionHandler to the RequestFactoryServlet (extend it and use its constructor taking an ExceptionHandler).

onViolation will only be called if your entities do not pass JSR-303 Bean Validation, which is checked before calling any service method.

A. Stevko

unread,
Mar 13, 2011, 4:46:55 PM3/13/11
to google-we...@googlegroups.com
Thanks for the reply Thomas :) Your blogs and writings were very necessary to my understanding of the new technologies.
Got time for another similar question re: request factory design?

Am I right in thinking that a DAO layer is the correct place for the extra business logic associated with server side pre/post commit operations not necessarily altering the database like spawning a 'welcome new user' email task? 

Also have you seen a JSR-303 Bean Validation extension that will guarantee uniqueness in a field (like email  address0? 


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

frog

unread,
Mar 21, 2011, 12:45:11 PM3/21/11
to Google Web Toolkit
Could you tell me if you got it working?
I dont' use Objectify just RF + Editors my custom DAO for Hibernate.
I do:
MyProxy p = context.create(MyProxy.class);
....
context.persist(p);
context.fire(new Receiver(...))

when persist() in DAO throws RuntimeException I let the
DefaultExceptionHandler take care of it. In response returned to
client I see

{"O":......
"I":[{"M":"Server Error: boo error peristing object","F":true}],"S":
[false]}

My receiver never executes onFailure as
AbstractRequestContext.onTransportSuccess response.getGeneralFailure()
always returns null. What am I doing wrong?

I will appreciate any comments

Thomas Broyer

unread,
Mar 21, 2011, 12:52:43 PM3/21/11
to google-we...@googlegroups.com
If you want to "catch" the failure in clidnt code, you have to add a Receiver for the persist() service method:
   context.persist(p).to(new Receiver…

Reply all
Reply to author
Forward
0 new messages