0

Catch Server 503 Error - Or Catch Stale Page

asked 2013-04-17 16:01:55 +0800

ansancle gravatar image ansancle
327 9

updated 2013-04-18 12:36:47 +0800

Does anyone know how to catch the server 503 error thrown by the browser if the server has gone down?

Or another way to put this is catch a stale page, the server has cycled and is back up but our page is now stale.

In my case, if we are sitting on a page and the server is restarted, the next time the user presses anything it will pop the "503: Service Temporarily Unavailable" dialog, then when they hit ok the page will reload and all is well. I want to do that reload under the covers so the dialog never gets popped.

I haven't found anything on the web and was wondering if anyone knows a ZK way or any other way to do this. Thanks! Andy

delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted
0

answered 2013-06-28 08:20:32 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

You can specify reload-uri with respect to specific response code under error-reload element of client-config element in zk.xml, please refer to the sample below (also include error handling and session timeout)

zk.xml

<zk>
    <!-- for response error, e.g., 500, 503 -->
    <client-config>
        <error-reload>
            <device-type>ajax</device-type>
            <error-code>500</error-code>
            <reload-uri></reload-uri>
        </error-reload>
        <error-reload>
            <device-type>ajax</device-type>
            <error-code>503</error-code>
            <reload-uri></reload-uri>
        </error-reload>
    </client-config>
    <!-- for Exception throwed in Event Listener -->
    <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/refresh.zul</location>
    </error-page>
    <!-- for session timeout -->
    <session-config>
        <device-type>ajax</device-type>    
        <timeout-uri></timeout-uri>    
    </session-config>
</zk>

test.zul

<zk>
    Test steps:
    <div />
    1. click 'response 503' button
    <div />
    2. click 'throw exception' button
    <div />
    3. Restart server then click 'test session timeout' button
    <div />
    <button label="response 503" onClick="alert(123);">
        <attribute name="onClick"><![CDATA[
            ((javax.servlet.http.HttpServletResponse)Executions.getCurrent().getNativeResponse()).sendError(javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        ]]></attribute>
    </button>
    <button label="throw exception">
        <attribute name="onCreate"><![CDATA[
            import org.zkoss.zk.ui.event.EventListener;
            import org.zkoss.zk.ui.event.Event;
            import org.zkoss.zk.ui.event.Events;
            self.addEventListener(Events.ON_CLICK, new EventListener () {
                public void onEvent (Event event) {
                    throw new Exception("");
                }
            });
        ]]></attribute>
    </button>
    <button label="test session timeout" onClick="alert(123);" />
    <div />
    loaded time: <label onCreate='self.setValue(System.currentTimeMillis() + "")' />
</zk>

refresh.zul (for error handling)

<zk>
    <zscript><![CDATA[
        Executions.getCurrent().sendRedirect("");
    ]]></zscript>
</zk>

References:

The client-config Element

The error-reload Element

The error-page Element

Error Handling

Session Timeout Management

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-04-17 16:01:55 +0800

Seen: 18 times

Last updated: Jun 28 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More