如何处理会话超时异常(使用MVP Places和Activities)? [英] How to handle a session timeout exception (with MVP Places and Activities)?

查看:172
本文介绍了如何处理会话超时异常(使用MVP Places和Activities)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何在GWT应用程序中处理超时请求?
这里是对我的web.xml文件的剪切:

 < session-config> 
< session-timeout> 30< / session-timeout>
< / session-config>

我的GWT项目基于MVP活动和地点。
当用户等待超过30mn时,我想显示一个弹出窗口并将用户重定向到登录页面。这是我为
所有RPC服务所做的:

  public void onFailure(Throwable caught){
...
if(catch instanceof InvocationException){
{
Window.alert(Time out de session。Veuillez vous reconnecter。2);
Window.open(GWT.getHostPageBaseURL()+identification.html,_self,null);
return;

...

它可以工作,但有几件事很烦人:
1)捕获的异常应该是RequestTimeoutException。但它没有被捕获,这就是为什么我使用InvocationException来代替。
它怎么没被抓到?
2)我如何以更通用的方式处理这个异常?在所有RPC服务中必须捕获该异常是有点愚蠢的...
我读了一些AsyncCallbackAdapter类...
3)现在我只处理RPC服务,但当然会超时异常无处不在:链接,按钮,页面刷新...
我正在使用MVP场所和活动。
当用户试图去某个地方时,是否有办法捕获该异常?



感谢您的帮助

解决方案


  1. RequestTimeoutException 在服务器没有响应时抛出。


  2. 您应该创建自己的检查异常,如 SessionTimeoutException ,并在客户端代码中处理它。 GWT知道如何处理(序列化)检查的异常并将它们传递给客户端代码: http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html#exceptions



    为了解决这个问题,应用程序范围的方式,您可以通过为远程服务创建自己的生成器来挂钩到RPC机制中:

  3. >

    最简单的方法(不更改所有现有代码)可以设置 Timer 。当会话超时显示模式 DialogBox (阻止其他小部件上的用户输入)时,他/她需要再次登录。



how do you handle a time out request in a GWT app ? Here is a snipped of my web.xml file :

<session-config>
<session-timeout>30</session-timeout>
</session-config>

My GWT project is based on MVP Activities and Places. Whenever the user waits more than 30mn, i want to display a popup and redirect the user to the login page. Here is what i do for all RPC services :

 public void onFailure(Throwable caught) {
    ...
    if (caught instanceof InvocationException) {
                    {
                        Window.alert("Time out de session. Veuillez vous reconnecter. 2");
                        Window.open(GWT.getHostPageBaseURL() + "identification.html", "_self", null);
                        return;
                    }
    ...}

It works but several things are annoying : 1) the caught exception should be RequestTimeoutException. But it's not caught, which is why i use InvocationException instead. How come it's not caught ? 2) how can i handle this exception in a more generic way ? It's a bit stupid to have to catch that exception in all RPC services ... I read about some AsyncCallbackAdapter class ... 3) Right now i handle RPC services only but of course time out exception occurs everywhere : links, buttons, page refresh ... I'm using MVP Places and Activities. Is there a way to catch that exception when the user tries to go to a place ?

Thanks for helping

解决方案

  1. RequestTimeoutException is thrown when server is not responding.

  2. You should create you own checked exception, something like SessionTimeoutException and handle it in you client code. GWT knows how to handle (serialize) checked exceptions and pass them to your client code: http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html#exceptions

    To handle this in application-wide way, you can hook into RPC mechanism, by creating you own generator for remote services: How to redirect to login page after session expire in GWT RPC call

  3. The easiest way (without changing all existing code) would be to set a Timer to periodically check (every few minutes) the server session. When session times out show a modal DialogBox (preventing user input on other widgets) notifying user he/she needs to login again.

这篇关于如何处理会话超时异常(使用MVP Places和Activities)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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