- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试让 javaLoader 在 Coldfusion8 应用程序中运行,我需要一些帮助才能冲过终点线。
这是我到目前为止所拥有的:
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>
在我的 handler.cfc 中,我尝试访问 javaloader 和 BCrypt 类,如下所示:
<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>
我可以转储 cryptonite 变量,但是当我尝试创建 BCrypt 实例时,脚本失败。
问题:
我很高兴我做到了这一步,但我已经坐了几个小时了,不知道我做错了什么。希望有更多见解的人可以为我指明方向吗?
感谢您的帮助!
最佳答案
好的。有几个错误。
要使用 Coldfusion8 和 BCrypt 或您选择的 Java 类设置 Javaloader,请执行以下操作:
1) 将任何 Java 类(.java 文件,而不是 .class 文件)放入 webroot/htdocs(Apache) 的文件夹中。我的 BCrypt 路径如下所示:
htdocs/classes/jBCrypt/
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="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>
设置应在应用程序范围内,如 here 。这应该设置所有 .java 类,您现在可以从其他地方引用它们,如下所示:
<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>
通读 here 就明白了。结果你必须引用 .java 文件,而不是 .class 文件,我最初是这样做的。
以下链接也可能有帮助:
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
关于java - 如何在 Coldfusion8 中使用 javaloader 设置 java 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10970133/
我是一名优秀的程序员,十分优秀!