Commit 3959fcd8ab01a626f76ee823949c6ec6ca0031af

Authored by Suraputt Suntimitr
1 parent 8ecfc36c
Exists in INGW_CMF

Response Soap

src/th/co/ais/ssbsrfc/control/TestMain.java
... ... @@ -2,26 +2,27 @@ package th.co.ais.ssbsrfc.control;
2 2  
3 3 import java.io.ByteArrayInputStream;
4 4 import java.io.File;
  5 +import java.io.Reader;
  6 +import java.io.StringReader;
5 7 import java.util.Scanner;
6 8  
7 9 import javax.xml.bind.JAXBContext;
  10 +import javax.xml.bind.JAXBElement;
8 11 import javax.xml.bind.Unmarshaller;
9   -import javax.xml.bind.annotation.XmlAccessType;
10   -import javax.xml.bind.annotation.XmlAccessorType;
11 12 import javax.xml.soap.MessageFactory;
12 13 import javax.xml.soap.SOAPBody;
13 14 import javax.xml.soap.SOAPMessage;
  15 +import javax.xml.stream.XMLInputFactory;
  16 +import javax.xml.stream.XMLStreamReader;
14 17  
15   -import th.co.ais.ssbsrfc.instance.AdjustmentResponseIns;
16   -import th.co.ais.ssbsrfc.message.MessageParser;
17   -
18   -@XmlAccessorType(XmlAccessType.FIELD)
19   -
20   -
21   -
  18 +import th.co.ais.ssbsrfc.instance.AdjustmentRequestRes;
  19 +import th.co.ais.ssbsrfc.instance.ResultHeader;
