You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Stavrinides <p....@albourne.com> on 2007/04/25 17:44:43 UTC

Session invalidate question

Hi Everyone,

I want to redirect to a page (other than my home page) and invalidate 
the session there.

After i call invalidate I get an exception that states the session has 
already been invalidated, even if I invalidate the session on the target 
page in pageEndRender. The question is how do I delay the invalidate on 
the target page long enough to prevent this exception.

For Example:

public void pageEndRender(PageEvent e) {
        if (getRequest().getSession(false) != null){
            try {
                //some clean up code here
                getRequest().getSession(false).invalidate();
            } catch (Exception ex){
                 //XXX -Exception still appears at runtime in tomcat 
which cannot be caught
            }
        }
    }

Produces The following  stack trace:
WARN - Exception during post-request cleanup: setAttribute: Session 
already invalidated
 - org.apache.tapestry.error.RequestExceptionReporterImpl (45) 
java.lang.IllegalStateException: setAttribute: Session already invalidated
        at 
org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1251)
        at 
org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1233)
        at 
org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:129)
        at 
org.apache.tapestry.web.ServletWebSession.setAttribute(ServletWebSession.java:62)
        at 
org.apache.tapestry.engine.state.SessionScopeManager.store(SessionScopeManager.java:90)
        at 
$StateObjectPersistenceManager_1122965794b.store($StateObjectPersistenceManager_1122965794b.java)
        at 
org.apache.tapestry.engine.state.StateObjectManagerImpl.store(StateObjectManagerImpl.java:56)
        at 
org.apache.tapestry.engine.state.ApplicationStateManagerImpl.flush(ApplicationStateManagerImpl.java:87)
        at 
$ApplicationStateManager_1122965778e.flush($ApplicationStateManager_1122965778e.java)
        at 
$ApplicationStateManager_1122965778f.flush($ApplicationStateManager_1122965778f.java)
        at 
org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:283)
        at 
org.apache.tapestry.services.impl.InvokeEngineTerminator.service(InvokeEngineTerminator.java:54)
        at 
