Ich habe erfolgreich ein XML
Dokument in ein JAXB
Objekt entmarshaliert, aber jetzt möchte ich auf das Objekt im Fluss verweisen und den Wert seiner Eigenschaften in eine Datenbanktabelle einfügen.Wie referenziere ich einen JAXB POJO in einem Mule-Fluss
Die Strömung ist wie folgt:
<?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>
Das Objekt ist wie folgt:
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;
}
}
}
}
}
}
}
Nach unmarshalling, wird das Objekt als [email protected]_random_string
instanziiert, die sie an Referenz erschwert. Also meine Frage ist einfach, wie kann ich auf dieses Objekt verweisen und in der Lage sein, auf die Werte zuzugreifen, die anderswo im Fluss verwendet werden.
Danke für Ihre Hilfe.
Was erhalten Sie von ' '? –
Es löst eine Ausnahme aus - java.lang.NullPointerException. Wenn das Unmarshalling jedoch ausgeführt wird, ist die Nutzlast nicht null und hat ein Objekt mit dem Namen [email protected] Ich kann die Nutzlast im Debugger durchsuchen und alle Werte im Objekt sehen. –