[ColdBox 4.1] Custom Interceptor for system settings

98 views
Skip to first unread message

Chad Baloga

unread,
May 19, 2015, 1:47:01 PM5/19/15
to col...@googlegroups.com
I am trying to setup a custom interceptor which will grab some data from a database and set those as session variables which can be used throughout the user's session.  First off, is an interceptor the way to go with this?  Second,  I am getting the error below.  I have never written my own interceptor so this is all new to me.   Any help is greatly appreciated.  Thanks!  

Error:

Event: security.Home 
Routed URL: N/A 
Layout: lay_default.cfm (Module: ) 
View: v_warning 
Timestamp: 05/19/2015 01:39:55 PM
Type: InterceptorService.InvalidInterceptionState 
Messages: The interception state sent in to process is not valid: beforeDebuggerPanel Valid states are [afterConfigurationLoad, afterAspectsLoad, preReinit, onException, onRequestCapture, onInvalidEvent, afterHandlerCreation, afterInstanceCreation, applicationEnd, sessionStart, sessionEnd, preProcess, preEvent, postEvent, postProcess, preProxyResults, preLayout, preRender, postRender, preViewRender, postViewRender, preLayoutRender, postLayoutRender, preModuleLoad, postModuleLoad, preModuleUnload, postModuleUnload, afterCacheElementInsert, afterCacheElementRemoved, afterCacheElementExpired, afterCacheElementUpdated, afterCacheClearAll, afterCacheRegistration, afterCacheRemoval, beforeCacheRemoval, beforeCacheReplacement, afterCacheFactoryConfiguration, beforeCacheFactoryShutdown, afterCacheFactoryShutdown, beforeCacheShutdown, afterCacheShutdown, afterInjectorConfiguration, beforeInstanceCreation, afterInstanceInitialized, beforeInstanceInspection, afterInstanceInspection, beforeInjectorShutdown, afterInjectorShutdown, beforeInstanceAutowire, afterInstanceAutowire]

My interceptor code right now is as follows:

In ColdBox.cfc in the interceptor array:  {class="interceptors.appInit"}

<cfcomponent hint="This is a appInit interceptor"
output="false"
extends="coldbox.system.Interceptor">

<!------------------------------------------- CONSTRUCTOR ------------------------------------------->

<cffunction name="configure" access="public" returntype="void" hint="This is the configuration method" output="false">
<cfscript>
</cfscript>
</cffunction>

<!------------------------------------------- INTERCEPTION POINTS ------------------------------------------->

<!--- After Config Load --->
<cffunction name="afterConfigurationLoad" access="public" returntype="void" output="false">
  <cfargument name="event" required="true" hint="The event object.">

<cfscript>
var oSession = getInstance('SessionStorage@cbstorages');
oSession.setVar("mysetting","testing!!");
</cfscript>
</cffunction>

</cfcomponent>

br...@bradwood.com

unread,
May 19, 2015, 2:00:57 PM5/19/15
to col...@googlegroups.com
Without the stack trace, I can't really tell what's going on, but I'm guessing you're using the cbdebugger module and it's trying to announce an interception point before it's been registered with the interceptor service.
 
I don't think any of the code you showed in your interceptor is an issue.  However, I do think you're a bit confused about what interceptor point to use.  afterConfigurationLoad will only fire ONCE-- after the app inits.  Therefore, if you want to set session data for every single user's session, you will want to use a different interception point-- namely sessionStart.
 
 
You may also want to consider simply having a session-scoped CFC that stored data related to the user.  Just put the scope annotation at the top of your component like so:
 
component scope="session" {}
 
Ask WireBox to give you the CFC any time you need it.  All the creation and persistence will handled automatically for you.  A separate CFC will be created for each user's session and get stored in the session scope but you won't have to do nearly as much work.  
 
Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/577f15cc-c033-452a-88cd-903046b44a1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chad Baloga

unread,
May 19, 2015, 2:03:47 PM5/19/15
to col...@googlegroups.com
OK, I got the error to go away and the session setting working.  Still would like some feedback if this is the best route to go.  Thanks!

Chad Baloga

unread,
May 19, 2015, 8:59:48 PM5/19/15
to col...@googlegroups.com

Ok thanks.  These are the system settings which don't really apply to the user but settings which are used for session timeouts, inactivity durations etc and are used as a user is in the system (guess I kind of worded it poorly).  The reason for storing in database is so that sys admins can change these settings. 

The data associated w the actual user is done w a user bean w setters and getters.

Thanks
Chad


--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to a topic in the Google Groups "ColdBox Platform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/coldbox/USNI5e2g-6M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to coldbox+u...@googlegroups.com.

To post to this group, send email to col...@googlegroups.com.

Chad Baloga

unread,
May 21, 2015, 8:41:34 AM5/21/15
to col...@googlegroups.com
Is there any way to clear out the components in the session scope besides restarting the ColdFusion service?  Fwreinit does seem to do the job.  

Thanks!
Chad

br...@bradwood.com

unread,
May 21, 2015, 10:32:38 AM5/21/15
to col...@googlegroups.com
In all sessions, or just the current one?  
 
If you want to clear all sessions, no there is no way to do it unless you set some application-level flag and have each request check, it and do a clear on the session scope then.
If you want to just clear the current session structClear( session ) will work, but perhaps you can explain what you're trying to do.
--------- Original Message ---------

Chad Baloga

unread,
May 21, 2015, 11:05:42 AM5/21/15
to col...@googlegroups.com
I was just adding some properties to my bean, and I can only get it to re-init and get the new properties by restart the CF service.

Thanks,
Chad

You received this message because you are subscribed to a topic in the Google Groups "ColdBox Platform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/coldbox/USNI5e2g-6M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to coldbox+u...@googlegroups.com.

To post to this group, send email to col...@googlegroups.com.

br...@bradwood.com

unread,
May 21, 2015, 11:19:59 AM5/21/15
to col...@googlegroups.com
If you're just testing for yourself, I've created an interceptor in the past that looks for ?clearsession=1 in the URL and just does a structClear( session )  You can also do it on fwreinit.  There's even an interception point for that.
--------- Original Message ---------
Reply all
Reply to author
Forward
0 new messages