Changeset 8321

Show
Ignore:
Timestamp:
07/04/09 07:29:33 (14 months ago)
Author:
artur.signell@…
Message:

Fix for #3115 - A new session should not be created if an application is not

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • versions/6.0/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java

    r8320 r8321  
    548548    private Application findApplicationInstance(HttpServletRequest request, 
    549549            RequestType requestType) throws MalformedURLException, 
    550             SAXException, IllegalAccessException, InstantiationException, 
    551550            ServletException, SessionExpired { 
    552551 
    553         final boolean restartApplication = (request 
    554                 .getParameter(URL_PARAMETER_RESTART_APPLICATION) != null); 
    555         final boolean closeApplication = (request 
    556                 .getParameter(URL_PARAMETER_CLOSE_APPLICATION) != null); 
    557  
    558         Application application = getExistingApplication(request); 
     552        boolean requestCanCreateApplication = requestCanCreateApplication( 
     553                request, requestType); 
     554 
     555        /* Find an existing application for this request. */ 
     556        Application application = getExistingApplication(request, 
     557                requestCanCreateApplication); 
     558 
    559559        if (application != null) { 
    560560            /* 
     
    562562             * user not specifically requested to close or restart it. 
    563563             */ 
     564 
     565            final boolean restartApplication = (request 
     566                    .getParameter(URL_PARAMETER_RESTART_APPLICATION) != null); 
     567            final boolean closeApplication = (request 
     568                    .getParameter(URL_PARAMETER_CLOSE_APPLICATION) != null); 
     569 
    564570            if (restartApplication) { 
    565571                closeApplication(application, request.getSession(false)); 
     
    574580 
    575581        // No existing application was found 
     582 
     583        if (requestCanCreateApplication) { 
     584            /* 
     585             * If the request is such that it should create a new application if 
     586             * one as not found, we do that. 
     587             */ 
     588            return createApplication(request); 
     589        } else { 
     590            /* 
     591             * The application was not found and a new one should not be 
     592             * created. Assume the session has expired. 
     593             */ 
     594            throw new SessionExpired(); 
     595        } 
     596 
     597    } 
     598 
     599    /** 
     600     * Check if the request should create an application if an existing 
     601     * application is not found. 
     602     *  
     603     * @param request 
     604     * @param requestType 
     605     * @return true if an application should be created, false otherwise 
     606     */ 
     607    private boolean requestCanCreateApplication(HttpServletRequest request, 
     608            RequestType requestType) { 
    576609        if (requestType == RequestType.UIDL && isRepaintAll(request)) { 
    577610            /* 
     
    580613             * without using writeAjaxPage. 
    581614             */ 
    582             return createApplication(request); 
     615            return true; 
    583616 
    584617        } else if (requestType == RequestType.OTHER) { 
    585618            /* 
    586              * TODO Shouldany request really create a new application instance 
    587              * if none was found? 
     619             * TODO Should any URL request really create a new application 
     620             * instance if none was found? 
    588621             */ 
    589             return createApplication(request); 
    590  
    591         } else { 
    592             /* The application was not found. Assume the session has expired. */ 
    593             throw new SessionExpired(); 
    594         } 
    595  
     622            return true; 
     623 
     624        } 
     625 
     626        return false; 
    596627    } 
    597628 
     
    15891620            servletPath = servletPath + "/"; 
    15901621        } 
     1622        System.out.println(request.getPathInfo()); 
    15911623        URL u = new URL(reqURL, servletPath); 
    15921624        return u; 
     
    15991631     * @param request 
    16001632     *            the HTTP request. 
     1633     * @param allowSessionCreation 
     1634     *            true if a session should be created if no session exists, 
     1635     *            false if no session should be created 
    16011636     * @return Application instance, or null if the URL does not map to valid 
    16021637     *         application. 
     
    16071642     * @throws IllegalAccessException 
    16081643     * @throws InstantiationException 
    1609      */ 
    1610     private Application getExistingApplication(HttpServletRequest request) 
    1611             throws MalformedURLException, SAXException, IllegalAccessException, 
    1612             InstantiationException { 
     1644     * @throws SessionExpired 
     1645     */ 
     1646    private Application getExistingApplication(HttpServletRequest request, 
     1647            boolean allowSessionCreation) throws MalformedURLException, 
     1648            SessionExpired { 
    16131649 
    16141650        // Ensures that the session is still valid 
    1615         final HttpSession session = request.getSession(true); 
     1651        final HttpSession session = request.getSession(allowSessionCreation); 
     1652        if (session == null) { 
     1653            throw new SessionExpired(); 
     1654        } 
    16161655 
    16171656        WebApplicationContext context = WebApplicationContext 
     
    16191658 
    16201659        // Gets application list for the session. 
    1621         final Collection applications = context.getApplications(); 
     1660        final Collection<Application> applications = context.getApplications(); 
    16221661 
    16231662        // Search for the application (using the application URI) from the list 
    1624         for (final Iterator i = applications.iterator(); i.hasNext();) { 
    1625             final Application sessionApplication = (Application) i.next(); 
     1663        for (final Iterator<Application> i = applications.iterator(); i 
     1664                .hasNext();) { 
     1665            final Application sessionApplication = i.next(); 
    16261666            final String sessionApplicationPath = sessionApplication.getURL() 
    16271667                    .getPath();