22 20  
23 21 public class TestMain {
24 22  
  23 + static AdjustmentRequestRes adj = new AdjustmentRequestRes();
  24 + static ResultHeader res = new ResultHeader();
  25 +
25 26 public static Object fromSoap(String strSoap, Class objClass) {
26 27 Object obj = null;
27 28  
... ... @@ -40,47 +41,64 @@ public class TestMain {
40 41 }
41 42  
42 43 public static void main(String[] args) throws Exception {
  44 +
  45 + String value = new Scanner(new File("D:\\car.xml")).useDelimiter("\\Z").next();
  46 + String [] valuex = value.split("</ResultHeader>",-1);
  47 + String [] valuey = value.split("<ResultHeader>", -1);
  48 + String msg = "";
  49 + String x = valuey[0]+valuex[1];
43 50  
44   -// String msg = "";
45   -// XMLInputFactory xif = XMLInputFactory.newFactory();
46   -// StreamSource xml = new StreamSource("D:\\car.xml");
47   -// XMLStreamReader xsr = xif.createXMLStreamReader(xml);
48   -// xsr.nextTag();
49   -//
50   -// while(!xsr.getLocalName().equals("ResultHeader")) {
51   -// if(xsr.getLocalName().equals("ResultHeader")){
52   -//
53   -// }
54   -// xsr.nextTag();
55   -// System.out.println(xsr.getLocalName());
56   -// }
57   -//
58   -// JAXBContext jc = JAXBContext.newInstance(Customer.class);
59   -// Unmarshaller unmarshaller = jc.createUnmarshaller();
60   -// JAXBElement<Customer> jb = unmarshaller.unmarshal(xsr, Customer.class);
61   -// xsr.close();
62   -//
63   -// Customer customer = jb.getValue();
64   -// System.out.println("Version:"+customer.Version);
65   -// System.out.println("ResultCode:"+customer.ResultCode);
66   -// System.out.println("MsgLanguageCode:"+customer.MsgLanguageCode);
67   -// System.out.println("ResultDesc:"+customer.ResultDesc);
68   -// System.out.println("AcctKey:"+customer.AcctKey);
  51 + Reader reader = new StringReader(value);
  52 + XMLInputFactory factory = XMLInputFactory.newInstance(); // Or newFactory()
  53 + XMLStreamReader xsr = factory.createXMLStreamReader(reader);
  54 + Reader readerx = new StringReader(x);
  55 + XMLInputFactory factoryx = XMLInputFactory.newInstance(); // Or newFactory()
  56 + XMLStreamReader xsrx = factoryx.createXMLStreamReader(readerx);
  57 + xsr.nextTag();
  58 + xsrx.nextTag();
  59 + while(!xsr.getLocalName().equals("ResultHeader")) {
  60 + xsr.nextTag();
  61 + }
  62 + while(!xsrx.getLocalName().equals("AdjustmentResult")) {
  63 + xsrx.nextTag();
  64 + }
  65 +
  66 + JAXBContext jc = JAXBContext.newInstance(AdjustmentRequestRes.class);
  67 +
  68 + Unmarshaller unmarshaller = jc.createUnmarshaller();
  69 +
  70 + JAXBElement<AdjustmentRequestRes> jb = unmarshaller.unmarshal(xsrx, AdjustmentRequestRes.class);
  71 + xsrx.close();
  72 +
  73 + adj = jb.getValue();
69 74  
  75 + jc = JAXBContext.newInstance(ResultHeader.class);
  76 + unmarshaller = jc.createUnmarshaller();
  77 + JAXBElement<ResultHeader> jbe = unmarshaller.unmarshal(xsr, ResultHeader.class);
70 78  
71   - /* System.out.println("BalanceID:"+customer.AdjustmentInfo.get(0).getBalanceID());
  79 + res = jbe.getValue();
  80 +
  81 + System.out.println("getVersion:"+res.getVersion());
  82 + System.out.println("getMsgLanguageCode:"+res.getMsgLanguageCode());
  83 +
  84 + System.out.println("getAcctKey:"+adj.getAcctKey());
  85 + System.out.println("getBalanceID:"+adj.getAdjustmentInfo().get(0).getBalanceID());
  86 +
  87 + //System.out.println("Version:"+customer.getresultHeader().getVersion());
  88 + /*
  89 + System.out.println("ResultCode:"+customer.ResultCode);
  90 + System.out.println("MsgLanguageCode:"+customer.MsgLanguageCode);
  91 + System.out.println("ResultDesc:"+customer.ResultDesc);
  92 + System.out.println("AcctKey:"+customer.AcctKey);
  93 +
  94 +
  95 + System.out.println("BalanceID:"+customer.AdjustmentInfo.get(0).getBalanceID());
72 96 System.out.println("BalanceType:"+customer.AdjustmentInfo.get(0).getBalanceType());
73 97 System.out.println("BalanceTypeName:"+customer.AdjustmentInfo.get(0).getBalanceTypeName());
74 98 System.out.println("CurrencyID:"+customer.AdjustmentInfo.get(0).CurrencyID);
75 99 System.out.println("NewBalanceAmt:"+customer.AdjustmentInfo.get(0).NewBalanceAmt);
76   - System.out.println("OldBalanceAmt:"+customer.AdjustmentInfo.get(0).OldBalanceAmt);*/
77   -
78   - String value = new Scanner(new File("D:\\car.xml")).useDelimiter("\\Z").next();
79   -
80   -
81   - AdjustmentResponseIns ins = (AdjustmentResponseIns)MessageParser.fromSoap(value, AdjustmentResponseIns.class);
82   -
83   - System.out.println(MessageParser.toJson(ins));
  100 + System.out.println("OldBalanceAmt:"+customer.AdjustmentInfo.get(0).OldBalanceAmt);
  101 + */
84 102  
85 103 }
86 104 }
... ...
src/th/co/ais/ssbsrfc/instance/AFInstance.java
... ... @@ -48,7 +48,21 @@ public class AFInstance {
48 48 private Map<String, RetryIns> dicRetry = null;
49 49  
50 50 private AdjustmentRequestIns adjustmentRequestIns = null;
  51 + private AdjustmentResponseIns adjustmentResponseIns = null;
  52 + private HashMap<String, String> Dn = null;
51 53  
  54 + public HashMap<String, String> getDn() {
  55 + return Dn;
  56 + }
  57 + public void setDn(HashMap<String, String> dn) {
  58 + Dn = dn;
  59 + }
  60 + public AdjustmentResponseIns getAdjustmentResponseIns() {
  61 + return adjustmentResponseIns;
  62 + }
  63 + public void setAdjustmentResponseIns(AdjustmentResponseIns adjustmentResponseIns) {
  64 + this.adjustmentResponseIns = adjustmentResponseIns;
  65 + }
52 66 public AdjustmentRequestIns getAdjustmentRequestIns() {
53 67 return adjustmentRequestIns;
54 68 }
... ...
src/th/co/ais/ssbsrfc/message/MessageParser.java
... ... @@ -31,7 +31,8 @@ import com.google.gson.JsonElement;
31 31 import com.google.gson.JsonObject;
32 32  
33 33 import ec02.utils.AppLog;
34   -import th.co.ais.ssbsrfc.instance.AdjustmentResponseIns;
  34 +import th.co.ais.ssbsrfc.instance.AdjustmentRequestRes;
  35 +import th.co.ais.ssbsrfc.instance.ResultHeader;
35 36 import th.co.ais.ssbsrfc.instance.SOAPNamespaceMapper;
36 37  
37 38 public class MessageParser
... ... @@ -259,7 +260,32 @@ public class MessageParser
259 260 return obj;
260 261 }
261 262  
262   - /*public static AdjustmentResponseIns formsoap(String ss) throws XMLStreamException, JAXBException{
  263 + public static AdjustmentRequestRes formsoapAdjust(String ss) throws XMLStreamException, JAXBException{
  264 +
  265 + String [] valuex = ss.split("</ResultHeader>",-1);
  266 + String [] valuey = ss.split("<ResultHeader>", -1);
  267 + String x = valuey[0]+valuex[1];
  268 +
  269 + Reader reader = new StringReader(x);
  270 + XMLInputFactory factory = XMLInputFactory.newInstance(); // Or newFactory()
  271 + XMLStreamReader xsr = factory.createXMLStreamReader(reader);
  272 +
  273 + AppLog.d("IN:"+xsr);
  274 + xsr.nextTag();
  275 + while(!xsr.getLocalName().equals("AdjustmentResult")) {
  276 + xsr.nextTag();
  277 + }
  278 +
  279 + JAXBContext jc = JAXBContext.newInstance(AdjustmentRequestRes.class);
  280 + Unmarshaller unmarshaller = jc.createUnmarshaller();
  281 + JAXBElement<AdjustmentRequestRes> jb = unmarshaller.unmarshal(xsr, AdjustmentRequestRes.class);
  282 + xsr.close();
  283 +
  284 + AdjustmentRequestRes customer = jb.getValue();
  285 + return customer;
  286 + }
  287 +
  288 + public static ResultHeader formsoapResultHeader(String ss) throws XMLStreamException, JAXBException{
263 289  
264 290 Reader reader = new StringReader(ss);
265 291 XMLInputFactory factory = XMLInputFactory.newInstance(); // Or newFactory()
... ... @@ -271,14 +297,14 @@ public class MessageParser
271 297 xsr.nextTag();
272 298 }
273 299  
274   - JAXBContext jc = JAXBContext.newInstance(AdjustmentResponseIns.class);
  300 + JAXBContext jc = JAXBContext.newInstance(ResultHeader.class);
275 301 Unmarshaller unmarshaller = jc.createUnmarshaller();
276   - JAXBElement<AdjustmentResponseIns> jb = unmarshaller.unmarshal(xsr, AdjustmentResponseIns.class);
  302 + JAXBElement<ResultHeader> jb = unmarshaller.unmarshal(xsr, ResultHeader.class);
277 303 xsr.close();
278 304  
279   - AdjustmentResponseIns customer = jb.getValue();
  305 + ResultHeader customer = jb.getValue();
280 306 return customer;
281   - }*/
  307 + }
