[coldbox-3.7.0] injecting an interceptor with a Coldspring object

I am working on a security interceptor and I am having trouble injecting a Coldspring object into it. I have seen some older responses on the list regarding setting up the IOC object in the configure (here config) method of the interceptor, but the setIOCFramework() and setIOCFactory() methods seem not to exist any longer.

From this thread:
https://groups.google.com/forum/#!searchin/coldbox/interceptor$20with$20Ioc/coldbox/cS2s09IW5o0/Olm9ufgEfHQJ

`

var ioc = getPlugin("ioc");

ioc.setIOCFramework(’
coldspring’);
// get the factory from the application scope.
ioc.setIOCFactory( application.coldspring );
//You can create your own coldspring factory here too and do all you need here too.

//That’s it. I just configured manually the IOC plugin.


`

I have also tried ading the ioc settings as a property in the interceptor definition:

// Coldbox.cfc

`
{ class=“interceptors.HTTPSecurity”,
properties={ioc=ioc} },

`

and then accessing the IOC object (with or without the above property in Coldbox.cfc )

`

//interceptor definition
component {

property name=“ioc” inject=“ioc”;

void function configure(){
variables.SecurityService = ioc.getBean( “SecurityService” );
}

}

`

None of this seems to be working. With this latest configuration (showed here) I get a#

The containsBean method was not found.

error in the IOC plugin, line 123, which says to me that the IOC plugin is not configured.

I also tried extending the Interceptor class and setting up the IOC object in my init() method

`
component extends=‘coldbox.system.Interceptor’{

any function init(required coldbox.system.web.Controller controller, required struct properties){
super.init(argumentcollection=arguments);
var ioc = getPlugin( “ioc” ).init( controller=arguments.controller );

variables.SecurityService = ioc.getBean( “SecurityService” );
return this;
}

}

`

I feel like I am missing something obvious. Can anyone show me how to wire this up so I can access my Coldspring object inside my interceptor?

Thanks

Robert

This is also not working.

Any reason why you are configuring this manually and not via the IOC settings in the configuration file?

Also any reason you are using such an antiquated di engine?

Hi Luis, thanks for your reply. Why Coldspring? I’ve been using Coldspring for awhile and it is in my comfort zone.I wrote the server-side app using Coldspring and a service layer. When I ported the rest of the code, I just brought over the entire model rather than re-wire it in Wirebox. I have been trying to avoid re-wiring it just yet, although I might be well served to do it now rather than later as the model grows.

As for why I am not configuring it in the IOC settings in the config file, I’ve been working with Coldbox for about a week, so I have not yet gotten around to learning all the ins and outs of the configuration file. :slight_smile: I’m watching the Udemy course and raking in as much material as I can through the wiki and Google, but I’m still a newbie for the moment.

I did create a workaround to solve my problem by plugging the authentication mechanism into the role-checking method in the IOC SecurityService, but I prefer a solution that keeps them separate. The right thing to do is re-wire the model and rid myself of this issue, but since the model runs well, I am reluctant to modify it just before release. I haven’t even touched Cachebox yet, so there is plenty to do once I get a stable build in production.

Thanks to you and everyone else who has contributed to Coldbox, you’ve made me a believer.

Robert

Depending on how involved your models are, you may find that switching to Wirebox, not as hard as you think. With the most basic of models, you would be able to just drop them or add the path to WireBox and just inject away.

Hi Luis, thanks for your reply. Why Coldspring? I’ve been using Coldspring for awhile and it is in my comfort zone.I wrote the server-side app using Coldspring and a service layer. When I ported the rest of the code, I just brought over the entire model rather than re-wire it in Wirebox. I have been trying to avoid re-wiring it just yet, although I might be well served to do it now rather than later as the model grows.

Understandable. In all reality moving to WireBox should be transparent. We even have a tool in the ColdBox Platform Utilities to migrate your ColdSpring XML file to a WireBox binder. In all my migrations, they have been transparent as DI works on contracts, so those won’t change.

