I am upgrading from Railo 3 to 4, and have run into a problem with the old Application.cfc. The Application.cfc fails on the following line in the OnRequest method:
content = invoke(controller = controllerPath, method = URL.action, arguments = {'data':FORM,'options':URL});
This is partial content of the error:
Railo 4.1.1.009 Error (template)
Message missing required argument [object] for function [invoke]
Pattern invoke(object:any, name:string [, arguments:any]):object
Documentation invokes a function/operation of the given object and if given object is a string, Railo tries to load as component.
Required:
- object (any): a component, struct or scope that holds a function, can also be the name of a component, in this case the component get loaded.
- name (string): name of the function/operation
Optional:
- arguments (any): arguments to pass to the function/operation
Stacktrace The Error Occurred in /home/admin/quicktrackweb/src/web/cf3/Application.cfc: line 215
213: dynFunc = view[URL.action];
214:
215: content = invoke(controller = controllerPath, method = URL.action, arguments = {'data':FORM,'options':URL});
216: //content = "test";
217: if (GetMetaData(dynFunc).access == 'remote') {
Java Stacktrace missing required argument [object] for function [invoke] at railo.transformer.bytecode.expression.var.Variable.getMatchingValueAndType(Variable.java:700):700 at railo.transformer.bytecode.expression.var.Variable._writeOutFirstBIF(Variable.java:458):458 at railo.transformer.bytecode.expression.var.Variable._writeOutFirst(Variable.java:419):419 at railo.transformer.bytecode.expression.var.Variable._writeOut(Variable.java:238):238 at railo.transformer.bytecode.expression.var.Variable._writeOut(Variable.java:219):219 at railo.transformer.bytecode.expression.ExpressionBase.writeOut(ExpressionBase.java:34):34 ...
Here is the OnRequest method:
public void function OnRequest (required string TargetPage) {
var content = '';
var controllerPath = '';
var dynFunc = '';
var isDebug = false;
var output = '';
var response = '';
var templatePath = 'views/login/login.cfm';
var toolbar = CreateObject('component', 'controllers.toolbar');
var view = '';
import 'controllers.ajax';
//ssl implemtation
if (!CGI.SERVER_PORT_SECURE) {
Location("http://#CGI.SERVER_NAME#/?#CGI.QUERY_STRING#", false);
}
param name='URL.view' type='string' default='home';
param name='URL.action' type='string' default='';
param name='URL.id' type='numeric' default=0;
param name='URL.options' type='string' default='';
URL.view = REReplace(URL.view, '\W', '', 'all');
if (StructKeyExists(URL, 'faq')) {
templatePath = "views/home/faq.cfm";
} else if (SESSION.user.id || (URL.view == 'login' && URL.action == 'new')) {
if (StructKeyExists(GetHttpRequestData().headers, 'ajax')) {
var ajax = new ajax(request = GetHttpRequestData(), url = URL, form = FORM, cookie = COOKIE);
Header(name = 'Content-Type', value = 'application/json');
WriteOutput(ajax.getResponse());
return;
} else {
if (URL.action == '') {
URL.action = ListGetAt(URL.view, ListLen(URL.view, '.'), '.');
}
if (hasFunction('controllers.' & URL.view, URL.action) || hasFunction('controllers.#URL.view#.#URL.view#', URL.action)) {
if (hasFunction('controllers.' & URL.view, URL.action)) {
controllerPath = 'controllers.#URL.view#';
} else {
controllerPath = 'controllers.#URL.view#.#URL.view#';
}
view = CreateObject('component', controllerPath);
dynFunc = view[URL.action];
========> Line where app fails: content = invoke(controller = controllerPath, method = URL.action, arguments = {'data':FORM,'options':URL});
if (GetMetaData(dynFunc).access == 'remote') {
GetPageContext().getResponse().reset();
Header(name = 'Content-Type', value = 'application/json');
WriteOutput(content);
return;
}
templatePath = '';
} else if (FileExists("views/#URL.view#/#URL.view#.cfm")){
templatePath = "views/#URL.view#/#URL.view#.cfm";
} else{
templatePath = "views/home/home.cfm";
}
}
}
if (content == '' && FileExists(templatePath)) {
savecontent variable = 'content' {include '#templatePath#';}
}
if (CGI.SCRIPT_NAME == '/js/webapp.cfm') {
Header(name = 'Content-Type', value = 'application/javascript');
include '/js/webapp.cfm';
} else if (CGI.SCRIPT_NAME == '/css/webapp.cfm') {
Header(name = 'Content-Type', value = 'text/css');
include '/css/webapp.cfm';
} else {
include '/index.cfm';
}
//Return out.
return;
}
Sorry for blasting all this code, but since I am fairly new to Railo/CF, I am not sure where to start. Has invoke been deprecated, and what should I put in place of it?
It seems like the invoke is completely different from the previous version because it is expecting an argument "object", but I have arguments "controller", "method", and "arguments"
My version of Railo is 4.1.1.009 I am running on a Ubuntu server with Apache 2.2.22 and Tomcat 7.0.20
By going back to Railo 3.3.4.003 final, matching the production server, it works. 3.3.4.003 does have ColdFusion compatibility with 9.0.0.1. I think this is why it works now, and I did not have to make any changes to the code in Application.cfc, other than to remove the http redirect where it checks for !CGI.SERVER_PORT_SECURE (caused a redirect loop, which I commented out).
If my thinking is wrong here, please let me know.