Skip to main content
Participating Frequently
June 15, 2011
Question

onSessionEnd not working as expected

  • June 15, 2011
  • 2 replies
  • 788 views

I have read many posts by people who have problems with onSessionEnd.  This is my first conversion of application.cfm to application.cfc and the onSessionEnd is not working with the CFFunction I am trying to invoke.

I guess what's hanging this up is how to properly call the component from the /lib/components/ folder where it resides.

When a user logs in I am creating a session array that tracks a jobNumber and the last_completed_step in that job.  There are multiple jobs in a users session.  At the end of the session I want to write the updated array data back to the DB.

I should make it clear that at present I look into my log file and see that the session is started - as coded in the onSessionStart shown below.  Furthermore, the onSessionEnd also writes to the log file when I take out the invocation of the component.  In other words if I just tell it to write "Session ended." to the log file I will see it in the log file. I have set current session timeout in CF Administrator and my app.cfc for 3 minutes for testing.

If I call the "giveMeAnswer" method in the jobState.cfc from a separate file (also at the root level) the giveMeAnswer method works properly and returns the value "I am a CFC."

If I move the jobState.cfc to the root level and set the component attribute to "jobState" I am also getting a return from the component.

<!--- Runs when your session starts --->

<cffunction name="onSessionStart" returnType="void" output="false">

    <!--- :: invoke all session variables | moved out of on session start  :: --->

    <cfinvoke component="#application.virtualPaths.cfcPath#system/sessionVars" method="init" />

    <cflog file="#This.Name#" type="Information" text="Session started.">

    </cffunction>

<!--- Runs when session times out --->

<cffunction name="onSessionEnd" returntype="void">

    <cfargument name="SessionScope" type="struct" required="true" />

    <cfargument name="ApplicationScope" type="struct" required="true" />

    <cfinvoke component="/lib/components/jobState" method="giveMeAnswer" returnvariable="returnFromCfc">

    </cfinvoke>

    <cflog file="#This.Name#" type="Information" text="Session ended.  #returnFromCfc#">

    <cfreturn />

</cffunction>

So, is it just not finding the component?  Any other ideas?

Thanks much, Jerry

This topic has been closed for replies.

2 replies

Inspiring
June 15, 2011
    <cfinvoke component="/lib/components/jobState" method="giveMeAnswer" returnvariable="returnFromCfc">  

I'm surprised that way of referencing a CFC works.  You should be using dot notation, not giving CFINVOKE a path.  This, though, has nothing to do with your issue, it's just an observation.

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e0a.html

--

Adam

Inspiring
June 15, 2011

It appears that you are trying to access a session variable after the session has ended. 

Participating Frequently
June 15, 2011

Maybe I need to do something to pass the session.jobStepArray to the component?

Like the argument might be: sessionScope.session.jobStepArray

...session.jobStepArray being the array I want to process in the CFC.  I thought that since the session.jobStepArray already existed I would not need to "send" it to the function.

Owainnorth
Inspiring
June 15, 2011

Read the docs, they will tell you all.

You can access shared scope variables as follows:

• You must use the SessionScope parameter to access the Session scope. You  cannot reference the Session scope directly; for example, use  Arguments.SessionScope.myVariable, not Session.myVariable.

• You must use the ApplicationScope parameter to access the Application  scope. You cannot reference the Application scope directly; for example,  use Arguments.ApplicationScope.myVariable, not Application.myVariable.  Use a named lock when you reference variables in the Application scope,  as shown in the example.

• You can access the Server scope directly; for example,  Server.myVariable.

• You cannot access the Request scope.