提问人:buyufix 提问时间:11/16/2023 更新时间:11/17/2023 访问量:24
JAXB 生成的 Java 类不处理 SOAP 请求
SOAP Request does not processed by JAXB Generated Java Classes
问:
这是我在下面看到的 .xsd 文件中的请求。如您所见,有些首字母故意大写和小写。
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://tempuri.org/"
targetNamespace="http://tempuri.org/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<xs:element name="Deneme">
<xs:complexType>
<xs:sequence>
<xs:element name="count" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CustomerRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerName" type="xs:string" />
<xs:element name="Age" type="xs:int" />
<xs:element name="YearlyIncome" type="xs:long" />
<xs:element name="cibilScore" type="xs:int" />
<xs:element name="employmentMode" type="xs:string" />
<xs:element ref="tns:Deneme"/>
</xs:sequence>
</xs:complexType>
</xs:element>
使用 JAXB 生成类后:
客户请求.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"customerName",
"age",
"yearlyIncome",
"cibilScore",
"employmentMode",
"deneme"
})
@XmlRootElement(name = "CustomerRequest")
public class CustomerRequest {
@XmlElement(name = "CustomerName", required = true)
protected String customerName;
@XmlElement(name = "Age")
protected int age;
@XmlElement(name = "YearlyIncome")
protected long yearlyIncome;
protected int cibilScore;
@XmlElement(required = true)
protected String employmentMode;
@XmlElement(name = "Deneme", required = true)
protected Deneme deneme;
// getter and setters
}
如您所见,@XmlElement与 xsd 文件相同。但是,propOrder 值以小写开头。它给我带来了以下问题:当我尝试使用SoapUI发送请求时,这种情况问题阻止了请求。
如果我像这样发送请求,它可以工作:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:CustomerRequest>
<customerName>5</customerName>
<age>5</age>
<yearlyIncome>5</yearlyIncome>
<cibilScore>5</cibilScore>
<employmentMode>5</employmentMode>
<deneme>
<count>55</count>
</deneme>
</tem:CustomerRequest>
</soapenv:Body>
</soapenv:Envelope>
但是,在下文中,它无法访问以大写开头的元素。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:CustomerRequest>
<CustomerName>5</CustomerName>
<Age>5</Age>
<YearlyIncome>5</YearlyIncome>
<cibilScore>5</cibilScore>
<employmentMode>5</employmentMode>
<Deneme>
<count>55</count>
</Deneme>
</tem:CustomerRequest>
</soapenv:Body>
</soapenv:Envelope>
我相信问题出在SOAP UI上,但可能有不同的原因,所以我想问你。
答: 暂无答案
评论