Unable to correctly initialize xml-security library using ColdFusion 10.0

我的未来我决定 提交于 2019-12-12 04:48:39

问题


I am using the following to initialize in CF 10 and I placed the xmlsec-1.5.8.jar file under Coldfusion10/cfusion/lib

<cfset Init = CreateObject("Java", "org.apache.xml.security.Init.Init()")> 

I have also tried placing the above code in a cfscript as

Init = CreateObject("Java", "org.apache.xml.security.Init.Init()");

I am getting the following error.

You must initialize the xml-security library correctly before you use it. Call the static method "org.apache.xml.security.Init.init();" to do that before you use any functionality from that library.

Thank you.


回答1:


In addition to the syntax error, there is another problem. The error message is indicating you must call a static method of that class first. One that is literally named init(). The problem is init() has a special meaning in CF. CF does not allow using the new keyword with java objects. Instead, it uses the name init() as a pseudo-constructor, which allows you to create a new instance of a class. So when you do this:

obj = createObject("java", "org.apache.xml.security.Init").init();

CF will create a new instance of that class, NOT call a method named init(). AFAIK, the only way around it is to use reflection. Something along these lines:

  // get a reference to the class
  ref = createObject("java", "org.apache.xml.security.Init");
  // initialize if needed
  if (!ref.isInitialized()) {
      // find static method named "init" with no parameters
      method = ref.getClass().getDeclaredMethod("init", []);
      // invoke it via reflection
      method.invoke(ref, javacast("null", ""));
  } 

placed the xmlsec-1.5.8.jar file under Coldfusion10/cfusion/lib

While there is nothing wrong with doing that, as of CF10, you can also load jars dynamically via your Application settings, ie this.javaSettings. If the feature seems familiar, it is basically a rip of Mark Mandel's awesome JavaLoader.cfc, only baked into CF ;-)



来源:https://stackoverflow.com/questions/29480784/unable-to-correctly-initialize-xml-security-library-using-coldfusion-10-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!