1

问题:

当 JAXB 将 xml 解组到对象树中时,来自单独 jar(和模式)的对象的属性未设置并保持为空。

请参阅下面的代码。在解组时,MeldingType 类的属性保持为 NULL,即使 SOAP 消息已经填充了 'meldingen' 元素中的 'code' 和 'melding' 子元素。

如果我在 .war 中创建 MeldingType 的“本地”版本,并将 MeldingType 的 .xsd 定义放在 out.xsd 中,则一切正常。:(

如何使用单独的 jar,以便我可以共享来自常见 .xsd 的常见 JAXB 对象?

情况

我有一个战争和一个 jar 文件。

  • .war 包含一个类“RequestType”、包信息、out.xsd 和 out.wsdl。
  • .jar 包含一个类“MeldingType”、包信息和 schema.xsd

战争文件

包装信息:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.xxx.nl/schema/out/v0010", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package nl.xxx.out.web.model;

请求类型

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "XbOutRequestType", propOrder = {
    "kenmerk",
    "meldingen"
})
public class XbOutRequestType {

    @XmlElement(required = true)
    protected String kenmerk;

    @XmlElement(required = true)
    protected List<MeldingType> meldingen = new ArrayList<MeldingType>();

    public String getKenmerk() {
        return this.kenmerk;
    }

    public List<MeldingType> getMeldingen() {
        return this.meldingen;
    }
}

出.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:ref="http://schemas.xxx.nl/schema/v0010"
    targetNamespace="http://schemas.xxx.nl/out/v0010"
        xmlns="http://schemas.xxx.nl/out/v0010"
    elementFormDefault="qualified"> 

    <xsd:element name="request" type="RequestType"/>

    <xsd:element name="respomse" type="ResponseType"/>

    <xsd:complexType name="RequestType">
        <xsd:sequence>
            <xsd:element name="kenmerk" type="ref:kenmerkType" minOccurs="1"/>            
            <xsd:element name="meldingen" type="ref:MeldingType" minOccurs="1" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="XbOutResponseType"/>        

</xsd:schema>

输出.wsdl

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                  xmlns:tns="http://schemas.xxx.nl/wsdl/out/v0010"
                  xmlns:typ="http://schemas.xxx.nl/schema/out/v0010"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  name="XbRender" targetNamespace="http://schemas.xxx.nl/wsdl/out/v0010">

    <wsdl:types>
        <xsd:schema targetNamespace="http://schemas.xxx.nl/wsdl/out/v0010"     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:import namespace="http://schemas.xxx.nl/schema/out/v0010"     schemaLocation="out.xsd" />
        </xsd:schema>
    </wsdl:types>

    <wsdl:message name="request">
        <wsdl:part name="body" element="typ:request" />
    </wsdl:message>

    <wsdl:message name="response">
        <wsdl:part name="body" element="typ:response" />
    </wsdl:message>

    <wsdl:portType name="portType">
        <wsdl:operation name="execute">
            <wsdl:input message="tns:request" />
            <wsdl:output message="tns:response" />
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="soapBinding" type="tns:portType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="execute">
            <soap:operation soapAction="execute"/>
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="service">
        <wsdl:port binding="tns:soapBinding" name="soapBinding">
            <soap:address location="http://localhost:9080/dummy" />
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>

包装信息:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://schemas.xxx.nl/schema/v0010")
package nl.xxx.schema.jaxb.model;

融合型

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MeldingType", propOrder = {
    "code",
    "melding"
})
public class MeldingType {

@XmlElement(required = true)
private String code;

@XmlElement(required = true)
private String melding;

public MeldingType() {
}

public MeldingType(final String code, final String melding) {
    this.code = code;
    this.melding = melding;
}

    public String getCode() {
        return this.code;
    }

    public String getMelding() {
        return this.melding;
    }

    public void setCode(final String code) {
        this.code = code;
    }

    public void setMelding(final String melding) {
        this.melding = melding;
    }
}

架构.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://schemas.xxx.nl/schema/v0010"
            xmlns="http://schemas.xxx.nl/schema/v0010"
                elementFormDefault="qualified">

    <xsd:simpleType name="kenmerkType">
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="12" />
            <xsd:maxLength value="32" />
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="MeldingType">
        <xsd:sequence>
            <xsd:element name="code" type="xsd:string" minOccurs="1" />
            <xsd:element name="melding" type="xsd:string" minOccurs="1" />
        </xsd:sequence>
    </xsd:complexType>

</xsd:schema>
4

0 回答 0