I'm trying to implement a .Net component in a Coldfusion application (this is on my development machine running CF 11.
I set up the object like this:
<cfset dll = ExpandPath('./com/Interop.CADXLib.dll')>
<cfobject class="CADXLib.CadX" type=".NET" name="cadx" assembly="#dll#”>
That’s in my application.cfc, in the onRequestStart() method. Then in my index.cfm I call:
<cfdump var="#cadx#”>
The object dumps just fine. I can see all the internal methods, including the one I need to get things going, the OpenDesign() method, which (in theory) opens a local file and reads the contents.
So next I set the actual filename I want to access:
<cfset thisfile="1571269P01R01_ARTIOS.ARD">
<cfset thispath=getDirectoryfromPath(getCurrentTemplatePath())>
<cfset thisfile=thispath & thisfile>
This works, and outputting “thistfile” gives me the correct path location. So now I call the actual method:
<cfset result=cadx.OpenDesign(thisfile,0)>
That’s where I get stuck. I get this error:
Either there are no methods with the specified method name and argument types or the OpenDesign method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.
I try the javacast function:
<cfset result=cadx.OpenDesign(JavaCast("string",thisfile),JavaCast("int",0))>
Same error. Method not found. But based on the dump, the method is clearly there.
Has anyone encountered this or something similar?
Related
I need to write an application for a client that calls a method from a ".dll" file. The ".dll" file was previously executed manually from an ".exe" GUI but now they want to automate the process.
I never worked with .dll files so everything that I found until now is the result of a complete day of research, I also received a small documentation with this tool:
The interface is an ActiveX DLL which provides two functions (GetUnitInfo and SaveResult).
In the moment I just want to run the "GetUnitInfo" method from the Winwdows command line using RUNDLL32.exe.
This is the documentation for the "GetUnitInfo" method:
The interface for GetUnitInfo is as follows:
Public Function GetUnitInfo( _
ByVal strRequest As String, _
ByRef strUnitInfo As String,
Optional ByVal strStationName As String = "") As Long
Sample calling code can be:
Dim lRet As Long
Dim strXML as String
lRet = GetUnitInfo( _“<?xml version=""1.0"" ?><GetUnitInfo
xmlns=""urn:GetUnitInfo-schema"" SerialNumber=""BD3ZZTC8MA"" />", strXML)
So I tried to run this method with some dummy parameters because the method returns an error if the parameters are not OK. The command:
RUNDLL32.EXE FFTester.dll, GetUnitInfo test1, test2
But I receive this error:
I used "Dependency Walker" to list the functions from the dll file:
But this are all the functions, normally I would expected that also "GetUnitInfo" is listed.
Can somebody help? It is not mandatory to use RUNDLL32.
Later edit:
I want to call this DLL from a tool that is written in JAVA, I tried to use JNA but I failed so I was thinking to call the dll functions from the command line because if this works I can use a process builder to execute the command.
I fixed my problem and I will provide a solution, maybe it will help someone else.
I used com4j library to generate the interfaces for my dll. After this you need to register your DLL otherwise most problely your code will throw an "ComException", you can read more in my second question.
To register a DLL:
C:\Windows\SysWOW64>regsvr32.exe "path to your DLL" for 32 bit DLL
Or
C:\Windows\System32>regsvr32.exe "path to your DLL" for 64 bit DLL
Also depending on your DLL type, 32 or 64 bit, you need to use proper Eclipse/JDK.
I just started learning about groovy and trying to transpose my java code to groovy scripts. Usually java allows you have a class with only methods that you can call from other classes. I wanted to translate that to groovy. I have in one file - lets call it File1- a method like this:
def retrieveData(String name){
// do something
}
and in the second file, File2, I call File1 like this:
def file1Class = this.class.classLoader.parseClass(new File("../File1.groovy"))
and then try to call the method in File1 like this:
def data = file1Class.retrieveData("String")
but it keeps giving me this error - MissingMethodException:
groovy.lang.MissingMethodException: No signature of method: static File1.retrieveData() is applicable for argument types: (java.lang.String) values: [String] Possible solutions: retrieveData(java.lang.String)
so it does recognize that I am sending in the correct number of parameters and even the correct object, but it isn't running the method as it should?
Is there something I am missing? I tried to remove the object definition from the method - in other words - like this:
def retrieveData(name){
// do something
}
but that didn't work either. I am clueless about what the next step would be. Can anyone please help push me in the right direction? I would greatly appreciate it.
See the answer provided in this StackOverflow reponse.
Use the GroovyScriptEngine class. What does the GroovyScriptEngine do? From the docs:
Specific script engine able to reload modified scripts as well as
dealing properly with dependent scripts.
See the example below.
def script = new GroovyScriptEngine( '.' ).with {
loadScriptByName( '..\File1.groovy' )
}
this.metaClass.mixin script
retrieveData()
Note how we use the loadScriptByNamemethod to
Get the class of the scriptName in question, so that you can
instantiate Groovy objects with caching and reloading.
This will allow you to access Groovy objects from files however you please.
Please forgive me, as I am a Java man dabbling in Javascript business :)
I wanted to be able to define a set of integration test cases to be easy to script against a Java application. I thought Javascript would be a perfect language to script against. To that end, I am using the Rhino engine that comes with JDK 7, via Java's Scripting API. The scripts would have access to Java classes already defined in the application, and could be reused to define use case scenarios for integration testing.
In the Java application, I have binded the javascript engine itself to the script as jsengine, so that I can load javascript files (Including a JavaScript file during Rhino eval).
I have two Javascript files, as defined below:
Function.js:
function send(msg) {
send.sendMessage(msg);
}
TestCase.js
jsengine.eval(new java.io.FileReader("Function.js");
sendMsg("Test Message");
I also have the following object defined and binded to the script as "javaobj":
public class TestConnection {
...
public void send(String message) {
// Code to send the string message via JMS
}
}
However, the Rhino engine complains with the following Exception. It seems to not like calling the javaobj's send method, for some reason.
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function send in object
function sendMsg(msg) {...}. (TestCase.js#3) in TestCase.js at line number 3
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:224)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:212)
at com.foo.test.scenario.JavaScriptEngine.execute(JavaScriptEngine.java:56)
at com.foo.test.TestSuite.start(TestSuite.java:88)
at com.foo.test.TestSuite.main(TestSuite.java:41)
Caused by: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function send in object
function sendMsg(msg) {...}. (TestCase.js#3) in TestCase.js at line number 3
at sun.org.mozilla.javascript.internal.ScriptRuntime.constructError(ScriptRuntime.java:3773)
at sun.org.mozilla.javascript.internal.ScriptRuntime.constructError(ScriptRuntime.java:3751)
at sun.org.mozilla.javascript.internal.ScriptRuntime.typeError(ScriptRuntime.java:3779)
at sun.org.mozilla.javascript.internal.ScriptRuntime.typeError2(ScriptRuntime.java:3798)
at sun.org.mozilla.javascript.internal.ScriptRuntime.notFunctionError(ScriptRuntime.java:3869)
at sun.org.mozilla.javascript.internal.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2345)
at sun.org.mozilla.javascript.internal.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2312)
at sun.org.mozilla.javascript.internal.Interpreter.interpretLoop(Interpreter.java:1524)
at sun.org.mozilla.javascript.internal.Interpreter.interpret(Interpreter.java:854)
at sun.org.mozilla.javascript.internal.InterpretedFunction.call(InterpretedFunction.java:164)
at sun.org.mozilla.javascript.internal.ContextFactory.doTopCall(ContextFactory.java:429)
at com.sun.script.javascript.RhinoScriptEngine$1.superDoTopCall(RhinoScriptEngine.java:116)
at com.sun.script.javascript.RhinoScriptEngine$1.doTopCall(RhinoScriptEngine.java:109)
at sun.org.mozilla.javascript.internal.ScriptRuntime.doTopCall(ScriptRuntime.java:3163)
at sun.org.mozilla.javascript.internal.InterpretedFunction.exec(InterpretedFunction.java:175)
at sun.org.mozilla.javascript.internal.Context.evaluateReader(Context.java:1159)
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:214)
... 4 more
Has anyone ever encountered this type of issue with Rhino?
P.S. This question seems related, but no answer given as well (TypeError in Rhino: migration from Java 6 to Java 7)
Looks like I found my own answer. There was a name conflict between the Javascript function and the name of the binded Java object. Both having the same name, the engine tries to call a non-existent method on a Function object!
Silly me... :P
I'm new to sphinx, and I've encountered a few problems:
$1 After setting max_matches = 200 in class searchd in csft.conf, I called
org.sphx.api.test.main(new String[]{"-h", "127.0.0.1","-i", "magnet","-p", "9312", "-l", "100", "keyword"});
in a java main method. The error returned is
Error: searchd error: per-query max_matches=1000 out of bounds (per-server max_matches=200)
As you can see, I've added the param: -l = 100, what else should I set to prevent this error in Java?
$2 I want to use sortMode = SphinxClient.SPH_SORT_TIME_SEGMENTS to have the search result ordering by time desc. My attribute is written like this in csft.conf:
sql_attr_timestamp=UNIX_TIMESTAMP(upload_time) as dt
Could anyone tell me how can I set the attribute in Java code? I've tried to set the sortClause String in java, but it always said that Attribute XXX has not been found.
$3 I want to know whether SphinxClient in Java is thread safe, becaust I don't like to create a SphinxClient instance every time a person do a query.
Thanks in advance!
If the class you are using is https://code.google.com/p/sphinxtools/source/browse/trunk/src/org/sphx/test/test.java?r=2
then the function never even inspects 'argv'. It hardcodes all the variables. There is nothing passed as the third param to setLimits
sql_attr_timestamp simply accepts a column name, no functions or anything. The function call HAS to be in the main sql_query
My java is very rusty, but would have to say no. It stores all sort of state in private varibles. Multiple threads using the client at once will clober them.
We are using some org.apache classes as part of implementing WS Security for a webservice.
variables.paths = arrayNew(1);
variables.paths[1] = getDirectoryFromPath(getCurrentTemplatePath()) & "lib\wss4j-1.5.8.jar";
variables.paths[2] = getDirectoryFromPath(getCurrentTemplatePath()) & "lib\xmlsec-1.4.2.jar";
variables.loader = createObject("component","lib.javaloader.JavaLoader").init(loadPaths=variables.paths,loadColdFusionClassPath=true);
variables.WSConstantsObj = loader.create("org.apache.ws.security.WSConstants");
variables.messageClass = loader.create("org.apache.ws.security.message.WSSecUsernameToken");
variables.secHeaderClass = loader.create("org.apache.ws.security.message.WSSecHeader");
The following code:
<cfset var msg = getMessage()>
produces:
The following code:
<cfset var secHeader = getSecHeader()>
produces:
The following code:
<cfset var env = soapEnv.getDocumentElement()>
produces:
env.getOwnerDocument()
produces a huge structure (too big to include here), which you can view here.
However, the following code:
<cfset e = msg.build(env.GetOwnerDocument(),secHeader)>
throws the error:
The build method was not found.
Either there are no methods with the specified method name and argument types or the build method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.
However the Build() method certainly exists, as per the yellow highlight in the first screenshot.
The error message talks about "...use the javacast function to reduce ambiguity". If this were the problem, how would I apply this solution?
It's not that "build()" doesn't exist but that your signature is incorrect. The 2 arguments for the build method are:
env.GetOwnerDocument(),secHeader
We know that that secHeader is of the class
org.apache.ws.security.message.WSSecHeader
Because your cfdump indicates as much.
That likely means that "env.GetOwnerDocument" is not returning an object of the class
org.w3c.dom.Document
It may be returning an error or a primitive or another class. Instantiate envGetOwnerDocumet() and dump that out and check the class. I think it is screwing up the method signature. That's my best guess anyway.