As for why I am not configuring it in the IOC settings in the config file, I’ve been working with Coldbox for about a week, so I have not yet gotten around to learning all the ins and outs of the configuration file. :slight_smile: I’m watching the Udemy course and raking in as much material as I can through the wiki and Google, but I’m still a newbie for the moment.

No problem, we where all there :slight_smile: The configuration file can setup ColdSpring for you with the appropriate configuration file, so it is seamlessly used in your application.

I did create a workaround to solve my problem by plugging the authentication mechanism into the role-checking method in the IOC SecurityService, but I prefer a solution that keeps them separate. The right thing to do is re-wire the model and rid myself of this issue, but since the model runs well, I am reluctant to modify it just before release. I haven’t even touched Cachebox yet, so there is plenty to do once I get a stable build in production.

Thanks to you and everyone else who has contributed to Coldbox, you’ve made me a believer.

Thank you Robert! It has been now over 7 years since the first public beta of ColdBox and we are still pushing the envelope. We are even more excited than when we started the project.

That’s very helpful, but I am writing the binder file by hand so I get some understanding of how the mappings work in Wirebox, and I would like to eliminate all the boilerplate code of init with arguments in favor of injection through cfproperty.

One thing seems not to be working for me, and I don’t understand quite why. In my Event Handlers, I tried to wire in my services using property tags, but it failed to work and gave me an error like “Invalid property definition”. With Coldspring, I had been using init() methods in my handlers and just defining the services manually, so I went back to that technique and it seems to be working. Below is a snippet of the configuration that failed. I commented out the property definition and went back to the init() method, and that is working, but I can’t say why. I wrote the binder and eliminated all the init arguments in favor of property injection in the components, and I defined the Wirebox ioc settings in the coldbox file. Property injection in the Event Handlers is the only thing that isn’t working so far.

Beyond this injection issue, and barring some additional testing, I think I have migrated over the whole app to Coldbox.

`
// this config didn’t work

property name=“UserService” inject=“model”;

/* function init( required any controller ){
super.init( arguments.controller );
variables.ioc = getPlugin(“ioc”);
variables.UserService = getPlugin(“ioc”).getBean(“UserService”);
return this;
}*/
`

I see you are injecting via “model” namespace, but you are using ColdSpring right?

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Can you give us more information on this “Invalid property definition” error. Such as the code you were using at the time and the full stack trace of the error message?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Luis, I just switched from Coldspring to Wirebox yesterday. Overall the switch was fairly painless, as predicted, although I still have a lot to learn about the Wirebox binder.

Brad, here is some of my config that causes the error. Note that I have commented out the init() method and am using cfproperty injection.

Coldbox.cfc

`
//IOC Integration
ioc = {
framework = “wirebox”,
reload = false,
objectCaching = true,
definitionFile = “#path#WireBox”
};

`

Coldbox finds the Wirebox binder and everything works, except property injection in the handlers. Here is an example.

/handlers/General.cfc

`

`

When I run this configuration and I try to hit the homepage, I get this error (full stack trace):