$WebRequestServicer_1122965784e.service($WebRequestServicer_112296578

etc....

Thanks
Peter




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


Re: Session invalidate question

Posted by Peter Stavrinides <p....@albourne.com>.
This is great Matt! thanks.

Matt Larson wrote:
> Peter,
>
> I have encountered a similar problem, and I think that the problem was 
> not in my code, but in where I was doing the session.invalidate().  In 
> trying to remove a cookie on logout, I found that I needed to do the 
> invalidation in an IEngineService.  You can then do a redirect to 
> whatever page you want at that time.
> This may not fit your needs, but what I did was to create my own 
> service via this configuration point in Hivemind:
>
> <service-point id="LogoutService" 
> interface="org.apache.tapestry.engine.IEngineService">
>        <invoke-factory>
>            <construct class="tapestry.LogoutService">
>                <set-service property="request" 
> service-id="tapestry.globals.HttpServletRequest" />
>                <set-service property="response" 
> service-id="tapestry.globals.HttpServletResponse" />
>                <set-object property="servletPath" 
> value="app-property:org.apache.tapestry.servlet-path" />
>                <set-object property="linkFactory" 
> value="infrastructure:linkFactory" />
>            </construct>
>        </invoke-factory>
>    </service-point>
>
> <contribution configuration-id="tapestry.services.FactoryServices">
>        <service name="logout" object="service:LogoutService" />
>    </contribution>
>
> Then in my service method of my engine class, I did the cookie 
> handling and the session.invalidate() using parts of the code from 
> Tapestry's logout service:
>
> public void service(IRequestCycle cycle) throws IOException {
>        HttpSession session = _request.getSession(false);
>
>        if (session != null) {
>            try {
>                session.invalidate();
>            } catch (IllegalStateException ex) {
>                logger.warn("Exception thrown invalidating 
> HttpSession.", ex);
>
>                // Otherwise, ignore it.
>            }
>        }
>
>        ....[do cookie handling]
>
>        _response.sendRedirect("page_to_redirect_to.html");
>    }
>
> Hope that helps.
>
> Cheers,
> Matt
>
> Peter Stavrinides wrote:
>> Hi Everyone,
>>
>> I want to redirect to a page (other than my home page) and invalidate 
>> the session there.
>>
>> After i call invalidate I get an exception that states the session 
>> has already been invalidated, even if I invalidate the session on the 
>> target page in pageEndRender. The question is how do I delay the 
>> invalidate on the target page long enough to prevent this exception.
>>
>> For Example:
>>
>> public void pageEndRender(PageEvent e) {
>>        if (getRequest().getSession(false) != null){
>>            try {
>>                //some clean up code here
>>                getRequest().getSession(false).invalidate();
>>            } catch (Exception ex){
>>                 //XXX -Exception still appears at runtime in tomcat 
>> which cannot be caught
>>            }
>>        }
>>    }
>>
>> Produces The following  stack trace:
>> WARN - Exception during post-request cleanup: setAttribute: Session 
>> already invalidated
>> - org.apache.tapestry.error.RequestExceptionReporterImpl (45) 
>> java.lang.IllegalStateException: setAttribute: Session already 
>> invalidated
>>        at 
>> org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1251) 
>>
>>        at 
>> org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1233) 
>>
>>        at 
>> org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:129) 
>>
>>        at 
>> org.apache.tapestry.web.ServletWebSession.setAttribute(ServletWebSession.java:62) 
>>
>>        at 
>> org.apache.tapestry.engine.state.SessionScopeManager.store(SessionScopeManager.java:90) 
>>
>>        at 
>> $StateObjectPersistenceManager_1122965794b.store($StateObjectPersistenceManager_1122965794b.java) 
>>
>>        at 
>> org.apache.tapestry.engine.state.StateObjectManagerImpl.store(StateObjectManagerImpl.java:56) 
>>
>>        at 
>> org.apache.tapestry.engine.state.ApplicationStateManagerImpl.flush(ApplicationStateManagerImpl.java:87) 
>>
>>        at 
>> $ApplicationStateManager_1122965778e.flush($ApplicationStateManager_1122965778e.java) 
>>
>>        at 
>> $ApplicationStateManager_1122965778f.flush($ApplicationStateManager_1122965778f.java) 
>>
>>        at 
>> org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:283) 
>>
>>        at 
>> org.apache.tapestry.services.impl.InvokeEngineTerminator.service(InvokeEngineTerminator.java:54) 
>>
>>        at 
>> $WebRequestServicer_1122965784e.service($WebRequestServicer_112296578
>>
>> etc....
>>
>> Thanks
>> Peter
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

-- 
Peter Stavrinides
Albourne Partners (Cyprus) Ltd
Tel: +357 22 750652 

If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Please visit http://www.albourne.com/email.html for important additional terms relating to this e-mail. 



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


Re: Session invalidate question

Posted by Matt Larson <sw...@ldnet.org>.
Peter,

I have encountered a similar problem, and I think that the problem was 
not in my code, but in where I was doing the session.invalidate().  In 
trying to remove a cookie on logout, I found that I needed to do the 
invalidation in an IEngineService.  You can then do a redirect to 
whatever page you want at that time. 

This may not fit your needs, but what I did was to create my own service 
via this configuration point in Hivemind:

<service-point id="LogoutService" 
interface="org.apache.tapestry.engine.IEngineService">
        <invoke-factory>
            <construct class="tapestry.LogoutService">
                <set-service property="request" 
service-id="tapestry.globals.HttpServletRequest" />
                <set-service property="response" 
service-id="tapestry.globals.HttpServletResponse" />
                <set-object property="servletPath" 
value="app-property:org.apache.tapestry.servlet-path" />
                <set-object property="linkFactory" 
value="infrastructure:linkFactory" />
            </construct>
        </invoke-factory>
    </service-point>

<contribution configuration-id="tapestry.services.FactoryServices">
        <service name="logout" object="service:LogoutService" />
    </contribution>

Then in my service method of my engine class, I did the cookie handling 
and the session.invalidate() using parts of the code from Tapestry's 
logout service:

 public void service(IRequestCycle cycle) throws IOException {
        HttpSession session = _request.getSession(false);

        if (session != null) {
            try {
                session.invalidate();
            } catch (IllegalStateException ex) {
                logger.warn("Exception thrown invalidating 
HttpSession.", ex);

                // Otherwise, ignore it.
            }
        }

        ....[do cookie handling]

        _response.sendRedirect("page_to_redirect_to.html");
    }

Hope that helps.

Cheers,
Matt

Peter Stavrinides wrote:
> Hi Everyone,
>
> I want to redirect to a page (other than my home page) and invalidate 
> the session there.
>
> After i call invalidate I get an exception that states the session has 
> already been invalidated, even if I invalidate the session on the 
> target page in pageEndRender. The question is how do I delay the 
> invalidate on the target page long enough to prevent this exception.
>
> For Example:
>
> public void pageEndRender(PageEvent e) {
>        if (getRequest().getSession(false) != null){
>            try {
>                //some clean up code here
>                getRequest().getSession(false).invalidate();
>            } catch (Exception ex){
>                 //XXX -Exception still appears at runtime in tomcat 
> which cannot be caught
>            }
>        }
>    }
>
> Produces The following  stack trace:
> WARN - Exception during post-request cleanup: setAttribute: Session 
> already invalidated
> - org.apache.tapestry.error.RequestExceptionReporterImpl (45) 
> java.lang.IllegalStateException: setAttribute: Session already 
> invalidated
>        at 
> org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1251) 
>
>        at 
> org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1233) 
>
>        at 
> org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:129) 
>
>        at 
> org.apache.tapestry.web.ServletWebSession.setAttribute(ServletWebSession.java:62) 
>
>        at 
> org.apache.tapestry.engine.state.SessionScopeManager.store(SessionScopeManager.java:90) 
>
>        at 
> $StateObjectPersistenceManager_1122965794b.store($StateObjectPersistenceManager_1122965794b.java) 
>
>        at 
> org.apache.tapestry.engine.state.StateObjectManagerImpl.store(StateObjectManagerImpl.java:56) 
>
>        at 
> org.apache.tapestry.engine.state.ApplicationStateManagerImpl.flush(ApplicationStateManagerImpl.java:87) 
>
>        at 
> $ApplicationStateManager_1122965778e.flush($ApplicationStateManager_1122965778e.java) 
>
>        at 
> $ApplicationStateManager_1122965778f.flush($ApplicationStateManager_1122965778f.java) 
>
>        at 
> org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:283) 
>
>        at 
> org.apache.tapestry.services.impl.InvokeEngineTerminator.service(InvokeEngineTerminator.java:54) 
>
>        at 
> $WebRequestServicer_1122965784e.service($WebRequestServicer_112296578
>
> etc....
>
> Thanks
> Peter
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


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