如何解决Camel Jaxb解扰问题 [英] How to fix Camel Jaxb unmasharlling problem

查看:0
本文介绍了如何解决Camel Jaxb解扰问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个xsd,并将其与如下所示的jaxb插件一起使用:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="http://www.mycompany.fr/Canonical/Schema/invoices.xsd"
           targetNamespace="http://www.mycompany.fr/Canonical/Schema/invoices.xsd"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified">

    <xs:element name="invoices">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="invoice" maxOccurs="unbounded" minOccurs="0">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element minOccurs="0" name="invoice-type" type="xs:string"/>
                            <xs:element minOccurs="0" name="insertion-date" type="xs:dateTime"/>
                            <xs:element minOccurs="0" name="amount" type="xs:double"/>
                        </xs:sequence>
                        <xs:attribute name="invoice-number" type="xs:string" use="required"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

插件:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.5.0</version>
                <executions>
                    <execution>
                        <id>xsd-to-java</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <packageName>com.mycompany.model</packageName>
                    <sources>
                        <source>src/main/resources/xsd/invoices.xsd</source>
                    </sources>
                </configuration>
            </plugin>

它为我生成了这个类:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "invoice"
})
@XmlRootElement(name = "invoices")
public class Invoices {

    protected List<Invoice> invoice;

    /**
     * Gets the value of the invoice 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 invoice property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getInvoice().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link Invoice }
     * 
     * 
     */
    public List<Invoice> getInvoice() {
        if (invoice == null) {
            invoice = new ArrayList<Invoice>();
        }
        return this.invoice;
    }


    /**
     * <p>Classe Java pour anonymous complex type.
     * 
     * <p>Le fragment de schéma suivant indique le contenu attendu figurant dans cette classe.
     * 
     * <pre>
     * &lt;complexType&gt;
     *   &lt;complexContent&gt;
     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt;
     *       &lt;sequence&gt;
     *         &lt;element name="invoice-type" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt;
     *         &lt;element name="insertion-date" type="{http://www.w3.org/2001/XMLSchema}dateTime" minOccurs="0"/&gt;
     *         &lt;element name="amount" type="{http://www.w3.org/2001/XMLSchema}double" minOccurs="0"/&gt;
     *       &lt;/sequence&gt;
     *       &lt;attribute name="invoice-number" use="required" type="{http://www.w3.org/2001/XMLSchema}string" /&gt;
     *     &lt;/restriction&gt;
     *   &lt;/complexContent&gt;
     * &lt;/complexType&gt;
     * </pre>
     * 
     * 
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "invoiceType",
        "insertionDate",
        "amount"
    })
    public static class Invoice {

        @XmlElement(name = "invoice-type")
        protected String invoiceType;
        @XmlElement(name = "insertion-date")
        @XmlSchemaType(name = "dateTime")
        protected XMLGregorianCalendar insertionDate;
        protected Double amount;
        @XmlAttribute(name = "invoice-number", required = true)
        protected String invoiceNumber;

        /**
         * Obtient la valeur de la propriété invoiceType.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getInvoiceType() {
            return invoiceType;
        }

        /**
         * Définit la valeur de la propriété invoiceType.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setInvoiceType(String value) {
            this.invoiceType = value;
        }

        /**
         * Obtient la valeur de la propriété insertionDate.
         * 
         * @return
         *     possible object is
         *     {@link XMLGregorianCalendar }
         *     
         */
        public XMLGregorianCalendar getInsertionDate() {
            return insertionDate;
        }

        /**
         * Définit la valeur de la propriété insertionDate.
         * 
         * @param value
         *     allowed object is
         *     {@link XMLGregorianCalendar }
         *     
         */
        public void setInsertionDate(XMLGregorianCalendar value) {
            this.insertionDate = value;
        }

        /**
         * Obtient la valeur de la propriété amount.
         * 
         * @return
         *     possible object is
         *     {@link Double }
         *     
         */
        public Double getAmount() {
            return amount;
        }

        /**
         * Définit la valeur de la propriété amount.
         * 
         * @param value
         *     allowed object is
         *     {@link Double }
         *     
         */
        public void setAmount(Double value) {
            this.amount = value;
        }

        /**
         * Obtient la valeur de la propriété invoiceNumber.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getInvoiceNumber() {
            return invoiceNumber;
        }

        /**
         * Définit la valeur de la propriété invoiceNumber.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setInvoiceNumber(String value) {
            this.invoiceNumber = value;
        }

    }

}

我使用此骆驼路由对XML进行解混:

    JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();
        jaxbDataFormat.setSchema("classpath:xsd/invoices.xsd");
from("file:{{xml.location}}?delay=1000")
                .log("Reading invoice XML data from ${header.CamelFileName}")
                .unmarshal(jaxbDataFormat)
                .split(body())
            .to("direct:processedXml");

但是当我运行我的应用程序时,我收到以下错误...

[route2][unmarshal1] [unmarshal[org.apache.camel.model.dataformat.JaxbDataFormat@7aff8796] ][0]

堆栈跟踪 ----------------------------------------------------------------------

这篇关于如何解决Camel Jaxb解扰问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