2016-08-10 3 views
0

개체에 XML 문서를 성공적으로 비 정렬했지만 이제는 흐름의 개체를 참조하여 해당 속성의 값을 데이터베이스 테이블에 삽입하고 싶습니다. 다음노새 흐름에서 JAXB POJO를 참조하는 방법

흐름은 다음과 같이

<?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; 
        } 

       } 

      } 

     } 

    } 

} 

} 

비 정렬 후, 오브젝트가 곤란 참조 할 수있는 [email protected]_random_string 같이 인스턴스화된다. 그래서 제 질문은 단순히이 객체를 참조하고 흐름의 다른 곳에서 사용할 값에 액세스 할 수있는 방법 일뿐입니다.

도움 주셔서 감사합니다.

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 부분이 null :/게터

+0

'''에서 얻는 것은 무엇입니까? –

+0

예외를 throw합니다 (java.lang.NullPointerException). 그러나 언 마샬링이 완료되면 페이로드는 null이 아니며 [email protected]라는 객체가 있습니다. 디버거에서 페이로드를 찾아보고 객체의 모든 값을 볼 수 있습니다. –

답변

0

귀하의 세터의 속성 이름과 호환되지 않습니다.

정확한 getter 이름은 getTransaction이며 setter와 동일합니다. 그것들을 바꿔주세요

+0

정말 고마워요. 왜 내가 그것을 보지 못했는지 모르겠다. 말할 필요도없이, 그것은 효과가 있었다. 감사. –

관련 문제