/[projects]/android/telmorewidget/src/dk/thoerup/telmorewidget/TelmoreFetcher.java
ViewVC logotype

Annotation of /android/telmorewidget/src/dk/thoerup/telmorewidget/TelmoreFetcher.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1395 - (hide annotations) (download)
Tue Apr 26 18:48:50 2011 UTC (13 years, 1 month ago) by torben
File size: 3226 byte(s)


1 torben 1395 package dk.thoerup.telmorewidget;
2    
3     import java.io.IOException;
4     import java.util.HashMap;
5     import java.util.Map;
6    
7     import org.jsoup.Connection;
8     import org.jsoup.Connection.Method;
9     import org.jsoup.Connection.Response;
10     import org.jsoup.helper.HttpConnection;
11     import org.jsoup.nodes.Document;
12     import org.jsoup.nodes.Element;
13     import org.jsoup.select.Elements;
14    
15     public class TelmoreFetcher {
16    
17     public static class Result {
18     public String saldo;
19     public String internetUsage;
20     }
21    
22    
23     public Result fetch(String username, String password) throws IOException {
24    
25     Map<String,String> params = new HashMap<String,String>();
26     params.put("j_username", username);
27     params.put("j_password", password);
28    
29     String url = "https://www.telmore.dk/t2/j_security_check";
30    
31     Connection con = HttpConnection.connect(url);
32     con.data(params);
33     con.followRedirects(false);
34     con.method( Method.POST );
35     Response resp = con.execute();
36    
37     //System.out.println("" + resp.statusCode() + " " + resp.statusMessage() );
38    
39     String JSESSIONID = resp.cookie("JSESSIONID");
40     String location = resp.header( "Location" );
41    
42     ///////////////////////////////////////////////////////////////////////////////////
43    
44     resp = HttpConnection.connect(location)
45     .followRedirects(false)
46     .cookie("JSESSIONID", JSESSIONID)
47     .method( Method.GET )
48     .execute();
49    
50     //System.out.println("" + resp.statusCode() + " " + resp.statusMessage() );
51     location = resp.header( "Location" );
52    
53     ///////////////////////////////////////////////////////////////////////////////////
54    
55     resp = HttpConnection.connect(location)
56     .followRedirects(false)
57     .cookie("JSESSIONID", JSESSIONID)
58     .method( Method.GET )
59     .execute();
60    
61     //System.out.println("" + resp.statusCode() + " " + resp.statusMessage() );
62     Document doc = resp.parse();
63    
64    
65    
66    
67     String iframeTarget = doc.getElementById("remoteIframePage").attr("abs:src");
68    
69    
70     ///////////////////////////////////////////////////////////////////////////////////
71    
72    
73     resp = HttpConnection.connect(iframeTarget)
74     .referrer(location)
75     .cookie("JSESSIONID", JSESSIONID)
76     .cookie("SS_X_JSESSIONID", resp.cookie("SS_X_JSESSIONID"))
77     .followRedirects(false)
78     .method( Method.GET )
79     .execute();
80    
81    
82    
83     //System.out.println("" + resp.statusCode() + " " + resp.statusMessage() );
84    
85    
86    
87    
88     doc = resp.parse();
89    
90     Element iframeBody = doc.getElementById("iframeBody");
91    
92     Element saldo = iframeBody.getElementsByClass("saldo").first();
93    
94     //System.out.println("Saldo:" + saldo.text() );
95    
96     Elements internet = iframeBody.getElementsByAttributeValue("style", "padding-top: 1px;");
97    
98     //System.out.println( "internet count: " + internet.size() );
99     //System.out.println( "internet: " + internet.first().text() );
100    
101     Result res = new Result();
102     res.saldo = saldo.text();
103     res.internetUsage = internet.first().text();
104    
105     return res;
106     }
107    
108     /*
109     void dumpHeaders(Response resp) {
110     dumpStringmap( resp.headers() );
111     }
112    
113     void dumpCookies(Response resp) {
114     dumpStringmap(resp.cookies());
115     }
116    
117     void dumpStringmap(Map<String,String> map) {
118     for (String key : map.keySet() ) {
119     String val = map.get(key);
120     System.out.println(">>" + key + ": " + val );
121     }
122     }*/
123     }

  ViewVC Help
Powered by ViewVC 1.1.20