agn*_*nul 8 java jax-ws jaxb moxy
我有一个第三方Web服务,我使用wsimport生成一个客户端.每次对webservice的调用都会成功完成,但我得到的响应对象的所有字段都设置为null.监控网络我可以看到,在线路上,响应消息中的所有XML元素都包含值,因此对象中应包含非空数据.此外,使用旧的axis1生成并使用相同数据调用的相同服务的客户端返回非空响应.知道发生了什么事吗?(如果它有任何区别我正在使用MOXy的JAXB实现).
更新:我已经能够缩小范围了.例如,wsdl在其自己的命名空间中定义对象http://www.acme.com/ws.我从服务中得到的回应是
<?xml version="1.0" encoding="UTF-8"?>
... SOAP envelope ...
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:responseINFOWL xsi:type="ns1:responseINFOWL">
<result>6003</result>
<ndserr/>
<transid>61437594</transid>
<descriptionerr>BLAH.</descriptionerr>
</ns1:responseINFOWL>
</ns1:opINFOWLResponse>
... SOAP closing tags ...
Run Code Online (Sandbox Code Playgroud)
并且被解组为非null OpINFOWLResponse,它包装非null responseINFOWL对象,并且所有字段都设置为null.为了好玩,我尝试编写几行来解组上面的代码片段(在剥离SOAP开销之后)
JAXBContext ctx = JAXBContext.newInstance(OpINFOWLResponse.class);
Unmarshaller u = ctx.createUnmarshaller();
OpINFOWLResponse o = (OpINFOWLResponse) u.unmarshal(new StringReader(theSnippetAbove));
ResponseINFOWL w = o.getResponseINFOWL();
Run Code Online (Sandbox Code Playgroud)
我得到了相同的结果.如果我将上面的XML更改为
<?xml version="1.0" encoding="UTF-8"?>
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:responseINFOWL xsi:type="ns1:responseINFOWL">
<ns1:result>6003</ns1:result>
<ns1:ndserr/>
<ns1:transid>61437594</ns1:transid>
<ns1:descriptionerr>BLAH.</ns1:descriptionerr>
</ns1:responseINFOWL>
</ns1:opINFOWLResponse>
Run Code Online (Sandbox Code Playgroud)
一切正常.游民.
更新(再次):与jaxb-RI和Moxy相同的行为.还是不知道出了什么问题.
更新(9月9日):下面关于名称空间限定错误的建议很有意思,但我认为wsimport会把事情做对.无论如何,这是我的package-info.java
@XmlSchema(
namespace = "http://www.acme.com/ws",
elementFormDefault = XmlNsForm.QUALIFIED)
package it.sky.guidaTv.service.remote;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlNsForm;
Run Code Online (Sandbox Code Playgroud)
这是ResponseINFOWL班级的相关部分
/*
* <p>Java class for responseINFOWL complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType name="responseINFOWL">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="result" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="descriptionerr" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="transid" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="ndserr" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* <element name="wallet" type="{http://www.acme.com/ws}t_wallet" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "responseINFOWL", propOrder = {
"result", "descriptionerr", "transid", "ndserr", "wallet" })
public class ResponseINFOWL {
@XmlElement(required = true)
protected String result;
@XmlElement(required = true)
protected String descriptionerr;
@XmlElement(required = true)
protected String transid;
protected String ndserr;
protected TWallet wallet;
// getters, setters and all.
}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用命名空间,package-info但仍然没有喜悦.
如果我的用例不正确,请纠正我。
您可以解组:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:responseINFOWL xsi:type="ns1:responseINFOWL">
<ns1:result>6003</ns1:result>
<ns1:ndserr />
<ns1:transid>61437594</ns1:transid>
<ns1:descriptionerr>BLAH.</ns1:descriptionerr>
</ns1:responseINFOWL>
</ns1:opINFOWLResponse>
Run Code Online (Sandbox Code Playgroud)
但无法解组:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:responseINFOWL xsi:type="ns1:responseINFOWL">
<result>6003</result>
<ndserr />
<transid>61437594</transid>
<descriptionerr>BLAH.</descriptionerr>
</ns1:responseINFOWL>
</ns1:opINFOWLResponse>
Run Code Online (Sandbox Code Playgroud)
这意味着 JAXB 映射中的名称空间限定不正确。以下内容可能会有所帮助:
如果您可以发布映射到这部分 XML 的类,以及该类package-info(如果有),那么我可以帮助您修改映射。
| 归档时间: |
|
| 查看次数: |
9962 次 |
| 最近记录: |