gpt4 book ai didi

java - 如何读取 xs :any response using CXF Generated Client?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:17:41 24 4
gpt4 key购买 nike

使用 CXF 2.1.4(生成的客户端)使用 Web 服务时,我在获取基于 WSDL 中以下 XSD 片段的响应时遇到问题。 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 类,它应该“保存”来自 Web 服务的响应

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

}

}

在生成的代理端口下面

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

最佳答案

ListgetContent() 返回可能包含各种 org.w3c.dom.Element , JAXBElement ,或完全绑定(bind)的类。

如果 JAXB 上下文无法识别 <Siif>元素,那么 JAXB 将谨慎行事并使用单个 Element 填充列表表示 <Siif> 的对象和它的 child 。如果它确实识别它们,它将包含 JAXBElement which in turn contains a西夫 object, or it may contain the直接 Siif` 对象。

Java 无法在其类型中表达这种多样性,因此只需绑定(bind)到 List<Object> .

关于java - 如何读取 xs :any response using CXF Generated Client?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4898927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com