Changeset 5528

Show
Ignore:
Timestamp:
09/26/08 14:04:26 (3 months ago)
Author:
joonas.lehtinen@…
Message:

Fixed #2106 : Reviewed, tested, merged (and a bit fixed) Maunos patch for automatic expiration forward when the session ends.

Location:
trunk/src/com/itmill/toolkit
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/com/itmill/toolkit/Application.java

    r5507 r5528  
    13941394        /** 
    13951395         * Enables or disables the notification. If disabled, the set URL (or 
    1396          * current) is loaded directly. 
     1396         * current) is loaded directly when next transaction between server and 
     1397         * client happens. 
    13971398         *  
    13981399         * @param sessionExpiredNotificationEnabled 
    1399          *            true = enabled, false = disabled 
     1400         *                true = enabled, false = disabled 
    14001401         */ 
    14011402        public void setSessionExpiredNotificationEnabled( 
     
    14061407        /** 
    14071408         * Sets the caption of the notification. Set to null for no caption. If 
    1408          * both caption and message is null, the notification is disabled; 
     1409         * both caption and message are null, client automatically forwards to 
     1410         * sessionExpiredUrl after timeout timer expires. Timer uses value read 
     1411         * from HTTPSession.getMaxInactiveInterval() 
    14091412         *  
    14101413         * @param sessionExpiredCaption 
     
    14171420        /** 
    14181421         * Sets the message of the notification. Set to null for no message. If 
    1419          * both caption and message is null, the notification is disabled; 
     1422         * both caption and message are null, client automatically forwards to 
     1423         * sessionExpiredUrl after timeout timer expires. Timer uses value read 
     1424         * from HTTPSession.getMaxInactiveInterval() 
    14201425         *  
    14211426         * @param sessionExpiredMessage 
    1422          *            the message 
     1427         *                the message 
    14231428         */ 
    14241429        public void setSessionExpiredMessage(String sessionExpiredMessage) { 
  • trunk/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java

    r5479 r5528  
    109109    /** List of pending variable change bursts that must be submitted in order */ 
    110110    private final Vector pendingVariableBursts = new Vector(); 
     111     
     112    /** Timer for automatic refirect to SessionExpiredURL */ 
     113    private Timer redirectTimer;  
     114     
     115    /** redirectTimer scheduling interval in seconds */  
     116    private int sessionExpirationInterval;  
    111117 
    112118    public ApplicationConnection(WidgetSet widgetSet, 
     
    501507                paintableToId.clear(); 
    502508            } 
    503         } 
    504  
     509            if (meta.containsKey("timedRedirect")) { 
     510                final JSONObject timedRedirect = meta.get("timedRedirect").isObject(); 
     511                redirectTimer = new Timer() {  
     512                    public void run() {  
     513                        redirect(timedRedirect.get("url").isString().stringValue());  
     514                    } 
     515                };                 
     516                sessionExpirationInterval = Integer.parseInt(timedRedirect.get("interval").toString()); 
     517            } 
     518        } 
     519        if (redirectTimer != null) { 
     520            redirectTimer.schedule(1000 * sessionExpirationInterval); 
     521        } 
    505522        // Process changes 
    506523        final JSONArray changes = (JSONArray) ((JSONObject) json) 
  • trunk/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java

    r5493 r5528  
    1313import java.io.OutputStreamWriter; 
    1414import java.io.PrintWriter; 
     15import java.lang.reflect.InvocationTargetException; 
    1516import java.lang.reflect.Method; 
    1617import java.text.DateFormatSymbols; 
     
    104105 
    105106    private int pendingLocalesIndex; 
     107 
     108    private int timeoutInterval = -1; 
    106109 
    107110    public CommunicationManager(Application application, 
     
    439442                metaOpen = true; 
    440443                outWriter.write("\"repaintAll\":true"); 
     444            } 
     445 
     446            SystemMessages ci = null; 
     447            try { 
     448                Method m = application.getClass().getMethod( 
     449                        "getSystemMessages", null); 
     450                ci = (Application.SystemMessages) m.invoke(null, null); 
     451            } catch (NoSuchMethodException e1) { 
     452                e1.printStackTrace(); 
     453            } catch (IllegalArgumentException e) { 
     454                e.printStackTrace(); 
     455            } catch (IllegalAccessException e) { 
     456                e.printStackTrace(); 
     457            } catch (InvocationTargetException e) { 
     458                e.printStackTrace(); 
     459            } 
     460 
     461            // meta instruction for client to enable auto-forward to 
     462            // sessionExpiredURL after timer expires. 
     463            if (ci != null && ci.getSessionExpiredMessage() == null 
     464                    && ci.getSessionExpiredCaption() == null 
     465                    && ci.isSessionExpiredNotificationEnabled()) { 
     466                int newTimeoutInterval = request.getSession() 
     467                        .getMaxInactiveInterval(); 
     468                if (repaintAll || (timeoutInterval != newTimeoutInterval)) { 
     469                    String escapedURL = ci.getSessionExpiredURL() == null ? "" 
     470                            : ci.getSessionExpiredURL().replace("/", "\\/"); 
     471                    if (metaOpen) { 
     472                        outWriter.write(","); 
     473                    } 
     474                    outWriter.write("\"timedRedirect\":{\"interval\":" 
     475                            + (newTimeoutInterval + 15) + ",\"url\":\"" 
     476                            + escapedURL + "\"}"); 
     477                    metaOpen = true; 
     478                } 
     479                timeoutInterval = newTimeoutInterval; 
    441480            } 
    442481