处理GWT RequestFactory服务器错误响应 [英] handling GWT RequestFactory server error responses

查看:97
本文介绍了处理GWT RequestFactory服务器错误响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个新编码的GWT / GAE应用程序,它在客户端使用了RequestFactory和Editors,后面使用了一个自定义的Objectify DAO服务。

persist()路径在成功上工作良好。
客户端JSR 303的工作原理也是如此。



我的问题是如何触发服务器警告/错误并处理UI更新?



我使用Chandler的Generic DAO作为Objectify 2在
http://turbomanage.wordpress.com/2010/02/09/generic-dao-for-objectify-2/

我的gwt活动正在调用persist(myProxy).fire(new Receiver<>)

我的dao代码抛出IllegalArgumentException和其他RuntimeExceptions用于业务逻辑情形找到重复的电子邮件地址 - 想要登录吗?

Receiver<>。onSuccess()可以正常工作以追踪成功的结果。
既不是Receiver<> onFailure()也不是Receiver<>。onViolation()报告RuntimeException。



(更正:为服务器端异常调用onFailure())



有没有更好的方法来做到这一点?
DAO抛出onViolation()或onFailure()会报错吗?
编辑器应该如何处理和从异常中恢复?

解决方案

我发现了最通用的命令序列为

  void start(){
//获得p
context1.get( (新接收者< P> {onSuccess(P resp){p = resp;} ...})。fire();
//或创建p
p = context2.create(P.class);
//然后保存p
req = context2.persist(p).to(new Receiver< P> {/ * note not use context1 * /
onViolation(...){ / * JSR 303处理程序* /};
onFailure(error){/ * handle * / error.getMessage()};
onSuccess(X x){/ * persist() };});
//带有p
的驱动编辑器driver.edit(p,req);

$ b $ ...
void onSave(){
//编辑器
ctxt = driver.flush()/ * note ctxt == context2 * /
if(driver.hasErrors()){/ * JSR 303 handler * /};
// RF
ctxt.fire();

根据下面的会话摘录 http://groups.google.com/group / google-web-toolkit / browse_thread / thread / da863606b3893132 / 96956661c53e1064?hl = zh_CN


$ b


Thomas Broyer
onFailure应包含您在服务器
端抛出的
异常的getMessage()。

您可以通过为
RequestFactoryServlet提供您自己的
ExceptionHandler来调整它(扩展它并
使用它的构造函数以
ExceptionHandler)。

只有当
实体没有通过时,才会调用onViolation JSR-303 Bean
验证,在
之前检查服务方法。

如果您想要
捕获clidnt代码中的失败
,您必须为$ b $添加一个Receiver b persist()服务方法:

context.persist(p).to(new Receiver ...



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 at http://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.

( Correction: onFailure() is being called for server-side exceptions)

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?

解决方案

I've found the most versatile command sequence to be

void start() {
    // Either get p
    context1.get(..).to( new Receiver<P> { onSuccess(P resp){p = resp;} ... }).fire();
    // OR create p
    p = context2.create( P.class );
    // Then save p
    req = context2.persist(p).to( new Receiver<P>{  /* note do not use context1 */
        onViolation(...) { /*JSR 303 handler*/ };
        onFailure( error ) { /* handle */ error.getMessage() }; 
        onSuccess(X x) { /* whatever persist() returns handler */ }; } ); 
    // drive editor with p
    driver.edit( p, req);    
}

....
void onSave() {    
    // editor
    ctxt = driver.flush()  /* note ctxt == context2 */
    if ( driver.hasErrors() ) { /*JSR 303 handler*/};
    // RF
    ctxt.fire();
}

Based on the conversation excerpt below at http://groups.google.com/group/google-web-toolkit/browse_thread/thread/da863606b3893132/96956661c53e1064?hl=en

Thomas Broyer 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.

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…

这篇关于处理GWT RequestFactory服务器错误响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