小编mar*_*ark的帖子

StatusCodeException与Vs. GWT中的RuntimeException

在我的GWT应用程序中.我重写了RemoteServiceServlet,以便在调用服务方法之前检查会话是否有效.我试图从服务器抛出一个RuntimeException("过期的会话"),我希望客户端从asynccallback onFailure中捕获此异常...

在客户端我想:Asynccallback:

@Override
    public void onFailure(Throwable caught) {
        final String message = caught.getMessage();

        if (!isNullOrEmptyString(message) && message.contains("expired session")) {
            com.google.gwt.user.client.Window.Location.reload();
        }

    }
Run Code Online (Sandbox Code Playgroud)

但是,在客户端中,捕获的对象仍然是StatusCodeException,并且消息仍然是默认的"...服务器中的异常...".如果它是我从服务器发送的会话过期消息,我如何覆盖至少要比较的默认消息?

谢谢

嗨Gursel,这是我的代码: - > Custom RemoteServiceServlet.我试图在调用之前"拦截"每个方法.我检查会话并抛出一个RuntimeException,如果它已经过期了.所以基本上,抛出异常的声明方法不是自定义RemoteServiceServlet.它仍然转到客户端异步中的"onFailure",但Throwable对象仍然是"StatusCodeException"类型,没有EXPIRED_SESSION_MSG消息.不要知道如何做这项工作.谢谢!

public class XRemoteServiceServlet extends RemoteServiceServlet {
    private final static String EXPIRED_SESSION_MSG = "ERROR: Application has expired session.";   
    @Override
    protected void onAfterRequestDeserialized(RPCRequest rpcRequest) {
        HttpServletRequest httpServletRequest = this.getThreadLocalRequest();
        HttpSession session = httpServletRequest.getSession(false);
        if (session != null) {
            final String sessionIdFromRequestHeader = getSessionIdFromHeader();
            if (!isNullOrEmptyString(sessionIdFromRequestHeader)) {
                final String sessionId = session.getId();

                if …
Run Code Online (Sandbox Code Playgroud)

gwt

7
推荐指数
1
解决办法
2989
查看次数

标签 统计

gwt ×1