coldfusion.compiler.ScriptParseExceptions$InvalidPropertyException: Invalid definition for Property. at coldfusion.compiler.ScriptParseExceptions.throwInvalidPropertyException(ScriptParseExceptions.java:130) at coldfusion.compiler.cfml40.throwPropertyError(cfml40.java:4535) at coldfusion.compiler.cfml40.cfml(cfml40.java:4592) at coldfusion.compiler.cfml40.start(cfml40.java:4871) at coldfusion.compiler.NeoTranslator.parsePage(NeoTranslator.java:694) at coldfusion.compiler.NeoTranslator.parsePage(NeoTranslator.java:675) at coldfusion.compiler.NeoTranslator.parseAndTransform(NeoTranslator.java:428) at coldfusion.compiler.NeoTranslator.translateJava(NeoTranslator.java:370) at coldfusion.compiler.NeoTranslator.translateJava(NeoTranslator.java:147) at coldfusion.runtime.TemplateClassLoader$TemplateCache$1.fetch(TemplateClassLoader.java:442) at coldfusion.util.LruCache.get(LruCache.java:180) at coldfusion.runtime.TemplateClassLoader$TemplateCache.fetchSerial(TemplateClassLoader.java:362) at coldfusion.util.AbstractCache.fetch(AbstractCache.java:58) at coldfusion.util.SoftCache.get_statsOff(SoftCache.java:133) at coldfusion.util.SoftCache.get(SoftCache.java:81) at coldfusion.runtime.TemplateClassLoader.findClass(TemplateClassLoader.java:622) at coldfusion.runtime.MetadataUtils.getComponentMetadata(MetadataUtils.java:129) at coldfusion.runtime.MetadataUtils.getComponentMetadata(MetadataUtils.java:115) at coldfusion.runtime.CfJspPage.GetComponentMetadata(CfJspPage.java:2744) at cfUtil2ecfc1064726892$funcGETINHERITEDMETADATA.runFunction(D:\webroot\coldbox\system\core\util\Util.cfc:305) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:655) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432) at cfMapping2ecfc179865792$funcPROCESS.runFunction(D:\webroot\coldbox\system\ioc\config\Mapping.cfc:578) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:518) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:660) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:469) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2373) at cfInjector2ecfc115662079$funcGETINSTANCE.runFunction(D:\webroot\coldbox\system\ioc\Injector.cfc:249) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:655) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432) at cfHandlerService2ecfc972355190$funcNEWHANDLER.runFunction(D:\webroot\coldbox\system\web\services\HandlerService.cfc:120) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2659) at cfHandlerService2ecfc972355190$funcGETHANDLER.runFunction(D:\webroot\coldbox\system\web\services\HandlerService.cfc:141) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:655) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432) at cfController2ecfc1715339667$funcRUNEVENT.runFunction(D:\webroot\coldbox\system\web\Controller.cfc:550) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:518) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:660) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:469) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2373) at cfColdbox2ecfc1139464707$funcPROCESSCOLDBOXREQUEST.runFunction(D:\webroot\coldbox\system\Coldbox.cfc:236) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2659) at cfColdbox2ecfc1139464707$funcONREQUESTSTART.runFunction(D:\webroot\coldbox\system\Coldbox.cfc:382) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:655) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432) at cfApplication2ecfc693062914$funcONREQUESTSTART.runFunction(D:\git\legacyavatar\www\Application.cfc:58) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:655) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414) at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:108) at coldfusion.runtime.AppEventInvoker.onRequestStart(AppEventInvoker.java:278) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:417) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:112) at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94) at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62) at coldfusion.CfmServlet.service(CfmServlet.java:219) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414) at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:204) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:722)

Everything else is running ok,.

I can comment out the cfproperty tags and use the init method and that works fine.

Remove the ioc bit from your config. If you’re completely on WireBox, you don’t need it. The only WireBox config you would need might be this optional bit:

// wirebox integration wirebox = {
	singletonReload = true,
	binder = 'config.WireBox'
};

Only set singletonReload to true on dev though.

Are you sure that error is coming from that handler? Is the handler script or tags? Where in the file are the property tags? Is there a space between the two attributes in your property tag? perhaps you can send the entire CFC file for us to look at.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

The issue is that you are using the IOC plugin to integrate to WireBox instead of natively. So you cannot use “model” or the “id” namespace because they are not activated. You will have to sue the “ioc” namespace instead unless you integrate how Brad showed you.

That’s the difference

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

10-4. Brad just helped me sort it out.

Thanks for the pointers, everything is looking solid now.

Robert

FYI, I had a block of cfscript in between the component definition and the cfproperty tags, that was the source of the error. Sometimes it’s the little things.