You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Martijn Stellinga (JIRA)" <ta...@jakarta.apache.org> on 2005/03/28 22:11:17 UTC

[jira] Commented: (TAPESTRY-169) Synchronization problem exists for the engine within a session

     [ http://issues.apache.org/jira/browse/TAPESTRY-169?page=comments#action_61669 ]
     
Martijn Stellinga commented on TAPESTRY-169:
--------------------------------------------

I had the same problem. In my case, I did the following:
1. Submit a login page. 
2. During the submit a visit was created;
3. I activated a new page to render, which was a frameset;
4. The browser would immediately start loading the frames inside the frameset.
Depending on the exact browser timing, the requests for the individual frames would arrive before the engine was saved to the session, resulting in a newly created engine.
If I understand it correctly, any HTML written to the browser that triggers a new request might cause the problem.

I have a workaround, which seems to solve the problem (at least in my case it did). 
I made an override of the org.apache.tapestry.engine.BaseEngine.createVisit method that immediately stores the engine into the session. 
This did require me to copy the code from the org.apache.tapestry.ApplicationServlet.init() method that created the attribute name used to store the engine in the session.
This is the resulting code in my Engine subclass:
protected Object createVisit(IRequestCycle cycle){
    Object visit = super.createVisit(cycle);
    String servletName = cycle.getRequestContext().getServlet().getServletName();
    String attributeName = "org.apache.tapestry.engine:"+servletName;
    HttpSession session = cycle.getRequestContext().getSession();
    if(session == null)
        session = cycle.getRequestContext().createSession();
    session.setAttribute(attributeName,this);
    return visit;
}

I don't know if this is the best solution, but I don't see any other way to store the engine in the session before the wrong HTML is outputed to the browser.

> Synchronization problem exists for the engine within a session
> --------------------------------------------------------------
>
>          Key: TAPESTRY-169
>          URL: http://issues.apache.org/jira/browse/TAPESTRY-169
>      Project: Tapestry
>         Type: Bug
>   Components: Framework
>     Versions: 3.0
>  Environment: Operating System: All
> Platform: All
>     Reporter: alvin shen
>     Assignee: Tapestry Developer List

>
> Take an example:
> I request a page which contains a image asset. The following steps can occur 
> during processing request of this page:
> 1). The framework creates a engine instance to service this request
> 2). The application stores some data into the visit object of this engine
> 3). The framework creates a session due to visit object access
> 4). The framework renders and flushes the resulting html page
> 5). The framework stores the engine into the session previously created
> 6). The framework finishes this cycle of processing
> Between step 4 and step 5 the web browser receives and parse the html page, 
> and it continues to load the contained image, and the following steps will 
> occur at server side:
> a). Tapestry calls getEngine() which may resulting creating a new engine 
> instance, because the engine accessed in the last cycle have not yet been 
> saved to this session yet. 
> b). With this engine, tapestry continues to process the image request with 
> AssetService
> c). At this point, step 5 of last cycle occurs and the engine accessed by that 
> cycle is saved to this session
> d). Tapestry continues to save engine accessed this cycle to the same session 
> which results in overrides the engine stored last cycle. And all visit data 
> associated with the overrided engine get lost!

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org