Apache Unexpected subelement exception while generating a webservice client
Asked Answered
G

2

7

I'm trying to generate a webservice client with wsdl2java from axis2 (version 1.6.1).

./wsdl2java.sh -uri http://www.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/efetch_snp.wsdl

When I call this service, I get an Exception.

org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement {http://www.ncbi.nlm.nih.gov/soap/eutils/efetch_snp}Rs

    try {
        EFetchSnpServiceStub fetchService = new EFetchSnpServiceStub();
        EFetchSnpServiceStub.EFetchRequest reqIdSnp = new EFetchSnpServiceStub.EFetchRequest();
        reqIdSnp.setId("193925233");
        EFetchSnpServiceStub.EFetchResult resIdSnp = fetchService.run_eFetch(reqIdSnp);
    } catch (Exception e) {
        System.out.println(e.toString());
    }   

With soaptest however I can see the Rs Tag in the result.

<Rs rsId="193925233" snpClass="snp" snpType="notwithdrawn" molType="genomic" bitField="050000000005000000000100" taxId="3702">

How can I fix this exception? The WSDL is not under my control.

Geostatics answered 11/4, 2012 at 20:24 Comment(4)
There is no "however" -- Axis complains about the element being there, not absent.Lorenza
Yes but what can I do that axis accepts this Rs tag?Geostatics
Nobody can answer that before we see the complete response, at least up to the point where the element Rs occurs, as well as the relevant parts of the WSDL (the element type declarations). Maybe the service's response really is violating the WSDL contract, that's entirely possible. Maybe it uses a newer WSDL than the one you have.Lorenza
Thanks. So this error occurs because of a wrong wsdl input. I will ask the provider of the wsdl.Geostatics
E
11

Unexpected subelement error mostly occur in Axis2 in ADB databinding type. When the sequence of tags coming in SOAP response is not same as that of attributes in java class formed from wsdl.

For example,

If response or request XML must have a, b, c elements in a sequence and actual XML has a, d, c elements in the sequence, then Axis2 would complain saying that it received an Unexpected element named d.

It can be resolved by changing the sequence of tags in wsdl.

Note : If this is not the case, check here for other reasons

Eisenberg answered 12/4, 2012 at 7:17 Comment(2)
The link appears to be broken.Earnestineearnings
You can check this one instead: http://axis.apache.org/axis2/java/core/faq.html#unexpected_subelementSchoen
I
1

I just had the same problem with NCBI eutils and solved it by editing the wsdl file and then regenerating the client classes locally. I used soaptest as you did to see exactly what it was expecting and then made them match up. In my case, they were missing the element named "DbBuild" in their DbInfoType object.

Immensurable answered 12/2, 2014 at 19:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.