diff --git a/src/th/co/ais/ssbsrfc/control/TestMain.java b/src/th/co/ais/ssbsrfc/control/TestMain.java index 4377457..55eaa1f 100644 --- a/src/th/co/ais/ssbsrfc/control/TestMain.java +++ b/src/th/co/ais/ssbsrfc/control/TestMain.java @@ -2,26 +2,27 @@ package th.co.ais.ssbsrfc.control; import java.io.ByteArrayInputStream; import java.io.File; +import java.io.Reader; +import java.io.StringReader; import java.util.Scanner; import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.soap.MessageFactory; import javax.xml.soap.SOAPBody; import javax.xml.soap.SOAPMessage; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; -import th.co.ais.ssbsrfc.instance.AdjustmentResponseIns; -import th.co.ais.ssbsrfc.message.MessageParser; - -@XmlAccessorType(XmlAccessType.FIELD) - - - +import th.co.ais.ssbsrfc.instance.AdjustmentRequestRes; +import th.co.ais.ssbsrfc.instance.ResultHeader; public class TestMain { + static AdjustmentRequestRes adj = new AdjustmentRequestRes(); + static ResultHeader res = new ResultHeader(); + public static Object fromSoap(String strSoap, Class objClass) { Object obj = null; @@ -40,47 +41,64 @@ public class TestMain { } public static void main(String[] args) throws Exception { + + String value = new Scanner(new File("D:\\car.xml")).useDelimiter("\\Z").next(); + String [] valuex = value.split("",-1); + String [] valuey = value.split("", -1); + String msg = ""; + String x = valuey[0]+valuex[1]; -// String msg = ""; -// XMLInputFactory xif = XMLInputFactory.newFactory(); -// StreamSource xml = new StreamSource("D:\\car.xml"); -// XMLStreamReader xsr = xif.createXMLStreamReader(xml); -// xsr.nextTag(); -// -// while(!xsr.getLocalName().equals("ResultHeader")) { -// if(xsr.getLocalName().equals("ResultHeader")){ -// -// } -// xsr.nextTag(); -// System.out.println(xsr.getLocalName()); -// } -// -// JAXBContext jc = JAXBContext.newInstance(Customer.class); -// Unmarshaller unmarshaller = jc.createUnmarshaller(); -// JAXBElement jb = unmarshaller.unmarshal(xsr, Customer.class); -// xsr.close(); -// -// Customer customer = jb.getValue(); -// System.out.println("Version:"+customer.Version); -// System.out.println("ResultCode:"+customer.ResultCode); -// System.out.println("MsgLanguageCode:"+customer.MsgLanguageCode); -// System.out.println("ResultDesc:"+customer.ResultDesc); -// System.out.println("AcctKey:"+customer.AcctKey); + Reader reader = new StringReader(value); + XMLInputFactory factory = XMLInputFactory.newInstance(); // Or newFactory() + XMLStreamReader xsr = factory.createXMLStreamReader(reader); + Reader readerx = new StringReader(x); + XMLInputFactory factoryx = XMLInputFactory.newInstance(); // Or newFactory() + XMLStreamReader xsrx = factoryx.createXMLStreamReader(readerx); + xsr.nextTag(); + xsrx.nextTag(); + while(!xsr.getLocalName().equals("ResultHeader")) { + xsr.nextTag(); + } + while(!xsrx.getLocalName().equals("AdjustmentResult")) { + xsrx.nextTag(); + } + + JAXBContext jc = JAXBContext.newInstance(AdjustmentRequestRes.class); + + Unmarshaller unmarshaller = jc.createUnmarshaller(); + + JAXBElement jb = unmarshaller.unmarshal(xsrx, AdjustmentRequestRes.class); + xsrx.close(); + + adj = jb.getValue(); + jc = JAXBContext.newInstance(ResultHeader.class); + unmarshaller = jc.createUnmarshaller(); + JAXBElement jbe = unmarshaller.unmarshal(xsr, ResultHeader.class); - /* System.out.println("BalanceID:"+customer.AdjustmentInfo.get(0).getBalanceID()); + res = jbe.getValue(); + + System.out.println("getVersion:"+res.getVersion()); + System.out.println("getMsgLanguageCode:"+res.getMsgLanguageCode()); + + System.out.println("getAcctKey:"+adj.getAcctKey()); + System.out.println("getBalanceID:"+adj.getAdjustmentInfo().get(0).getBalanceID()); + + //System.out.println("Version:"+customer.getresultHeader().getVersion()); + /* + System.out.println("ResultCode:"+customer.ResultCode); + System.out.println("MsgLanguageCode:"+customer.MsgLanguageCode); + System.out.println("ResultDesc:"+customer.ResultDesc); + System.out.println("AcctKey:"+customer.AcctKey); + + + System.out.println("BalanceID:"+customer.AdjustmentInfo.get(0).getBalanceID()); System.out.println("BalanceType:"+customer.AdjustmentInfo.get(0).getBalanceType()); System.out.println("BalanceTypeName:"+customer.AdjustmentInfo.get(0).getBalanceTypeName()); System.out.println("CurrencyID:"+customer.AdjustmentInfo.get(0).CurrencyID); System.out.println("NewBalanceAmt:"+customer.AdjustmentInfo.get(0).NewBalanceAmt); - System.out.println("OldBalanceAmt:"+customer.AdjustmentInfo.get(0).OldBalanceAmt);*/ - - String value = new Scanner(new File("D:\\car.xml")).useDelimiter("\\Z").next(); - - - AdjustmentResponseIns ins = (AdjustmentResponseIns)MessageParser.fromSoap(value, AdjustmentResponseIns.class); - - System.out.println(MessageParser.toJson(ins)); + System.out.println("OldBalanceAmt:"+customer.AdjustmentInfo.get(0).OldBalanceAmt); + */ } } diff --git a/src/th/co/ais/ssbsrfc/instance/AFInstance.java b/src/th/co/ais/ssbsrfc/instance/AFInstance.java index e0f1ff6..7cb6a68 100644 --- a/src/th/co/ais/ssbsrfc/instance/AFInstance.java +++ b/src/th/co/ais/ssbsrfc/instance/AFInstance.java @@ -48,7 +48,21 @@ public class AFInstance { private Map dicRetry = null; private AdjustmentRequestIns adjustmentRequestIns = null; + private AdjustmentResponseIns adjustmentResponseIns = null; + private HashMap Dn = null; + public HashMap getDn() { + return Dn; + } + public void setDn(HashMap dn) { + Dn = dn; + } + public AdjustmentResponseIns getAdjustmentResponseIns() { + return adjustmentResponseIns; + } + public void setAdjustmentResponseIns(AdjustmentResponseIns adjustmentResponseIns) { + this.adjustmentResponseIns = adjustmentResponseIns; + } public AdjustmentRequestIns getAdjustmentRequestIns() { return adjustmentRequestIns; } diff --git a/src/th/co/ais/ssbsrfc/message/MessageParser.java b/src/th/co/ais/ssbsrfc/message/MessageParser.java index 9ca0e68..5aa2b7c 100644 --- a/src/th/co/ais/ssbsrfc/message/MessageParser.java +++ b/src/th/co/ais/ssbsrfc/message/MessageParser.java @@ -31,7 +31,8 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import ec02.utils.AppLog; -import th.co.ais.ssbsrfc.instance.AdjustmentResponseIns; +import th.co.ais.ssbsrfc.instance.AdjustmentRequestRes; +import th.co.ais.ssbsrfc.instance.ResultHeader; import th.co.ais.ssbsrfc.instance.SOAPNamespaceMapper; public class MessageParser @@ -259,7 +260,32 @@ public class MessageParser return obj; } - /*public static AdjustmentResponseIns formsoap(String ss) throws XMLStreamException, JAXBException{ + public static AdjustmentRequestRes formsoapAdjust(String ss) throws XMLStreamException, JAXBException{ + + String [] valuex = ss.split("",-1); + String [] valuey = ss.split("", -1); + String x = valuey[0]+valuex[1]; + + Reader reader = new StringReader(x); + XMLInputFactory factory = XMLInputFactory.newInstance(); // Or newFactory() + XMLStreamReader xsr = factory.createXMLStreamReader(reader); + + AppLog.d("IN:"+xsr); + xsr.nextTag(); + while(!xsr.getLocalName().equals("AdjustmentResult")) { + xsr.nextTag(); + } + + JAXBContext jc = JAXBContext.newInstance(AdjustmentRequestRes.class); + Unmarshaller unmarshaller = jc.createUnmarshaller(); + JAXBElement jb = unmarshaller.unmarshal(xsr, AdjustmentRequestRes.class); + xsr.close(); + + AdjustmentRequestRes customer = jb.getValue(); + return customer; + } + + public static ResultHeader formsoapResultHeader(String ss) throws XMLStreamException, JAXBException{ Reader reader = new StringReader(ss); XMLInputFactory factory = XMLInputFactory.newInstance(); // Or newFactory() @@ -271,14 +297,14 @@ public class MessageParser xsr.nextTag(); } - JAXBContext jc = JAXBContext.newInstance(AdjustmentResponseIns.class); + JAXBContext jc = JAXBContext.newInstance(ResultHeader.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); - JAXBElement jb = unmarshaller.unmarshal(xsr, AdjustmentResponseIns.class); + JAXBElement jb = unmarshaller.unmarshal(xsr, ResultHeader.class); xsr.close(); - AdjustmentResponseIns customer = jb.getValue(); + ResultHeader customer = jb.getValue(); return customer; - }*/ + } public static String toJson(Object obj) { String strJson = ""; diff --git a/src/th/co/ais/ssbsrfc/substate/SubWaitAdjustmentChargeReportResponse.java b/src/th/co/ais/ssbsrfc/substate/SubWaitAdjustmentChargeReportResponse.java index eff3b24..941ca43 100644 --- a/src/th/co/ais/ssbsrfc/substate/SubWaitAdjustmentChargeReportResponse.java +++ b/src/th/co/ais/ssbsrfc/substate/SubWaitAdjustmentChargeReportResponse.java @@ -8,16 +8,21 @@ import ec02.af.data.EquinoxRawData; import ec02.utils.AppLog; import th.co.ais.ssbsrfc.config.Constant; import th.co.ais.ssbsrfc.config.StateConfig; +import th.co.ais.ssbsrfc.instance.AdjustmentRequestRes; import th.co.ais.ssbsrfc.instance.AdjustmentResponseIns; import th.co.ais.ssbsrfc.instance.ChargeReportIns; import th.co.ais.ssbsrfc.instance.EC02Instance; import th.co.ais.ssbsrfc.instance.EQXRawInstance; +import th.co.ais.ssbsrfc.instance.ResultHeader; import th.co.ais.ssbsrfc.message.MessageParser; import th.co.ais.ssbsrfc.utils.EqxStringUtils; public class SubWaitAdjustmentChargeReportResponse extends WaitSubState { + private ResultHeader res = new ResultHeader(); + private AdjustmentRequestRes adj = new AdjustmentRequestRes(); + private AdjustmentResponseIns adjustresponse = new AdjustmentResponseIns(); private ChargeReportIns chargeReportIns = new ChargeReportIns(); public void configSubstate(EC02Instance ec02Instance, EquinoxRawData equinoxRawData) @@ -33,8 +38,20 @@ public class SubWaitAdjustmentChargeReportResponse extends WaitSubState { String value = EqxStringUtils.getMessage(equinoxRawData, ec02Instance); AppLog.d("## PARAMETERS : " + value); - AdjustmentResponseIns ins = (AdjustmentResponseIns) MessageParser.fromSoap(value, AdjustmentResponseIns.class); - AppLog.d(ins.getadjustmentResult().getAcctKey()); + try { + res = (ResultHeader) MessageParser.formsoapResultHeader(value); + adj = (AdjustmentRequestRes) MessageParser.formsoapAdjust(value); + } catch (XMLStreamException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + adjustresponse.setResultHeader(res); + adjustresponse.setAdjustmentResult(adj); + ec02Instance.getAFInstance().setAdjustmentResponseIns(adjustresponse); chargeReportIns.setResult("000"); chargeReportIns.setPrepaidsubscriberflag("1"); diff --git a/src/th/co/ais/ssbsrfc/substate/SubWaitAdjustmentChargeRequestResponse.java b/src/th/co/ais/ssbsrfc/substate/SubWaitAdjustmentChargeRequestResponse.java index 1316d18..2975920 100644 --- a/src/th/co/ais/ssbsrfc/substate/SubWaitAdjustmentChargeRequestResponse.java +++ b/src/th/co/ais/ssbsrfc/substate/SubWaitAdjustmentChargeRequestResponse.java @@ -11,16 +11,20 @@ import ec02.af.data.EquinoxRawData; import ec02.utils.AppLog; import th.co.ais.ssbsrfc.config.Constant; import th.co.ais.ssbsrfc.config.StateConfig; +import th.co.ais.ssbsrfc.instance.AdjustmentRequestRes; import th.co.ais.ssbsrfc.instance.AdjustmentResponseIns; import th.co.ais.ssbsrfc.instance.ChargeResponseIns; import th.co.ais.ssbsrfc.instance.EC02Instance; import th.co.ais.ssbsrfc.instance.EQXRawInstance; +import th.co.ais.ssbsrfc.instance.ResultHeader; import th.co.ais.ssbsrfc.message.MessageParser; import th.co.ais.ssbsrfc.utils.EqxStringUtils; public class SubWaitAdjustmentChargeRequestResponse extends WaitSubState { - + private ResultHeader res = new ResultHeader(); + private AdjustmentRequestRes adj = new AdjustmentRequestRes(); + private AdjustmentResponseIns adjustresponse = new AdjustmentResponseIns(); private ChargeResponseIns chargeResponseIns = new ChargeResponseIns(); public void configSubstate(EC02Instance ec02Instance, EquinoxRawData equinoxRawData) @@ -32,13 +36,25 @@ public class SubWaitAdjustmentChargeRequestResponse extends WaitSubState { public Object getMessage(EC02Instance ec02Instance, EquinoxRawData equinoxRawData) { + String value = EqxStringUtils.getMessage(equinoxRawData, ec02Instance); AppLog.d("## PARAMETERS : " + value); - - AdjustmentResponseIns ins= (AdjustmentResponseIns) MessageParser.fromSoap(value, AdjustmentResponseIns.class); - - AppLog.d(ins.getadjustmentResult().getAcctKey()); + try { + res = (ResultHeader) MessageParser.formsoapResultHeader(value); + adj = (AdjustmentRequestRes) MessageParser.formsoapAdjust(value); + } catch (XMLStreamException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + adjustresponse.setResultHeader(res); + adjustresponse.setAdjustmentResult(adj); + ec02Instance.getAFInstance().setAdjustmentResponseIns(adjustresponse); + Random random = new Random(); Date time = new Date(); String x = time.getTime()+""; diff --git a/src/th/co/ais/ssbsrfc/substate/SubWaitChargeReport.java b/src/th/co/ais/ssbsrfc/substate/SubWaitChargeReport.java index 2ff7940..505a9dc 100644 --- a/src/th/co/ais/ssbsrfc/substate/SubWaitChargeReport.java +++ b/src/th/co/ais/ssbsrfc/substate/SubWaitChargeReport.java @@ -55,7 +55,7 @@ public class SubWaitChargeReport extends WaitSubState { i++; } - + ec02Instance.getAFInstance().setDn(map); this.type = Constant.TYPE_SUCCESS; diff --git a/src/th/co/ais/ssbsrfc/substate/SubWaitChargeRequest.java b/src/th/co/ais/ssbsrfc/substate/SubWaitChargeRequest.java index fac7343..911c19e 100644 --- a/src/th/co/ais/ssbsrfc/substate/SubWaitChargeRequest.java +++ b/src/th/co/ais/ssbsrfc/substate/SubWaitChargeRequest.java @@ -55,7 +55,7 @@ public class SubWaitChargeRequest extends WaitSubState { i++; } - + ec02Instance.getAFInstance().setDn(map); this.type = Constant.TYPE_SUCCESS; -- libgit2 0.21.2