TestMain.java
3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package th.co.ais.ssbsrfc.control;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.Scanner;
import javax.xml.bind.JAXBContext;
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 th.co.ais.ssbsrfc.instance.AdjustmentResponseIns;
import th.co.ais.ssbsrfc.message.MessageParser;
@XmlAccessorType(XmlAccessType.FIELD)
public class TestMain {
public static Object fromSoap(String strSoap, Class objClass) {
Object obj = null;
try {
SOAPMessage message = MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream(strSoap.getBytes()));
Unmarshaller unmarshaller = JAXBContext.newInstance(objClass).createUnmarshaller();
SOAPBody body = message.getSOAPBody();
if(body != null && !body.getTextContent().trim().equals("")) {
obj = unmarshaller.unmarshal(body.extractContentAsDocument());
}
} catch (Exception e) {
e.printStackTrace();
}
return obj;
}
public static void main(String[] args) throws Exception {
// 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<Customer> 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);
/* 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));
}
}