282 308  
283 309 public static String toJson(Object obj) {
284 310 String strJson = "";
... ...
src/th/co/ais/ssbsrfc/substate/SubWaitAdjustmentChargeReportResponse.java
... ... @@ -8,16 +8,21 @@ import ec02.af.data.EquinoxRawData;
8 8 import ec02.utils.AppLog;
9 9 import th.co.ais.ssbsrfc.config.Constant;
10 10 import th.co.ais.ssbsrfc.config.StateConfig;
  11 +import th.co.ais.ssbsrfc.instance.AdjustmentRequestRes;
11 12 import th.co.ais.ssbsrfc.instance.AdjustmentResponseIns;
12 13 import th.co.ais.ssbsrfc.instance.ChargeReportIns;
13 14 import th.co.ais.ssbsrfc.instance.EC02Instance;
14 15 import th.co.ais.ssbsrfc.instance.EQXRawInstance;
  16 +import th.co.ais.ssbsrfc.instance.ResultHeader;
15 17 import th.co.ais.ssbsrfc.message.MessageParser;
16 18 import th.co.ais.ssbsrfc.utils.EqxStringUtils;
17 19  
18 20  
19 21 public class SubWaitAdjustmentChargeReportResponse extends WaitSubState {
20 22  
  23 + private ResultHeader res = new ResultHeader();
  24 + private AdjustmentRequestRes adj = new AdjustmentRequestRes();
  25 + private AdjustmentResponseIns adjustresponse = new AdjustmentResponseIns();
21 26 private ChargeReportIns chargeReportIns = new ChargeReportIns();
22 27  
23 28 public void configSubstate(EC02Instance ec02Instance, EquinoxRawData equinoxRawData)
... ... @@ -33,8 +38,20 @@ public class SubWaitAdjustmentChargeReportResponse extends WaitSubState {
33 38 String value = EqxStringUtils.getMessage(equinoxRawData, ec02Instance);
34 39 AppLog.d("## PARAMETERS : " + value);
35 40  
36   - AdjustmentResponseIns ins = (AdjustmentResponseIns) MessageParser.fromSoap(value, AdjustmentResponseIns.class);
37   - AppLog.d(ins.getadjustmentResult().getAcctKey());
  41 + try {
  42 + res = (ResultHeader) MessageParser.formsoapResultHeader(value);
  43 + adj = (AdjustmentRequestRes) MessageParser.formsoapAdjust(value);
  44 + } catch (XMLStreamException e) {
  45 + // TODO Auto-generated catch block
  46 + e.printStackTrace();
  47 + } catch (JAXBException e) {
  48 + // TODO Auto-generated catch block
  49 + e.printStackTrace();
  50 + }
  51 +
  52 + adjustresponse.setResultHeader(res);
  53 + adjustresponse.setAdjustmentResult(adj);
  54 + ec02Instance.getAFInstance().setAdjustmentResponseIns(adjustresponse);
38 55  
39 56 chargeReportIns.setResult("000");
40 57 chargeReportIns.setPrepaidsubscriberflag("1");
... ...
src/th/co/ais/ssbsrfc/substate/SubWaitAdjustmentChargeRequestResponse.java
... ... @@ -11,16 +11,20 @@ import ec02.af.data.EquinoxRawData;
11 11 import ec02.utils.AppLog;
12 12 import th.co.ais.ssbsrfc.config.Constant;
13 13 import th.co.ais.ssbsrfc.config.StateConfig;
  14 +import th.co.ais.ssbsrfc.instance.AdjustmentRequestRes;
14 15 import th.co.ais.ssbsrfc.instance.AdjustmentResponseIns;
15 16 import th.co.ais.ssbsrfc.instance.ChargeResponseIns;
16 17 import th.co.ais.ssbsrfc.instance.EC02Instance;
17 18 import th.co.ais.ssbsrfc.instance.EQXRawInstance;
  19 +import th.co.ais.ssbsrfc.instance.ResultHeader;
18 20 import th.co.ais.ssbsrfc.message.MessageParser;
19 21 import th.co.ais.ssbsrfc.utils.EqxStringUtils;
20 22  
21 23  
22 24 public class SubWaitAdjustmentChargeRequestResponse extends WaitSubState {
23   -
  25 + private ResultHeader res = new ResultHeader();
  26 + private AdjustmentRequestRes adj = new AdjustmentRequestRes();
  27 + private AdjustmentResponseIns adjustresponse = new AdjustmentResponseIns();
24 28 private ChargeResponseIns chargeResponseIns = new ChargeResponseIns();
25 29  
26 30 public void configSubstate(EC02Instance ec02Instance, EquinoxRawData equinoxRawData)
... ... @@ -32,13 +36,25 @@ public class SubWaitAdjustmentChargeRequestResponse extends WaitSubState {
32 36  
33 37 public Object getMessage(EC02Instance ec02Instance, EquinoxRawData equinoxRawData)
34 38 {
  39 +
35 40 String value = EqxStringUtils.getMessage(equinoxRawData, ec02Instance);
36 41 AppLog.d("## PARAMETERS : " + value);
37   -
38   - AdjustmentResponseIns ins= (AdjustmentResponseIns) MessageParser.fromSoap(value, AdjustmentResponseIns.class);
39   -
40   - AppLog.d(ins.getadjustmentResult().getAcctKey());
41 42  
  43 + try {
  44 + res = (ResultHeader) MessageParser.formsoapResultHeader(value);
  45 + adj = (AdjustmentRequestRes) MessageParser.formsoapAdjust(value);
  46 + } catch (XMLStreamException e) {
  47 + // TODO Auto-generated catch block
  48 + e.printStackTrace();
  49 + } catch (JAXBException e) {
  50 + // TODO Auto-generated catch block
  51 + e.printStackTrace();
  52 + }
  53 +
  54 + adjustresponse.setResultHeader(res);
  55 + adjustresponse.setAdjustmentResult(adj);
  56 + ec02Instance.getAFInstance().setAdjustmentResponseIns(adjustresponse);
  57 +
42 58 Random random = new Random();
43 59 Date time = new Date();
44 60 String x = time.getTime()+"";
... ...
src/th/co/ais/ssbsrfc/substate/SubWaitChargeReport.java
... ... @@ -55,7 +55,7 @@ public class SubWaitChargeReport extends WaitSubState {
55 55 i++;
56 56 }
57 57  
58   -
  58 + ec02Instance.getAFInstance().setDn(map);
59 59  
60 60 this.type = Constant.TYPE_SUCCESS;
61 61  
... ...
src/th/co/ais/ssbsrfc/substate/SubWaitChargeRequest.java
... ... @@ -55,7 +55,7 @@ public class SubWaitChargeRequest extends WaitSubState {
55 55 i++;
56 56 }
57 57  
58   -
  58 + ec02Instance.getAFInstance().setDn(map);
59 59  
60 60 this.type = Constant.TYPE_SUCCESS;
61 61  
... ...