How to have one component extend another component? - coldfusion

I'm trying to extend a component in my application located on a local server (the url to access to my application is defined like that: http://my.new.application/)
Here is the structure of my application on the server (I cannot change the name of the main folder) is:
folder my.new.application
application.cfc
index.cfm
Folder
application.cfc
page.cfm
The folder folder has it's own Application.cfc file extending the master
one and overloading the onRequestStart function with an empty one.
But when I try to implement that:
<cfcomponent displayname="Application" extends="my.new.application/Application">
<cffunction name="onRequestStart">
<!--- override the parent implementation to remove authentication for this
part of the application --->
</cffunction>
</cfcomponent>
I get the following error:
Could not find the ColdFusion component or interface my.new.application/Application.
On the production server the main folder is named myApplication. If I do the same:
<cfcomponent displayname="Application" extends="myApplication/Application">
It works perfectly.
Could you please help me in order to solve the problem for the local server ?

Related

Specified the java library in the Application.cfc

We have created a CFX customer tag and a jar file. The jar files are in coldfusion server ../WEB-INF/lib. It processed successfully for years. Recently we are going to upgrade to coldfusion11 linux. For the maintenance concerns, the system admin prefer to move out these library files from server WEB-INF/lib to application local directory.
Here is the code for setting the localpath for coldfusion 10.
Application.cfc
<cfcomponent>
<cfscript>
//this.name = hash( getCurrentTemplatePath() ); // unique app name
this.javaSettings = {
loadPaths: [
"/opt/WebRoot-DEV/afsapps/tp-web-apps/payroll/process/java/lib"
],
loadColdFusionClassPath: true,
reloadOnChange: true,
watchInterval: 100,
watchExtensions = "jar,class"
};
</cfscript>
<cffunction name="OnRequestStart" returnType="void">
<cfargument name="targetPage" type="string" required="true" />
<!--- Include Application.cfm --->
<cfinclude template="Application.cfm" />
</cffunction>
</cfcomponent>
But it doesn't work, could find the jar file. I got this error message:
"The error message is "The CFX custom tag CFX_GenerateGarnishmentDocuments was not found in the custom tag database. You must add custom tags to the database before using them. If you have added your tag to the database, check the spelling of the tag within your template to ensure that it matches the database entry. "
I am not sure we could move the library files to local path, is this feasible? If yes, how to do it?
As the error message says - it is not enough to simply add the jar file. You must also register it in the ColdFusion Adminstrator under "Extensions->CFX Tags" ... A CFX tag is a specific jar file that implements a native API interface to CF so it can be used without java. it's a special thing.
Step 1 is to get your file INTO the class path. You can do this by putting it in the Lib director, or you can specify the path via the JVM args like so:
Restart CF and then register the CFX Tag in the CF Administrator like so:
The class name will be part of the documentation of the CFX tag. To use it you then call it as one thing - CFX_nameofthetag with attributes specified by the documentation.
CFX is basically a wrapper so that you can use something more complex and Java like in a simple primitive values in/out and get something coldfusiony back like a query or struct. It's designed to let you do ColdFusion without knowing a lot of Java. :)

ColdFusion - Cached CFC not refreshing

Running ColdFusion 10 Update 18 on Server 2012 R2 with IIS 8.5. I've made changes to a CFC, and created a new CFC file as well to test. The changes I made aren't being reflected, and the new file returns a 404 File Not Found.
I've done the following:
Checked the Jakarta virtual directory exists
Removed and readded the site with the CF Web Config tool
Cleared the WEB-INF class temporary folder
Clicked all the Clear Cache buttons in CF Admin
Unchecked all cache options in CF Admin
I inherited this setup and do not have any prior ColdFusion experience. Thanks!
Maybe you can add some supplemental functionality to your application.
I adapted this to your fw1init=1 query param.
Your intercept in index.cfm or futher upstream if necessary.
<cfscript>
if (find('404;',CGI.query_string)){
location('index.cfm?fwreinit=1');
}
</cfscript>
In your Application.cfc
<cfscript>
public boolean function OnRequestStart(required string Target){
if (structkeyExists(url, 'fwreinit') and url.fwreinit){
if (isDefined('application')){
structClear(application);
onApplicationStart();
}
if (isDefined('session')){
structClear(session);
onSessionStart();
}
}
}
</cfscript>

Coldfusion RESTful API, No Mapping Found error

