English 中文(简体)
3.1.3 发送复杂型号,有pache xml rpc客户
原标题:sending complex type with apache xml rpc client 3.1.3

So I m trying to send an xml-rpc message to moses xml-rpc server in Java, but keep getting error:

org.apache.xmlrpc.XmlRpcException: Parameter that is supposed to be a structure is not

I m using Apache xmlrpc client 3.1.3 from http://ws.apache.org/xmlrpc/client.html. My guess is the parameter definition is not compatible, but after experimenting with different type to use as input, the output is still the same. I have an example of the client, but it s written in perl:

#!/usr/bin/env perl

use Encode;
use XMLRPC::Lite;
use utf8;

$url = "http://localhost:8080/RPC2";
$proxy = XMLRPC::Lite->proxy($url);

$text = "il a souhaité que la présidence trace à nice le chemin pour l  avenir .";

# Work-around for XMLRPC::Lite bug
$encoded = SOAP::Data->type(string => Encode::encode("utf8",$text));

my %param = ("text" => $encoded, "align" => "true");
$result = $proxy->call("translate",\%param)->result;
print $result->{ text } . "
";
if ($result->{ align }) {
    print "Phrase alignments: 
";
    $aligns = $result->{ align };
    foreach my $align (@$aligns) {
        print $align->{ tgt-start } . "," . $align->{ src-start } . "," 
            . $align->{ src-end } . "
"; 
    }
}

我的守则是:

XmlRpcClientConfigImpl tConf = new XmlRpcClientConfigImpl();
try {
    tConf.setServerURL(new URL("http://127.0.0.1:8080/RPC2"));
    tConf.setBasicEncoding("UTF-8");
} catch (MalformedURLException ex) {
    ex.printStackTrace(System.out);
}
XmlRpcClient tClient = new XmlRpcClient();
tClient.setConfig(tConf);

List<List<String>> tInPar = new ArrayList<>();
tInPar.add(Arrays.asList(new String[]{"text", "hello"}));
tInPar.add(Arrays.asList(new String[]{"align", "true"}));

String tResult = null;
try {
    tResult = (String) tClient.execute("translate", tInPar);
} catch (XmlRpcException ex) {
    ex.printStackTrace(System.out);
}

Is it correct?

感谢您的帮助

最佳回答

在寄信标表上咨询后,I ve被介绍为这一 j客户的蚊子服务器实例:

增 编

问题回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签