开发者

How to read an xs:any response using CXF Generated Client?

When consuming a webserice with CXF 2.1.4 (the generated client) I am having problem getting the response based on the following XSD snippet in the WSDL. CXF Generates a List representing it, but when I execute the service, the response comes null. I used wireshark to what I was reciving and indeed the response XMl is coming as expected, but CXF just give me null object. The exposed services is implemented using .NET.

Below the XSD of the response object. And

    <!--- chunk -->
     <s:element name="GestionSIIFResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="GestionSIIFResult">
          <s:complexType mixed="true">
            <s:sequence>
              <s:any />
            </s:sequence>
          </s:complexType>
        </s:element>
      </s:sequence>
    </s:complexType>
  </s:element>
  <!--- chunk -->

And this is the response I am getting from the service:

   <soap:Body>
  <GestionSIIFResponse xmlns="http://tempuri.org/">
     <GestionSIIFResult>
        <Siif xmlns="">
           <Pagina>NUY001B</Pagina>
           <Exitos>
              <ExitoRep>
                 <CodExito>SIL0082</CodExito>
                 <DesExito>La transaccion se ha aplicado satisfactoriamente</DesExito>
              </ExitoRep>
           </Exitos>
           <InformacionCab/>
           <Repeticiones/>
        </Siif>
     </GestionSIIFResult>
  </GestionSIIFResponse>

Below is the Generated java class that should "hold" the response from the web service

/*
*  some imports here
*/

/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="GestionSIIFResult" minOccurs="0">
 *           &lt;complexType>
 *             &lt;complexContent>
 *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *                 &lt;sequence>
 *                   &lt;any/>
 *                 &lt;/sequence>
 *               &lt;/restriction>
 *             &lt;/complexContent>
 *           &lt;/complexType>
 *         &lt;/element>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "gestionSIIFResult"
})
@XmlRootElement(name = "GestionSIIFResponse")
public class GestionSIIFResponse {

    @XmlElement(name = "GestionSIIFResult")
    protected GestionSIIFResponse.GestionSIIFResult gestionSIIFResult;

    /**
     * Gets the value of the gestionSIIFResult property.
     * 
     * @return
     *     possible object is
     *     {@link GestionSIIFResponse.GestionSIIFResult }
     *     
     */
    public GestionSIIFResponse.GestionSIIFResult getGestionSIIFResult() {
        return gestionSIIFResult;
    }

    /**
     * Sets the value of the gestionSIIFResult property.
     * 
     * @param value
     *     allowed object is
     *     {@link GestionSIIFResponse.GestionSIIFResult }
     *     
     */
    public void setGestionSIIFResult(GestionSIIFResponse.GestionSIIFResult value) {
        this.gestionSIIFResult = value;
    }


    /**
     * <p>Java class for anonymous complex type.
     * 
     * <p>The following schema fragment specifies the expected content contained within this class.
     * 
     * <pre>
     * &lt;complexType>
     *   &lt;complexContent>
     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
     *       &lt;sequence>
     *         &lt;any/>
     *       &lt;/sequence>
     *     &lt;/restriction>
     *   &lt;/complexContent>
     * &lt;/complexType>
     * </pre>
     * 
     * 
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "content"
    })
    public static class GestionSIIFResult {

        @XmlMixed
        @XmlAnyElement(lax = true)
        protected List<Object> content;

        /**
         * Gets the value of the content property.
         * 
         * <p>
         * This accessor method returns a reference to the live list,
         * not a snapshot. Therefore any modification you make to the
         * returned list will be present inside the JAXB object.
         * This is why there is not a <CODE>set</CODE> method for the content property.
         * 
         * <p>
         * For example, to add a new item, do as follows:
         * <pre>
         *    getContent().add(newItem);
         * </pre>
         * 
         * 
         * <p>
         * Objects of the following type(s) are allowed in the list
         * {@link Object }
         * {@link String }
         * 
         * 
         */
        public List<Object> getContent() {
            if (content == null) {
                content = new ArrayList<Object>();
            }
            return this.content;
        }

    }

}

Below the generated proxy port

/**
 * This class was generated by Apache CXF 2.1.4
 * Mon Jan 17 12:02:39 COT 2011
 * Generated source version: 2.1.4
 * 
 */

@WebService(targetNamespace = "http://tempuri.org/", name = "WSGYG05Soap")
@XmlSeeAlso({ObjectFactory.class})
public interface WSGYG05Soap {

    @ResponseWrapper(localName = "GestionSIIFResponse", targetNamespace = "http://tempuri.org/", className = "suramericana.banw.servicios.tuya.v2.GestionSIIFResponse"/*"org.tempuri.GestionSIIFResponse"*/)
    @RequestWrapper(localName = "GestionSIIF",开发者_C百科 targetNamespace = "http://tempuri.org/", className = "suramericana.banw.servicios.tuya.v2.GestionSIIF"/*"org.tempuri.GestionSIIF"*/)
    @WebResult(name = "GestionSIIFResult", targetNamespace = "http://tempuri.org/")
    @WebMethod(operationName = "GestionSIIF", action = "http://tempuri.org/GestionSIIF")
    public GestionSIIFResponse.GestionSIIFResult gestionSIIF(
        @WebParam(name = "Peticion", targetNamespace = "http://tempuri.org/")
        GestionSIIF.Peticion peticion,
        @WebParam(header = true,name="CabAut", targetNamespace = "http://tempuri.org/")
        CabAut cabAut
    );
    //@ResponseWrapper(localName = "GestionSIIFResponse", targetNamespace = "http://tempuri.org/", className = "suramericana.banw.servicios.tuya.v2.GestionSIIFResponse"/*"org.tempuri.GestionSIIFResponse"*/)
    //@RequestWrapper(localName = "GestionSIIF", targetNamespace = "http://tempuri.org/", className = "suramericana.banw.servicios.tuya.v2.GestionSIIF"/*"org.tempuri.GestionSIIF"*/)
    //@WebResult(name = "GestionSIIFResult", targetNamespace = "http://tempuri.org/")
    //@WebMethod(operationName = "GestionSIIF", action = "http://tempuri.org/GestionSIIF")
    /*public GestionSIIFResponse.GestionSIIFResult gestionSIIF(
        @WebParam(name = "Peticion", targetNamespace = "http://tempuri.org/")
        GestionSIIF.Peticion peticion,
        @WebParam(header = true,name="CabAut", targetNamespace = "http://tempuri.org/")
        CabAut cabAut
    );*/
}


The List returned by getContent() could potentially contains a variety of org.w3c.dom.Element, JAXBElement, or fully-bound classes.

If the JAXB context doesn't recognise the <Siif> element, then JAXB will play it safe and populate the list with a single Element object representing the <Siif> and its children. If it does recognise them , it'll either contain JAXBElementwhich in turn contains aSiifobject, or it may contain theSiif` object directly.

Java cannot express this variety in its types, so just binds to List<Object>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