gpt4 book ai didi

java - ColdFusion Javacast 数组从 loadPaths 到类时出错

转载 作者:行者123 更新时间:2023-11-30 05:56:59 25 4
gpt4 key购买 nike

我正在尝试使用 Elasticsearch 的 Java API。

我正在尝试创建一个 RestClientBuilder .

Host=createObject("java", "org.apache.http.HttpHost").init(variables.HostName, variables.Port);
Node=createObject("java", "org.elasticsearch.client.Node").init(Host);

RestClient=createObject("java", "org.elasticsearch.client.RestClient").builder(Javacast("org.elasticsearch.client.Node[]", [Node])).build();

我收到错误

Cannot convert the value to Java array because type org.elasticsearch.client.Node is unknown.

另外,如果我只是尝试使用:

RestClient=createObject("java", "org.elasticsearch.client.RestClient").builder(Javacast("org.apache.http.HttpHost[]", [Host]));

我收到以下错误

Either there are no methods with the specified method name and argument types or the builder 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.

我认为这是因为 ColdFusion 与 varargs 不能很好地配合

最佳答案

我找到了使用此方法的解决方法

https://www.bennadel.com/blog/1980-tojava---a-coldfusion-user-defined-function-for-complex-java-casting.htm

我相信未使用 Javacast 和 javaSettings loadPaths 时存在错误。

coldfusion.runtime.Cast$UnknownTypeException: Cannot convert the value to Java array because type org.elasticsearch.client.Node is unknown. at coldfusion.runtime.Cast.toJavaArray(Cast.java:1602)

此外,如果我尝试执行 UDF 采取的操作

local.javaClass = createObject("java", "org.apache.http.HttpHost");
local.HostArrayReflect = createObject("java", "java.lang.reflect.Array");
local.HostArray = local.HostArrayReflect.newInstance(
local.javaClass.GetClass()
, JavaCast( "int", ArrayLen(local.Hosts))
);
for (i=0; i LT ArrayLen(local.Hosts); i=i+1) {
local.HostArrayReflect.Set(local.HostArray, JavaCast("int", i), local.Hosts[i]);
}

我收到错误

An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. If the class has a constructor that accepts an argument, you must call the constructor explicitly using the init(args) method. Error : org.apache.http.HttpHost

java.lang.NoSuchMethodException: org.apache.http.HttpHost.() at java.lang.Class.getConstructor0(Class.java:3082) at java.lang.Class.newInstance(Class.java:412) at coldfusion.runtime.java.JavaProxy.createObjectWithDefaultConstructor(JavaProxy.java:209) at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:92)

当我尝试运行 getClass() 时会发生这种情况,但在 UDF 中没有问题。一位同事尝试在 Lucee 上运行此程序,并且似乎有效,因此我相信 CF 中存在与此相关的错误。

关于java - ColdFusion Javacast 数组从 loadPaths 到类时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52996435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com