简体   繁体   English

将CFML参数转换为Java类以进行Web服务调用时出错

[英]Error converting CFML arguments to Java classes for web service invocation

I am trying to consume a WSDL from ColdFusion using cfinvoke tag and I am having problems passing arguments. 我试图使用cfinvoke标签从ColdFusion中使用WSDL,并且我在传递参数时遇到问题。 If it's a simple STRING or NUMERIC argument, it works good. 如果它是一个简单的STRING或NUMERIC参数,那么效果很好。 The problem is when I need to pass this argument: 问题是当我需要传递这个论点时:

<part name="options" type="soap-enc:Array"/>

Well, I tried different ways: pass a ColdFusion ARRAY, STRUCT, simple string, etc. Nothing works. 好吧,我尝试了不同的方法:传递ColdFusion ARRAY,STRUCT,简单的字符串等。没有任何作用。 In some cases I got a response from the web service telling that the parameter is missing and when I pass a structure, I am getting this error: 在某些情况下,我收到来自Web服务的响应,告诉参数丢失,当我传递结构时,我收到此错误:

Error converting CFML arguments to Java classes for web service invocation. 将CFML参数转换为Java类以进行Web服务调用时出错。 Unable to create web service argument class [Ljava.lang.Object;. 无法创建Web服务参数类[Ljava.lang.Object;。 Error: java.lang.InstantiationException: [Ljava.lang.Object;. 错误:java.lang.InstantiationException:[Ljava.lang.Object;。 Often this is because the web service defines an abstract complexType as an input to an operation. 这通常是因为Web服务将抽象complexType定义为操作的输入。 You must create an actual instance of this type in Java. 您必须在Java中创建此类型的实际实例。

You can see the script in action here: 您可以在此处查看脚本:

cf wsdl web service test cf wsdl web服务测试

There you have the link to the web service definitions. 在那里,您可以链接到Web服务定义。 What should I do? 我该怎么办? How do I pass simple Array objects to WSLD from ColdFusion? 如何从ColdFusion将简单的Array对象传递给WSLD?

The lack of transparency around complex SOAP objects like you see here are a big reason why JSON is much preferred as a data format these days. 像你在这里看到的那样,复杂SOAP对象之间缺乏透明度是JSON目前作为数据格式首选的一个重要原因。 I've written Java components to deal with this kind of thing. 我编写了Java组件来处理这类事情。 You need to know the specific format of the options variable (the second argument), which is an array of Objects, though it gives no details. 您需要知道options变量的特定格式(第二个参数),它是一个Objects数组,尽管它没有提供任何细节。 I don't have a completely working solution for you, but this code should get you most of the way there. 我没有一个完全可行的解决方案,但是这段代码应该可以帮到你。

<cfscript>
    ws = createObject("webservice", "https://api.iritravel.ro/?wsdl");
    res = ws.getCountries(token = "137e8f1a094-1031");
    country = createObject( "java", "java.util.HashMap" ).init();
    country.put( 'CountryId', 2 );
    res2 = ws.getTowns( token = "137e8f1a094-1031", options=[ country ] );
    writedump( res2 );
    writedump( country );
</cfscript>

If I get it working I will post an update, but you might be able to get it done using what I have here. 如果我开始工作,我会发布更新,但您可以使用我在这里的内容完成它。 I have created a HashMap (basic Java object) and added a key "CountryId" with a value of 2. See the way I formatted the options argument as an array and passed the country HashMap object to it as the first element of the array. 我创建了一个HashMap(基本Java对象),并添加了一个值为2的键“CountryId”。请参阅我将options参数格式化为数组的方式,并将国家HashMap对象作为数组的第一个元素传递给它。 That bit of the code works, so you just need to know the specific format of the Object the service is expecting. 这段代码可以工作,所以你只需要知道服务所期望的Object的特定格式。

Update 更新

I have included a SOAPUI-generated request for getTowns() which shows the problem is the same whether using webservices calls or cfhttp. 我已经包含了一个SOAPUI生成的getTowns()请求,它表明无论是使用webservices调用还是cfhttp,问题都是一样的。 In this case, I have added a CountryId parameter to the request, and what I get back is the same response I got from the previous call - param CountryId is missing. 在这种情况下,我在请求中添加了一个CountryId参数,我得到的是与前一次调用相同的响应 - param CountryId缺失。 So the issue is the same - the format of the Object Array that the service is expecting to consume is incorrect. 所以问题是一样的 - 服务期望消耗的对象数组的格式是不正确的。

http://pastebin.com/ZXBS2e2r http://pastebin.com/ZXBS2e2r

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM