如何在骡子流中引用JAXB POJO

时间:2016-08-10 03:06:57

标签: java xml jaxb mule

我已成功将XML文档解组为JAXB对象,但现在,我想在流中引用该对象并将其属性值插入数据库表中。

流程如下:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="10009" basePath="/ipay/bra" doc:name="HTTP Listener Configuration"/>
<mulexml:jaxb-context name="JAXB_Context" packageNames="com.dhg.api" doc:name="JAXB Context"/>
<flow name="transaction_initiation_testFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/transaction" doc:name="HTTP">
        <http:response-builder>
            <http:header headerName="Content-Type" value="text/xml"/>
        </http:response-builder>
    </http:listener>
    <mulexml:jaxb-xml-to-object-transformer returnClass="com.dhg.api.PAYMENTS" jaxbContext-ref="JAXB_Context" doc:name="XML to JAXB Object"/>
    <logger message="#[payload.transaction.email]" level="INFO" doc:name="Logger"/>
    <echo-component doc:name="Echo"/>
</flow>
</mule>

对象如下:

package com.dhg.api;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;



@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {"transaction"})
@XmlRootElement(name = "PAYMENTS")
public class PAYMENTS {

@XmlElement(name = "TRANSACTION", required = true)
protected PAYMENTS.TRANSACTION transaction;

public PAYMENTS.TRANSACTION getTRANSACTION() {
    return transaction;
}

public void setTRANSACTION(PAYMENTS.TRANSACTION value) {
    this.transaction = value;
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "entity",
    "useraddress1",
    "useraddress2",
    "useraddress3",
    "usercountry",
    "userparish",
    "totalamount",
    "payer",
    "status",
    "ipaynumber",
    "email"
})
public static class TRANSACTION {

    @XmlElement(name = "ENTITY", required = true)
    protected PAYMENTS.TRANSACTION.ENTITY entity;
    @XmlElement(name = "USERADDRESS1", required = true)
    protected String useraddress1;
    @XmlElement(name = "USERADDRESS2", required = true)
    protected String useraddress2;
    @XmlElement(name = "USERADDRESS3", required = true)
    protected String useraddress3;
    @XmlElement(name = "USERCOUNTRY", required = true)
    protected String usercountry;
    @XmlElement(name = "USERPARISH", required = true)
    protected String userparish;
    @XmlElement(name = "TOTALAMOUNT")
    protected float totalamount;
    @XmlElement(name = "PAYER", required = true)
    protected String payer;
    @XmlElement(name = "STATUS", required = true)
    protected String status;
    @XmlElement(name = "IPAYNUMBER")
    protected int ipaynumber;
    @XmlElement(name = "EMAIL", required = true)
    protected String email;
    @XmlAttribute(name = "txdate")
    protected String txdate;
    @XmlAttribute(name = "txno")
    protected String txno;

    public PAYMENTS.TRANSACTION.ENTITY getENTITY() {
        return entity;
    }

    public void setENTITY(PAYMENTS.TRANSACTION.ENTITY value) {
        this.entity = value;
    }

    public String getUSERADDRESS1() {
        return useraddress1;
    }
    public void setUSERADDRESS1(String value) {
        this.useraddress1 = value;
    }

    public String getUSERADDRESS2() {
        return useraddress2;
    }

    public void setUSERADDRESS2(String value) {
        this.useraddress2 = value;
    }

    public String getUSERADDRESS3() {
        return useraddress3;
    }

    public void setUSERADDRESS3(String value) {
        this.useraddress3 = value;
    }

    public String getUSERCOUNTRY() {
        return usercountry;
    }

    public void setUSERCOUNTRY(String value) {
        this.usercountry = value;
    }

    public String getUSERPARISH() {
        return userparish;
    }

    public void setUSERPARISH(String value) {
        this.userparish = value;
    }

    public float getTOTALAMOUNT() {
        return totalamount;
    }

    public void setTOTALAMOUNT(float value) {
        this.totalamount = value;
    }

    public String getPAYER() {
        return payer;
    }

    public void setPAYER(String value) {
        this.payer = value;
    }

    public String getSTATUS() {
        return status;
    }

    public void setSTATUS(String value) {
        this.status = value;
    }

    public int getIPAYNUMBER() {
        return ipaynumber;
    }

    public void setIPAYNUMBER(int value) {
        this.ipaynumber = value;
    }

    public String getEMAIL() {
        return email;
    }

    public void setEMAIL(String value) {
        this.email = value;
    }

    public String getTxdate() {
        return txdate;
    }

    public void setTxdate(String value) {
        this.txdate = value;
    }

    public String getTxno() {
        return txno;
    }

    public void setTxno(String value) {
        this.txno = value;
    }

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "account"
    })
    public static class ENTITY {

        @XmlElement(name = "ACCOUNT", required = true)
        protected PAYMENTS.TRANSACTION.ENTITY.ACCOUNT account;
        @XmlAttribute(name = "biller")
        protected String biller;

        public PAYMENTS.TRANSACTION.ENTITY.ACCOUNT getACCOUNT() {
            return account;
        }
        public void setACCOUNT(PAYMENTS.TRANSACTION.ENTITY.ACCOUNT value) {
            this.account = value;
        }
        public String getBiller() {
            return biller;
        }

        public void setBiller(String value) {
            this.biller = value;
        }

        @XmlAccessorType(XmlAccessType.FIELD)
        @XmlType(name = "", propOrder = {
            "details"
        })
        public static class ACCOUNT {

            @XmlElement(name = "DETAILS", required = true)
            protected PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS details;
            @XmlAttribute(name = "bpnumber")
            protected Integer bpnumber;

            public PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS getDETAILS(){
                return details;
            }

            public void setDETAILS(PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS value) {
                this.details = value;
            }


            public Integer getBpnumber() {
                return bpnumber;
            }


            public void setBpnumber(Integer value) {
                this.bpnumber = value;
            }


            @XmlAccessorType(XmlAccessType.FIELD)
            @XmlType(name = "", propOrder = {
                "dockey"
            })
            public static class DETAILS {

                @XmlElement(name = "DOCKEY")
                protected List<PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS.DOCKEY> dockey;

                public List<PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS.DOCKEY> getDOCKEY() {
                    if (dockey == null) {
                        dockey = new ArrayList<PAYMENTS.TRANSACTION.ENTITY.ACCOUNT.DETAILS.DOCKEY>();
                    }
                    return this.dockey;
                }


                @XmlAccessorType(XmlAccessType.FIELD)
                @XmlType(name = "", propOrder = {
                    "value"
                })
                public static class DOCKEY {

                    @XmlValue
                    protected String value;
                    @XmlAttribute(name = "payment")
                    protected Float payment;

                    public String getValue() {
                        return value;
                    }

                    public void setValue(String value) {
                        this.value = value;
                    }

                    public Float getPayment() {
                        return payment;
                    }

                    public void setPayment(Float value) {
                        this.payment = value;
                    }

                }

            }

        }

    }

}

}

解组后,对象被实例化为com.dhg.api.PAYMENTS@some_random_string,这使得很难引用。所以我的问题很简单,我怎样才能引用这个对象并能够访问这些值以便在流程的其他地方使用。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您的setter / getter不符合以下属性名称:

public PAYMENTS.TRANSACTION getTRANSACTION() {
    return transaction;
}

public void setTRANSACTION(PAYMENTS.TRANSACTION value) {
    this.transaction = value;
}

因此<logger message="#[payload.transaction.email]" level="INFO" doc:name="Logger"/> transaction部分为空。

正确的getter名称是getTransaction,对于setter来说是一样的。请改变它们

相关问题