TestMain.java
4.6 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package th.co.ais.ssbsrfc.control;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.Reader;
import java.io.StringReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
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 com.sun.org.apache.xalan.internal.xsltc.compiler.Parser;
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;
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 {
Date time = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MMddHHmmssSS");
String ti = sdf.format(new Date());
sdf = new SimpleDateFormat("yyyy");
int i = Integer.parseInt(sdf.format(new Date()))-543;
ti = i+ti;
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSS");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, -543);
System.out.println(time.toString());
System.out.println(time.getTime());
System.out.println(ti);
System.out.println(dateFormat.format(cal.getTime()));
String value = new Scanner(new File("D:\\car.xml")).useDelimiter("\\Z").next();
String [] valuex = value.split("</ResultHeader>",-1);
String [] valuey = value.split("<ResultHeader>", -1);
String msg = "";
String x = valuey[0]+valuex[1];
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<AdjustmentRequestRes> jb = unmarshaller.unmarshal(xsrx, AdjustmentRequestRes.class);
xsrx.close();
adj = jb.getValue();
jc = JAXBContext.newInstance(ResultHeader.class);
unmarshaller = jc.createUnmarshaller();
JAXBElement<ResultHeader> jbe = unmarshaller.unmarshal(xsr, ResultHeader.class);
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);
*/
}
}