Start Application from Proxy

All,

I have an issue that I have data continually flowing into my server via a gateway (think three dozen gateway events per minute). When the server reboots, the gateway hits the application (via proxy) before a page is called to initiate the application, throwing an error as the application isn’t loaded. Is it possible to init the application without calling a web page?

Thanks,
John

Check out how the coldbox.system.remote.ColdboxProxy works as it’s meant to be a bridge into a ColdBox app. As long as your Application.cfc has the necessary bits to load ColdBox, it should always exist in the application scope. If your event gateways are located in a sub folder from the web root, just make sure you set up the coldbox app mapping and config file location in the Application.cfc so it can load up properly.

Can you share with us the error you are receiving?

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

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

The event gateway instance points to the cfc (gateway.cfc) in subfolder of my application’s root named “remote” (a la the ColdBox proxy documentation example). The gateway instance configuration file is likewise in that “remote” subfolder. So the gateway.cfc targeted by the event gateway extends the ColdBox proxy and utilized my application’s application.cfc. The application.cfc does indeed have the proper settings as the site works fine, just not the gateway event. Specifically, the COLDBOX_APP_MAPPING setting points to the root of my application.

To simplify the basics at this point, gateway.cfc consists of a single function - OnIncomingMessage(required struct gatewayEvent). For testing, this function does one thing only: it logs a simple “hello” using the writeLog() function.

To test, I restart my ColdFusion Application Server and turn on the event gateway (currently have startup mode set to manual while I am testing). When an incoming gateway event hits gateway.cfc, I get the following message in the coldfusion-out.log:

Jan 4, 2017 6:06:27 PM Error [Thread-16] - Error invoking CFC for gateway [GATEWAY NAME]: Event handler exception. {GATEWAYTYPE={Socket},CFCMETHOD={onIncomingMessage},DATA={…},GATEWAYID={[GATEWAY NAME]},CFCTIMEOUT={[TIMEOUT VALUE]},ORIGINATORID={[XXXX]},CFCPATH={[PATH TO GATEWAY.CFC]}}.

If however, I then pull up a page from my site, subsequent gateway events produce the following:

Jan 4, 2017 6:11:02 PM Information [Thread-16] - Proxy Hello

> Jan 4, 2017 6:06:27 PM Error [Thread-16] - Error invoking CFC for gateway [GATEWAY NAME]: Event handler exception. {GATEWAYTYPE={Socket},CFCMETHOD={onIncomingMessage},DATA={…},GATEWAYID={[GATEWAY NAME]},CFCTIMEOUT={[TIMEOUT VALUE]},ORIGINATORID={[XXXX]},CFCPATH={[PATH TO GATEWAY.CFC]}}.

What’s the actual error message? The text above doesn’t seem to actually be an error at all.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

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

Digging deeper, the specific error in the exception.log is:

An exception occurred while invoking an event handler method from Application.cfc. The method name is: onApplicationStart."

30212 coldfusion.runtime.EventHandlerException: Event handler exception.
30213 at coldfusion.runtime.AppEventInvoker.onApplicationStart(AppEventInvoker.java:239)
30214 at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:336)
30215 at coldfusion.filter.EventRequestMonitorFilter.invoke(EventRequestMonitorFilter.java:47)
30216 at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
30217 at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
30218 at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
30219 at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
30220 at coldfusion.eventgateway.EventProxy.invokeComponent(EventProxy.java:66)
30221 at coldfusion.eventgateway.EventProxy.invokeComponent(EventProxy.java:47)
30222 at coldfusion.eventgateway.EventRequestHandler.invokeCFC(EventRequestHandler.java:185)
30223 at coldfusion.eventgateway.EventRequestHandler.processRequest(EventRequestHandler.java:111)
30224 at coldfusion.eventgateway.EventRequestDispatcher$Task.run(EventRequestDispatcher.java:130)
30225 at coldfusion.util.SimpleWorkerThread.run(SimpleThreadPool.java:214)
30226 Caused by: coldfusion.runtime.CfJspPage$NoSuchTemplateException: Could not find the ColdFusion component or interface C:.inetpub.wwwroot.[APPLICATIONFOLDER].remote…config.Coldbox.

I’m now creating log points inside application.cbBootstrap.loadColdbox(); to try to determine exactly what is happening.

> Could not find the ColdFusion component or interface C:.inetpub.wwwroot.[APPLICATIONFOLDER].remote…config.Coldbox.

Have you configured the COLDBOX_CONFIG_FILE setting in your Application.cfc?

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

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

COLDBOX_CONFIG_FILE is an empty string, be it for starting from event gateway or from web site.

Then that’s your problem. I said to make sure you set the path to the config file in my first reply :slight_smile:

If the mapping for the ColdBox app is “” then the config file should probably be “config.Coldbox”.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

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

Brad,

Thanks for pointing that out to me a second time since I thought the default COLDBOX_CONFIG_FILE was ok since it worked for web.

I have now set the COLDBOX_CONFIG_FILE. This, however, only got me part of the way. For those who come across this in the future, the following are all the things I needed to do to make the site work after the application gets initialized via a gateway event:

  • Set the COLDBOX_CONFIG_FILE instead of having it default. Should be something like COLDBOX_APP_MAPPING & “.config.Coldbox”;

  • The “new Coldbox()” call I had in application.cfc did not include the fourth parameter, COLDBOX_APP_MAPPING. Be sure to include this in your new Coldbox() call.

  • If you not using ColdFusion’s built-in web server, set a mapping for “/” to the root of your actual web server. If you don’t, ExpandPath("/") will result in the built-in ColdFusion web server’s root, not your actual web server root.

  • Replace the default baseURL in \config\routes.cfm. Out of the box, baseURL is set as follows:

if( len(getSetting(‘AppMapping’) ) lte 1){
setBaseURL(“https://#hostName##getContextRoot()#/”);
}
else{
setBaseURL(“https://#hostName##getContextRoot()#/#getSetting(‘AppMapping’)#/”);
}

However, for event gateway calls getContextRoot() yields the CFC path setting in the gateway instance instead of the typical empty string of a web call to the application. So you’ll need to determine dynamic baseURLs in another fashion that suits your application. Two options are to write code in routes.cfm that accurately determines the baseURL, or use an application variable to track if the site has been initialized for Web use and, if not, reload Coldbox. Another option is to override the baseURL on each event call via the method outlined in Google Groups.

John