marshalSendAndReceive()引发“ UnmarshallingFailureException”和“ SAXParseException; cvc-elt.1:找不到元素”的声明

时间:2019-02-18 14:37:33

标签: spring-boot soap jaxb marshalling maven-jaxb2-plugin

我正在尝试从Java代码调用Soap服务,我正在使用SpringBoot和Maven。我已经使用了maven-jaxb2-plugin并生成了java类。然后,通过使用 marshalSendAndReceive(),我想获取响应,但函数抛出错误“ UnmarshallingFailureException: SAXParseException; cvc-elt.1:”,找不到元素“ abc'“。

当我呼叫端点时,marshalSendAndReceive()引发错误,我已经配置了不同的marshallar,但没有任何作用。

我的xsd:

<xsd:element  name="GetFilterStatus" type="GetFilterStatusType" />

<xsd:element name="ReturnFilterStatus" type="ReturnFilterStatusType" />

<xsd:complexType name="GetFilterStatusType">
    <xsd:sequence>
        <xsd:element name="SchemaVersion" type="xsd:string"
            minOccurs="1" maxOccurs="1" />
        <xsd:element name="MessageHeader" type="message:MessageHeaderType"
            minOccurs="1" maxOccurs="1" />
        <xsd:element name="GetFilterStatusBody" minOccurs="1"
            maxOccurs="1">
            <xsd:complexType id="GetFilterStatusBodyType">
                <xsd:sequence>
                    <xsd:element name="EANReference" type="network:EANReferenceType"
                        minOccurs="1" maxOccurs="1" />
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="ReturnFilterStatusType">
    <xsd:sequence>
        <xsd:element name="SchemaVersion" type="xsd:string"
            minOccurs="1" maxOccurs="1" />
        <xsd:element name="MessageHeader" type="message:MessageHeaderType"
            minOccurs="1" maxOccurs="1" />
        <xsd:element name="RefMessageIdentifier" type="message:MessageIdentifierType"
            minOccurs="1" maxOccurs="1" />
        <xsd:element name="Result" type="common:ResultType"
            minOccurs="1" maxOccurs="1" />
        <xsd:choice minOccurs="1" maxOccurs="1">
            <xsd:element name="Filters" type="network:FiltersType" />
            <xsd:element name="Errors" type="common:ErrorsType" />
        </xsd:choice>
    </xsd:sequence>
</xsd:complexType>   

我的客户和编组:

@Bean
public Client Client(Jaxb2Marshaller marshaller) {
    Client client = new Client();

    client.setDefaultUri("http://localhost:8080/ws");
    client.setMarshaller(marshaller);
    client.setUnmarshaller(marshaller);

    return client;
}


@Bean
public Jaxb2Marshaller marshaller() throws Exception {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

    marshaller.setCheckForXmlRootElement(false);
   marshaller.setSchema(new ClassPathResource("/xsd/docs/GetFilterStatus-
   v1_00.xsd"));
 marshaller.setSupportJaxbElementClass(true);

  marshaller.setPackagesToScan("ws.supplier.igs.operations.v1");
}

我的客户班:

  public class Client extends WebServiceGatewaySupport {

public JAXBElement<ReturnFilterStatusType> getFilterStatus (String url,JAXBElement<GetFilterStatusType> request,SoapActionCallback soapActionCallback) {


   JAXBElement<ReturnFilterStatusType> returnFilterStatusType= (JAXBElement<ReturnFilterStatusType>) (getWebServiceTemplate().marshalSendAndReceive(url,  request, soapActionCallback));


    return returnFilterStatusType;
}

我应该得到响应,并且应该在我的课堂上得到地图

**Error that I'm getting:** 

org.springframework.oxm.UnmarshallingFailureException:JAXB解组异常;嵌套的异常是javax.xml.bind.UnmarshalException  -具有链接的例外: [org.xml.sax.SAXParseException; cvc-elt.1:找不到元素'ReturnFilterStatusType'的声明。]     在org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:911)     在org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:784)

0 个答案:

没有答案