[coldbox-4.2] Module and Interceptor issue

Hi!

I’ve got an interceptor that runs onSessionStart(). When the app starts up for the first time, it is unable to locate the cbstorages module. I’m usingthe provider pattern as far as wirebox injecting is concerned. However, this doesn’t mitigate the issue that our onSessionStart() interceptor needs to access cookie and session scopes from within that function and that this probably occurs before the module is loaded.

I suppose I’m asking if there’s a way to know from within the interceptor if the cbstorages module has been loaded yet.

The other solution, I suppose, is to access those scopes directly, but I’d prefer to keep everything abstracted.

Here’s the error:

Could not find the ColdFusion component or interface cbstorages.models.CookieStorage.

Here’s a condensed version of the interceptor code:

<cfset cart.create()>

<cfif comparenocase(cookieStorage.getVar(“adid”), “”) neq 0>

<cfset sessionStorage.setVar(“adid”, left(cookieStorage.getVar(“adid”),15))>

I’ve included the full stack trace below. The interceptor above is onSessionStart.cfc, but the line #'s won’t match up since I took out code that doesn’t affect this issue.

Thanks in advance!!!
-Jamie

Is this issue for every user, or only for the first hit to the application? As long as the app is started up, I don’t see why all the modules wouldn’t be loaded.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Pretty sure it’s just the first hit to the app.

I’m not actually sure the order that the methods in Application.cfc are called? is onSessionStart running before onRequest? i wonder if this is an issue of the framework not having booted up yet due to not having a check to ensure the framework is loaded.

Can you put in some debugging to try and figure the order that stuff is getting called?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

To add a bit more context: This same code worked fine on first app init in CB 3.8.1 when I was using the sessionstorage and cookiestorage plugins. So, it definitely has to do with the modules not being loaded when onSessionStart is called. I was hoping there’s a way to get around that.

According to Adobe (and I’m sure Lucee follows same), the order of function calls from application.cfc is:
https://helpx.adobe.com/coldfusion/cfml-reference/application-cfc-reference/method-summary.html

When a request executes, ColdFusion runs the CFC methods in the following order:

  1. onApplicationStart (if not run before for this application)
  2. onSessionStart (if not run before for this session)
  3. onRequestStart
  4. onRequest/onCFCRequest
  5. onRequestEnd
    The onApplicationEnd, onSessionEnd, and onError CFCs are triggered by specific events.

Jamie,

Declare the properties but omit the injection. Then set the properties manually in your configure() method using Wirebox.

I had a near-exact same issue recently on a CB4 upgrade which used injected plugins in the interceptors. It’s because the interceptors are loaded (but not configured) before the modules. In this case your onSessionStart() isn’t even firing. Coldbox is throwing the error because it’s trying to inject the component with references which don’t yet exist.

HTH,

Jon

Thanks for the advice, Jon. However, I must be doing something incorrectly.

I declared the properties and then I tried to set them to instances of the sessionStorage and cookieStorage CFCs (see code below) and get the following error:

# Requested instance not found: ‘sessionStorage@cbstorages’
The instance could not be located in any declared scan location(s) (models) or full path location
sessionStorage = getInstance("sessionStorage@cbstorages"); cookieStorage = getInstance("cookieStorage@cbstorages");

No, you’re not doing anything wrong. My bad. I forgot I had to move the even further down in the chain of events. They can to go in the afterConfigurationLoad function like so:

void function afterConfigurationLoad(){
        variables.Storage = variables.Wirebox.getInstance( "sessionStorage@cbstorages" );
    }

Yep, that seemed to work. Thank you very much!