0

I am developing a jax-ws client, I am trying to handle an ArrayList returned as a response, but i had always empty list.

Returned list is NOT empty, I am sure that WebService provider is returning data in that list, I checked that using SoapUI.

there is generated client related files:

 @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfFact", propOrder = {
    "item"
})
public class ArrayOfFact {

    protected List<Fact> item;
 public List<Fact> getItem() {
        if (item == null) {
            item = new ArrayList<Fact>();
        }
        return this.item;
    }

}

ArrayOfFacts class generated by wsimport it's the same class generated before.

The XML response I receive in SOAPUI :

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ReleveResponse xmlns="http://www.test.ma/webservices/WSTestServe/">
         <ReleveResult>
            <ConversationId>conId</ConversationId>
            <Status>
               <WSStatus>OK</WSStatus>
               <WSCode>OK</WSCode>
               <WSMessage>Le traitement s’est bien déroulé!</WSMessage>
            </Status>
            <myReleveInfo>
               <NomCli>El Karkouri youssef</NomCli>
               <NbrImp>7</NbrImp>
               <Facture>
                  <Fact>
                     <RefImp>FACT-124</RefImp>
                     <MntImp>230</MntImp>
                     <LibImp>label 1</LibImp>
                     <FlgPaiObl>1</FlgPaiObl>
                  </Fact>
                  <Fact>
                     <RefImp>FACT-125</RefImp>
                     <MntImp>260</MntImp>
                     <LibImp>label 0</LibImp>
                     <FlgPaiObl>0</FlgPaiObl>
                  </Fact>
                  <Fact>
                     <RefImp>FACT-126</RefImp>
                     <MntImp>360</MntImp>
                     <LibImp>label 2</LibImp>
                     <FlgPaiObl>0</FlgPaiObl>
                  </Fact>
                  <Fact>
                     <RefImp>FACT-127</RefImp>
                     <MntImp>236</MntImp>
                     <LibImp>label 3</LibImp>
                     <FlgPaiObl>0</FlgPaiObl>
                  </Fact>
                  <Fact>
                     <RefImp>FACT-128</RefImp>
                     <MntImp>2310</MntImp>
                     <LibImp>label 4</LibImp>
                     <FlgPaiObl>1</FlgPaiObl>
                  </Fact>
                  <Fact>
                     <RefImp>FACT-129</RefImp>
                     <MntImp>2450</MntImp>
                     <LibImp>label 0</LibImp>
                     <FlgPaiObl>1</FlgPaiObl>
                  </Fact>
                  <Fact>
                     <RefImp>FACT-167</RefImp>
                     <MntImp>2380</MntImp>
                     <LibImp>label 1125</LibImp>
                     <FlgPaiObl>0</FlgPaiObl>
                  </Fact>
               </Facture>
            </myReleveInfo>
         </ReleveResult>
      </ReleveResponse>
   </soapenv:Body>
</soapenv:Envelope>

The JSON response I receive whwn I test the jax-ws client :

{
"status": "OK",
"language": "en",
"data": {
    "conversationId": {
        "name": "{http://www.test.ma/webservices/WSTestServe/}ConversationId",
        "declaredType": "java.lang.String",
        "scope": "ma.comp.company.client.testserv.AbstractBean",
        "value": "conId",
        "nil": false,
        "globalScope": false,
        "typeSubstituted": false
    },
    "status": {
        "name": "{http://www.test.ma/webservices/WSTestServe/}Status",
        "declaredType": "ma.comp.company.client.testserv.StatusBeanOut",
        "scope": "ma.comp.company.client.testserv.AbstractBeanOutOfReleveInfo",
        "value": {
            "wsstatus": "OK",
            "wscode": "OK",
            "wsmessage": "Le traitement s’est bien déroulé!"
        },
        "nil": false,
        "globalScope": false,
        "typeSubstituted": false
    },
    "myReleveInfo": {
        "nomCli": {
            "name": "{http://www.test.ma/webservices/WSTestServe/}NomCli",
            "declaredType": "java.lang.String",
            "scope": "ma.comp.company.client.testserv.ReleveInfo",
            "value": "El Karkouri youssef",
            "nil": false,
            "globalScope": false,
            "typeSubstituted": false
        },
        "nbrImp": {
            "name": "{http://www.test.ma/webservices/WSTestServe/}NbrImp",
            "declaredType": "java.lang.String",
            "scope": "ma.comp.company.client.testserv.ReleveInfo",
            "value": "7",
            "nil": false,
            "globalScope": false,
            "typeSubstituted": false
        },
        "facture": {
            "name": "{http://www.test.ma/webservices/WSTestServe/}Facture",
            "declaredType": "ma.comp.company.client.testserv.ArrayOfFact",
            "scope": "ma.comp.company.client.testserv.ReleveInfo",
            "value": {
                "item": []
            },
            "nil": false,
            "globalScope": false,
            "typeSubstituted": false
        }
    }
},
"message": null

}

