Question

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'} . "\n";
if ($result->{'align'}) {
    print "Phrase alignments: \n";
    $aligns = $result->{'align'};
    foreach my $align (@$aligns) {
        print $align->{'tgt-start'} . "," . $align->{'src-start'} . "," 
            . $align->{'src-end'} . "\n"; 
    }
}

and here is my code:

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?

Thank you for your help

Was it helpful?

Solution

After consulting in moses mailing list, I've been given this java client example for moses server: https://github.com/moses-smt/mosesdecoder/blob/master/contrib/server/SampleClient.java

Thanks

OTHER TIPS

I don't know Java and can't check your code. If your client has any other connection method besides XML transmitted via SOAP, use it! This has been true for any SOAP and most XML APIs I've seen in the past.

Did you run that Perl code and verify that it's working?

If it does: Add some debugging to see what it does and compare this to your script. XMLRPC::Lite claims to be based on SOAP::Lite which has debugging when using

use SOAP::Lite +trace;

Three chances: First, adding this line enables debugging also for XMLRPC::Lite. Second: Add the "+trace" flag to the "use XMLRPM::Lite" line to enable debugging. Third: Maybe SOAP debugging is impossible when being called as XMLRPC::Lite.

Look here for more information: http://metacpan.org/pod/SOAP::Trace

Finally, a packet sniffer like tcpdump may show you what is being transmitted.

I'd suspect that either your XML structure differs from the Perl one's or they differ only by whitespaces, linebreaks or order of elements and the server at the other side is not accepting true XML but a text block with keywords included in < >.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top