This shouldn't be too hard to answer, but the discussions and documentation I've found can be rather unclear.
First of all, a little bit of information about my setup:
I'm on a hosted environment, and going through our ColdFusion admin group can be time-consuming. Therefore, I'm using the
restInitApplication function to register my RESTful web service.
My webroot folder (where my Application.cfm is located) is in
"E:\docs\wwwroot". I can only see, add, edit folders/files from
wwwroot down. I have no idea what's in "e:\docs". I believe that up
above where I cannot see there is another Application.cfm that sets
such things as the serverType (development, staging, or production),
that we (and other ColdFusion sites hosted on this server) use in
various places in our application code.
My pdfRestfulAPI.cfc (the component containing my webservice function) is in this folder,
"e:\docs\wwwroot\RESTservices". My component code looks like this:
<cfcomponent rest="true" >
<cffunction name="pdfconvert" access="remote" returntype="binary"
output="false" produces="application/xml" method="get" >
<cfargument name="sourceWebPageURL" type="string" >
<cfset pdfDoc = "" >
<cfdocument name="pdfDoc"
format="PDF"
src="#sourceWebPageURL#"
saveAsName="sample.pdf" >
</cfdocument>
<cfreturn #pdfDoc#>
</cffunction>
</cfcomponent>
The function itself is not an issue. It just converts a web page to pdf--pass a URL, get a PDF version of that web page. When I set it up as non-RESTful API (SOAP/xml) it works just fine.
In my Application.cfm, I am attempting to register my web service using the following code:
<cfset restInitApplication( getDirectoryFromPath(getCurrentTemplatePath())
& "RESTservices" ) >
This gives me a dir_path attribute of "E:\docs\wwwroot\RESTservices", which seems correct to me. I've omitted the optional mapping_name attribute. When the documentation says that this "can be anything", that is not helpful.
The error that I get in my Application.cfm reads:
coldfusion.rest.RestAppAdapter$InvalidApplicationException: No mapping
found for path E:\docs\wwwroot\RESTservices
Hopefully, I've laid out the details in such a way that anyone could try this out and let me know what I'm doing wrong.
Thanks, everyone!

Session Variables and Remote CFC Calls

Why does ColdFusion not recognize my session variable when I remotely call a CFC?
Example:
I have a CFC that I call using:
http://www.mywebsite.com/CFC/myfunc.cfc?method=dosomething;arg1=foo;arg2=foo2
If I put the following...
<cfdump var="#session#" abort>
...on the very first line of myfunc.cfc, I see a properly displayed cfdump of all of my session variables. However, if I do something simple like:
<cfset myvar = session.datasrc>
I get a 500 error. Element DATASRC is undefined in SESSION.
session.datasrc appears in the cfdump and if I don't access it remotely (like with a <cfinvoke>) it works fine. Am I missing a some property, or a setting in CFIDE? Something somewhere isn't allowing for remote calls to CFC's to access session variables. Thanks.
Calls to a "remote" cfc do maintain session if called through a browser.
<cffunction access="remote" returntype="any" output="No" hint="this hint" name="test">
<cfargument required="false" name="username" type="string" default=""/>
<cfset session.username="#arguments.username#">
<cfreturn session>
</cffunction>
Call the cfc with http://localhost:8500/CFCs/your.cfc?method=test and you will see the session id will remain constant. Call it as http://localhost:8500/CFCs/your.cfc?method=test&username=bob and you will set the session variable, strip off the argument from the url and the session variable is persisted.
If you are calling the remote cfc without using a browser, you will need to "manually" pass in the sessionid as discussed here
Remote calls to a cfc don't have any sense of session. It's always a one shot deal.
If you access the cfc via the url as you have above, you'll gets session because it's like accessing it as a page. The web server will pass through all the elements, such as session cookies, through to the server making the session scope available to the cfc.
If you access the cfc remotely none of this will be available to the component because of the way it was requested.
You should never rely on transient scope variables inside of service methods. Either inject them using something like coldspring to provide dependancy on a "configuration" service or pass values in as arguments.
To be blunt with you, the session scope is absolutely not the right place to be storing datasource names. Given that you're on ColdFusion 9, you might be interested in looking at the application wide datasource setting under Application.cfc
The session isn't the proper scope for variables like a datasource unless you have different datasources for different users. The application scope is the proper location for application-wide variables. I would first try using the application scope and see if you are still having issues. Also check things like variable name spelling, and try to hit that function locally from within the application via a CFINVOKE call (set the function to public if you need to) to see if it works fine locally. Then you know it's probably something with the way you are calling it remotely.

Coldfusion gateway, problem with application.cfc OnRequestStart

My application.cfc uses the OnRequestStart to check users are logged in
<cfif not isDefined("session.auth.isLoggedIn")>
<cfinclude template="loginForm.cfm">
<cfabort>
</cfif>
and this is mangling my attempts to use a gateway service which errors out with
Error invoking CFC for gateway watchInboundFiles: null {GATEWAYTYPE={FileWatcher},ORIGINATORID={},CFCMETHOD={onDelete},DATA={{FILENAME={C:\temp\New Text Document.txt},TYPE={DELETE}}},CFCPATH={F:\ColdFusion9\wwwroot\watch_dir.cfc},GATEWAYID={watchInboundFiles}}.
If I comment out the OnRequestSTart method the gateway works as expected.
Someone else ran into this before here and a solution is apparently to
add a new application.cfc which
extended my original but overrode the
onRequestStart() - which worked
perfectly.
So how do I do that please?
To answer your question:
Your new Application.cfc will live in another directory but extend your original:
<cfcomponent extends="path.to.my.original.Application">
<cffunction name="onRequestStart">
<!--- No login code here --->
</cffunction>
</cfcomponent>
All other functions are available as usual.
Hoep that helps! More info here.
You could also add something to the application.cfc to see if the call is coming from the gateway. If so then skip the if block.