I'm trying to get javaLoader to run in a Coldfusion8 application and I need some help to get me across the finish line.
This is what I have so far:
Inside application.cfc:
...
THIS.mappings["/javaloader"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "tools/javaloader";
...
<cffunction name="onApplicationStart" returnType="boolean" output="false" hint="application initalizer">
<cfscript>
Application.str = structNew();
Application.str.myJavaLoaderKey = "someUUID_javaloader";
Application.str.jarPaths = arrayNew(1);
</cfscript>
<cfif ( NOT structKeyExists(server, Application.str.myJavaLoaderKey) )>
<!--- add path to class files to jarPath Array --->
<cfset Application.str.jarPaths[1] = expandPath("/classes/BCrypt.class")>
<!--- this will map out to: ...htdocs/classes/BCrypt.class --->
<cfif ( NOT structKeyExists(server, Application.str.myJavaLoaderKey) )>
<cflock name="#Hash(Application.str.myJavaLoaderKey)#" type="exclusive" timeout="10">
<cfset server[Application.str.myJavaLoaderKey] = createObject("component", "javaloader.JavaLoader")>
<!--- tried .init(Application.str.jarPaths) here, but didn't do anything --->
</cflock>
</cfif>
</cfif>
<cfreturn true />
</cffunction>
This was done following instructions from here and here.
In my handler.cfc, I'm trying to access javaloader and the BCrypt class like so:
<cfsript>
pass = "some_password";
<!--- this is accessible --->
cryptonite = server[Application.str.myJavaLoaderKey];
<!--- now trying to call init() with respective path to create an instance --->
<!--- BREAKS HERE --->
bCrypt = cryptonite.init(Application.str.jarPaths[1]);
hashed = bCrypt.hashpw(pass, bcrypt.gensalt());
</cfscript>
I can dump the cryptonite variable allright, but when I try to create the instance of BCrypt, the script fails.
Question:
I'm happy I made it this far, but I've been sitting on this for a few hours now with no clue what I'm doing wrong. Hopefully someone with more insight can point me in a direction?
Thanks for help!
Ok. There were a couple of mistakes.
To setup Javaloader with Coldfusion8 and BCrypt or a Java Class of your choice, do the following:
1) Put whatever Java Classes (the .java file, not the .class file) in a folder in your webroot/htdocs(Apache). My path for BCrypt looks like this:
2) Do the same for javaloader. My path looks like this:
3) In Application.cfc:
The setup should be in the application scope as per here. This should set up all .java classes which you can now reference from elsewhere like so:
Figured it out reading through here. Turns out you have to refer to the .java file and not the .class file, which I initally did.
The following links may also be helpful:
http://blog.mxunit.org/2011/02/hashing-passwords-with-bcrypt-in.html
http://www.compoundtheory.com/javaloader/docs/
http://www.aliaspooryorik.com/blog/index.cfm/e/posts.details/post/using-bcrypt-in-coldfusion-10-370