Fact class:

    @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Fact", propOrder = {
    "refImp",
    "mntImp",
    "libImp",
    "flgPaiObl"
})
public class Fact {

    @XmlElementRef(name = "RefImp", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
    protected JAXBElement<String> refImp;
    @XmlElementRef(name = "MntImp", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
    protected JAXBElement<String> mntImp;
    @XmlElementRef(name = "LibImp", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
    protected JAXBElement<String> libImp;
    @XmlElementRef(name = "FlgPaiObl", namespace = "http://www.test.ma/webservices/WSTesServe/", type = JAXBElement.class, required = false)
    protected JAXBElement<String> flgPaiObl;

    // Getters and Setters

}
Youssefo
  • 1
  • 4
  • is there any reason why you are not using wsimport? – diedu Jul 24 '18 at 01:28
  • I do not know, I'm new in WS SOAP. do they have the same role? – Youssefo Jul 25 '18 at 09:15
  • I just tested wsimport, and i get the same problem. always the list is empty :( – Youssefo Jul 25 '18 at 10:05
  • Check with an sniffer tool that the request you send with the client is the same as the one you send via soapui, it could be you are missing some kind of parameter, also would be useful is you post the arrayoffacts class generated by wsimport and the xml response you receive in soapui – diedu Jul 25 '18 at 14:16
  • requests are the same, and i added to the question the responses (SOAPUI and client) – Youssefo Jul 25 '18 at 16:21
  • Why that response is in json? – diedu Jul 25 '18 at 21:02
  • Because I develop a REST API that call the client and return the response in json. – Youssefo Jul 25 '18 at 22:14
  • you will find a test class that I added to the question – Youssefo Jul 25 '18 at 22:21
  • Have you read this? https://stackoverflow.com/questions/3601113/jax-ws-return-empty-lists it looks like the same problem – diedu Jul 25 '18 at 22:39
  • Check the Fact generated class, maybe it does not match the xml and that prevents the item being added to the list – diedu Jul 25 '18 at 22:44
  • How to use PayloadValidatingInterceptor? The generated Fact and the XML have the same properties, i added it to the question. – Youssefo Jul 26 '18 at 00:05
  • I found this, try the last response https://coderanch.com/t/650899/java/Jaxb-Binding-List-returned-web, but anyways the binding seems to be the problem so you should look for a way to validate that it is correct by doing the marshaling manually and maybe inspecting the process via a debugger and step into the parser code, this is as far I can help, sorry I don't have much experience either – diedu Jul 26 '18 at 02:39
  • I thank you for your help, you're right the problem it was the binding. I fixed that by adding an xml element declaration in class ObjectFactory generated by wsimport. – Youssefo Jul 26 '18 at 10:09

1 Answers1

0

I fixed that by adding an xml element declaration in class ObjectFactory generated by wsimport

@XmlElementDecl(namespace = "http://www.test.ma/webservices/WSTestServe/", name = "Fact", scope = ArrayOfFact.class)
public JAXBElement<Fact> createArrayOfFactItem(Fact value) {
    return new JAXBElement<Fact>(_ReleveInfoFact_QNAME, Fact.class, ArrayOfFact.class, value);
}

And the list of items should be annotated by :

@XmlElementRef(name = "Fact", namespace = "http://www.test.ma/webservices/WSTestServe/", type = JAXBElement.class, required = false)
protected List<Fact> item;
Youssefo
  • 1
  • 4