15 |
|
|
16 |
@Override |
@Override |
17 |
public void run() { |
public void run() { |
18 |
long start = System.currentTimeMillis(); |
|
19 |
ResultBuffer rb = ResultBuffer.getResultBuffer(); |
ResultBuffer rb = ResultBuffer.getResultBuffer(); |
20 |
try { |
try { |
21 |
|
|
22 |
rb.clear(); |
rb.clear(); |
23 |
rb.addString(start, "Starting"); |
rb.addString("Starting"); |
24 |
|
|
25 |
|
|
26 |
Response res = Jsoup.connect("http://medlemssystem.spejdernet.dk/login.aspx?ReturnUrl=%2f").execute(); |
Response res = Jsoup.connect("http://medlemssystem.spejdernet.dk/login.aspx?ReturnUrl=%2f").execute(); |
27 |
Map<String, String> cookies = res.cookies(); |
Map<String, String> cookies = res.cookies(); |
28 |
|
|
29 |
rb.addString(start, "Got login page"); |
rb.addString("Got login page"); |
30 |
|
|
31 |
res = Jsoup |
res = Jsoup |
32 |
.connect("http://medlemssystem.spejdernet.dk/Login.aspx?changeuser=1") |
.connect("http://medlemssystem.spejdernet.dk/Login.aspx?changeuser=1") |
42 |
.cookies(cookies) |
.cookies(cookies) |
43 |
.execute(); |
.execute(); |
44 |
|
|
45 |
rb.addString(start, "Login OK"); |
rb.addString("Login OK"); |
46 |
//This will get you cookies |
//This will get you cookies |
47 |
cookies.putAll( res.cookies() ); |
cookies.putAll( res.cookies() ); |
48 |
//printMap(cookies); |
//printMap(cookies); |
52 |
//And this is the easieste way I've found to remain in session |
//And this is the easieste way I've found to remain in session |
53 |
Response data = Jsoup.connect(dataCsvUrl).cookies(cookies).timeout(10000).execute(); |
Response data = Jsoup.connect(dataCsvUrl).cookies(cookies).timeout(10000).execute(); |
54 |
if ( ! data.contentType().equalsIgnoreCase("text/x-csv; charset=iso-8859-1") ) { |
if ( ! data.contentType().equalsIgnoreCase("text/x-csv; charset=iso-8859-1") ) { |
55 |
rb.addString(start, "Data.csv - has the wrong content type: " + data.contentType()); |
rb.addString("Data.csv - has the wrong content type: " + data.contentType()); |
56 |
return; |
return; |
57 |
} |
} |
58 |
String dataCsv = data.body(); |
String dataCsv = data.body(); |
59 |
rb.addString(start, "Got data.csv"); |
rb.addString("Got data.csv"); |
60 |
|
|
61 |
String rollerCsvUrl = "http://medlemssystem.spejdernet.dk/DataExport.aspx?Id=5c0cf638-dc87-413f-91b6-9c7300c70137&listid=e8c5ae9d-5ea7-4a00-bea4-a0ce00ea891e&execute=true"; |
String rollerCsvUrl = "http://medlemssystem.spejdernet.dk/DataExport.aspx?Id=5c0cf638-dc87-413f-91b6-9c7300c70137&listid=e8c5ae9d-5ea7-4a00-bea4-a0ce00ea891e&execute=true"; |
62 |
Response roller = Jsoup.connect(rollerCsvUrl).cookies(cookies).timeout(10000).execute(); |
Response roller = Jsoup.connect(rollerCsvUrl).cookies(cookies).timeout(10000).execute(); |
63 |
if ( ! roller.contentType().equalsIgnoreCase("text/x-csv; charset=iso-8859-1") ) { |
if ( ! roller.contentType().equalsIgnoreCase("text/x-csv; charset=iso-8859-1") ) { |
64 |
rb.addString(start, "Roller.csv - has the wrong content type: " + roller.contentType()); |
rb.addString("Roller.csv - has the wrong content type: " + roller.contentType()); |
65 |
return; |
return; |
66 |
} |
} |
67 |
String rollerCsv = roller.body(); |
String rollerCsv = roller.body(); |
68 |
rb.addString(start, "Got roller.csv"); |
rb.addString("Got roller.csv"); |
69 |
|
|
70 |
Map<String,String> postData = new TreeMap<String,String>(); |
Map<String,String> postData = new TreeMap<String,String>(); |
71 |
postData.put("roller", rollerCsv); |
postData.put("roller", rollerCsv); |
75 |
byte resp[] = HttpUtil.postContent("http://horsensspejder.t-hoerup.dk/data/postdata.php", params, 3000); |
byte resp[] = HttpUtil.postContent("http://horsensspejder.t-hoerup.dk/data/postdata.php", params, 3000); |
76 |
|
|
77 |
String response = new String(resp); |
String response = new String(resp); |
78 |
rb.addString(start, "POST Response: " + response); |
rb.addString("POST Response: " + response); |
79 |
|
|
80 |
rb.addString(start, "Done !"); |
rb.addString("Done !"); |
81 |
|
|
82 |
} catch (Exception e) { |
} catch (Exception e) { |
83 |
rb.addString(start, "Error occurred: " + e.toString() ); |
rb.addString("Error occurred: " + e.toString() ); |
84 |
} |
} |
85 |
} |
} |
86 |
|
|