问题描述
我想让javaLoader在Coldfusion8应用程序中运行,我需要一些帮助让我跨越终点线。
这是我有的far:
内部 application.cfc :
...
THIS.mappings [/ javaloader] = GetDirectoryFromPath(GetCurrentTemplatePath())& tools / javaloader;
...
< cffunction name =onApplicationStartreturnType =booleanoutput =falsehint =application initalizer>
< cfscript>
Application.str = structNew();
Application.str.myJavaLoaderKey =someUUID_javaloader;
Application.str.jarPaths = arrayNew(1);
< / cfscript>
< cfif(NOT structKeyExists(server,Application.str.myJavaLoaderKey))>
<!---将类文件的路径添加到jarPath Array --->
< cfset Application.str.jarPaths [1] = expandPath(/ classes / BCrypt.class)>
<!---这将映射到:... htdocs / classes / BCrypt.class --->
< cfif(NOT structKeyExists(server,Application.str.myJavaLoaderKey))>
< cflock name =#Hash(Application.str.myJavaLoaderKey)#type =exclusivetimeout =10>
< cfset server [Application.str.myJavaLoaderKey] = createObject(component,javaloader.JavaLoader)>
<!---试试.init(Application.str.jarPaths)这里,但没有做任何事情--->
< / cflock>
< / cfif>
< / cfif>
< cfreturn true />
< / cffunction>
这是根据和。
在我的 handler.cfc javaloader和BCrypt类是这样的:
< cfsript&
pass =some_password;
<!--- this is accessible --->
cryptonite = server [Application.str.myJavaLoaderKey];
<!---现在试图调用init()与相应的路径创建一个实例--->
<!--- BREAKS HERE --->
bCrypt = cryptonite.init(Application.str.jarPaths [1]);
hashed = bCrypt.hashpw(pass,bcrypt.gensalt());
< / cfscript>
我可以转储cryptonite变量allright,但是当我尝试创建BCrypt的实例时,脚本失败。
问题:
我很高兴我做得很远,这几个小时现在没有线索我做错了。
感谢您的帮助!
确定。有几个错误。
要设置具有Coldfusion8和BCrypt的Javaloader或您选择的Java类,请执行以下操作:
1)将任何Java类(.java文件,而不是.class文件)放在webroot / htdocs(Apache)的文件夹中。我的BCrypt路径如下:
htdocs / classes / jBCrypt /
/ pre>
2)对javaloader执行相同操作。我的路径如下所示:
htdocs / tools / javaloader /
3)在 Application.cfc 中:
<!--- create mapping to javaloder --->
< cfscript>
THIS.mappings [/ javaloader] = GetDirectoryFromPath(GetCurrentTemplatePath())& tools / javaloader;
< / cfscript>
<!--- Application start --->
< cffunction name =onApplicationStartreturnType =booleanoutput =falsehint =>
< cfscript>
<!---在应用程序范围内存储UUID和emptry路径数组--->
Application.str = structNew();
Application.str.myJavaLoaderKey =your_uuid_javaloader;
Application.str.jarPaths = arrayNew(1);
< / cfscript>
<!---检查是否存在--->
< cfif(NOT structKeyExists(server,Application.str.myJavaLoaderKey))>
<!---把所有的.java文件路径放在这里,这是JBCrypt --->
< cfset Application.str.jarPaths [1] = expandPath(/ classes / jBCrypt-0.3)>
< cfif(NOT structKeyExists(server,Application.str.myJavaLoaderKey))>
< cflock name =#Hash(Application.str.myJavaLoaderKey)#type =exclusivetimeout =10>
<!--- create javaloader object and init with all submitted paths --->
< cfset server [Application.str.myJavaLoaderKey] = createObject(component,javaloader.JavaLoader)init(sourceDirectories = Application.str.jarPaths)>
< / cflock>
< / cfif>
< / cfif>
< / cffunction>
安装程序应该位于。这应该设置所有.java类,你现在可以从其他地方引用如下:
< cfscript&
var pass =a_password;
javaLoader = server [Application.str.myJavaLoaderKey];
//创建javaloader-BCrypt的实例
bcrypt = javaLoader.create(BCrypt)。init();
//现在你可以从bcrypt调用方法,如:
hashed = bcrypt.hashpw(pass,bcrypt.gensalt());
< / cfscript>
想通读。原来,你必须参考 .java 文件,而不是 .class 文件,这是我原来做的。
以下链接也可能有所帮助:
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:
htdocs/classes/jBCrypt/
2) Do the same for javaloader. My path looks like this:
htdocs/tools/javaloader/
3) In Application.cfc:
<!--- create mapping to javaloder ---> <cfscript> THIS.mappings["/javaloader"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "tools/javaloader"; </cfscript> <!--- Application start ---> <cffunction name="onApplicationStart" returnType="boolean" output="false" hint=""> <cfscript> <!--- store a UUID and emptry path array in Application scope ---> Application.str = structNew(); Application.str.myJavaLoaderKey = "your_uuid_javaloader"; Application.str.jarPaths = arrayNew(1); </cfscript> <!--- check if exists ---> <cfif ( NOT structKeyExists(server, Application.str.myJavaLoaderKey) )> <!--- put all paths to your .java files here, this is for JBCrypt ---> <cfset Application.str.jarPaths[1] = expandPath("/classes/jBCrypt-0.3")> <cfif ( NOT structKeyExists(server, Application.str.myJavaLoaderKey) )> <cflock name="#Hash(Application.str.myJavaLoaderKey)#" type="exclusive" timeout="10"> <!--- create javaloader object and init with all submitted paths ---> <cfset server[Application.str.myJavaLoaderKey] = createObject("component", "javaloader.JavaLoader").init(sourceDirectories=Application.str.jarPaths )> </cflock> </cfif> </cfif> </cffunction>
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:
<cfscript> var pass = "a_password"; javaLoader = server[Application.str.myJavaLoaderKey]; // create an instance of javaloader-BCrypt bcrypt = javaLoader.create("BCrypt").init(); // now you can call methods from bcrypt like so: hashed = bcrypt.hashpw(pass, bcrypt.gensalt()); </cfscript>
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这篇关于如何在Coldfusion8中使用javaloader设置java库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!