Как прочитать xs: любой ответ, используя CXF Generated Client? - PullRequest
3 голосов
/ 04 февраля 2011

При использовании веб-службы с CXF 2.1.4 (сгенерированный клиент) у меня возникают проблемы при получении ответа на основе следующего фрагмента XSD в WSDL. CXF Генерирует список, представляющий его, но когда я выполняю службу, ответ становится нулевым. Я использовал wireshark для того, что я получал, и действительно, XMl отвечает, как и ожидалось, но CXF просто дает мне нулевой объект. Предоставленные сервисы реализованы с использованием .NET.

Ниже XSD объекта ответа. И

    <!--- 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 -->

И вот ответ, который я получаю от службы:

   <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>

Ниже приведен сгенерированный Java-класс, который должен «содержать» ответ от веб-службы

<code>/*
*  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>
 * 
* * * / @XmlAccessorType (XmlAccessType.FIELD) @XmlType (name = "", propOrder = { "GestionSIIFResult" }) @XmlRootElement (name = "GestionSIIFResponse") открытый класс GestionSIIFResponse { @XmlElement (name = "GestionSIIFResult") защищенный GestionSIIFResponse.GestionSIIFResult gestionSIIFResult; / ** * Получает значение свойства gestionSIIFResult. * * @вернуть * возможный объект * {@link GestionSIIFResponse.GestionSIIFResult} * * / public GestionSIIFResponse.GestionSIIFResult getGestionSIIFResult () { вернуть gestionSIIFResult; } / ** * Устанавливает значение свойства gestionSIIFResult. * * @param value * разрешенный объект * {@link GestionSIIFResponse.GestionSIIFResult} * * / public void setGestionSIIFResult (значение GestionSIIFResponse.GestionSIIFResult) { this.gestionSIIFResult = значение; } / ** *

Java-класс для анонимного сложного типа. * *

Следующий фрагмент схемы определяет ожидаемое содержимое, содержащееся в этом классе. * *

     * &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>
     * 
* * * / @XmlAccessorType (XmlAccessType.FIELD) @XmlType (name = "", propOrder = { «Содержание» }) открытый статический класс GestionSIIFResult { @XmlMixed @XmlAnyElement (lax = true) защищенный список содержание; / ** * Получает значение свойства содержимого. * *

* Этот метод доступа возвращает ссылку на текущий список, * не снимок. Поэтому любые изменения, которые вы вносите в * возвращенный список будет присутствовать внутри объекта JAXB. * Вот почему нет метода set для свойства content. * *

* Например, чтобы добавить новый элемент, сделайте следующее: *

         *    getContent().add(newItem);
         * 
* * *

* Объекты следующих типов разрешены в списке * {@link Object} * {@link String} * * * / общедоступный список getContent () { if (content == null) { content = new ArrayList (); } вернуть this.content; } } }

ниже сгенерированного прокси-порта

/**
 * 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", 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
    );*/
}

1 Ответ

1 голос
/ 04 февраля 2011

List, возвращаемый getContent(), потенциально может содержать различные org.w3c.dom.Element, JAXBElement или полностью связанные классы.

Если контекст JAXB не распознает элемент <Siif>, то JAXB будет воспроизводить его безопасно и заполнит список одним Element объектом, представляющим <Siif> и его дочерние элементы. Если он распознает их , он либо содержит JAXBElement which in turn contains a Siif object, or it may contain the Siif` объект напрямую.

Java не может выразить это разнообразие в своих типах, поэтому просто связывается с List<Object>.

...