/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 420 by torben, Wed Oct 7 13:37:37 2009 UTC revision 421 by torben, Thu Oct 8 12:19:42 2009 UTC
# Line 8  import java.util.Collections; Line 8  import java.util.Collections;
8  import java.util.List;  import java.util.List;
9  import java.util.logging.Logger;  import java.util.logging.Logger;
10    
   
11  import com.gargoylesoftware.htmlunit.WebClient;  import com.gargoylesoftware.htmlunit.WebClient;
12  import com.gargoylesoftware.htmlunit.html.DomNodeList;  import com.gargoylesoftware.htmlunit.html.DomNodeList;
13  import com.gargoylesoftware.htmlunit.html.HtmlElement;  import com.gargoylesoftware.htmlunit.html.HtmlElement;
14  import com.gargoylesoftware.htmlunit.html.HtmlPage;  import com.gargoylesoftware.htmlunit.html.HtmlPage;
15    
16    import dk.thoerup.curcuitbreaker.CircuitBreaker;
17    import dk.thoerup.curcuitbreaker.CircuitBreakerManager;
18  import dk.thoerup.traininfoservice.DBConnection;  import dk.thoerup.traininfoservice.DBConnection;
19    
20  public class DepartureFetcher {  public class DepartureFetcher {
# Line 24  public class DepartureFetcher { Line 25  public class DepartureFetcher {
25                    
26                                    
27                    
28          public List<DepartureBean> cachedLookupDepartures(int stationID) throws Exception {          public List<DepartureBean> cachedLookupDepartures(int stationID) throws Throwable {
29    
30                  List<DepartureBean> list = cache.get(stationID);                  List<DepartureBean> list = cache.get(stationID);
31                                    
# Line 38  public class DepartureFetcher { Line 39  public class DepartureFetcher {
39          }          }
40                                    
41    
42          public List<DepartureBean> lookupDepartures(int stationID) throws Exception {          public List<DepartureBean> lookupDepartures(int stationID) throws Throwable {
43                  List<DepartureBean> departureList = new ArrayList<DepartureBean>();                  List<DepartureBean> departureList = new ArrayList<DepartureBean>();
44                                    
45                  Connection conn = null;                  Connection conn = null;
# Line 75  public class DepartureFetcher { Line 76  public class DepartureFetcher {
76                  return departureList;                  return departureList;
77          }          }
78                    
79          public List<DepartureBean> lookupDepartures(String stationcode, String type) throws Exception {          public List<DepartureBean> lookupDepartures(String stationcode, String type) throws Throwable {
80                                    
81                  List<DepartureBean> departureList = new ArrayList<DepartureBean>();                  List<DepartureBean> departureList = new ArrayList<DepartureBean>();
82                                    
# Line 83  public class DepartureFetcher { Line 84  public class DepartureFetcher {
84              webClient.setTimeout(2500);              webClient.setTimeout(2500);
85              webClient.setJavaScriptEnabled(false);              webClient.setJavaScriptEnabled(false);
86                                                            
87                String uri = "http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode;
88                BanedkInvocation wrapper = new BanedkInvocation(webClient, uri);
89                CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
90                            
91              final HtmlPage page = webClient.getPage("http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode);              HtmlPage page = (HtmlPage) breaker.invoke(wrapper);
92                            
93              HtmlElement table = page.getElementById("afgangtabel");              HtmlElement table = page.getElementById("afgangtabel");
94                            
# Line 184  public class DepartureFetcher { Line 188  public class DepartureFetcher {
188          }          }
189                    
190          //test          //test
191          public static void main(String args[]) throws Exception{          public static void main(String args[]) throws Throwable {
192                  DepartureFetcher f = new DepartureFetcher();                  DepartureFetcher f = new DepartureFetcher();
193                  List<DepartureBean> deps = f.lookupDepartures("AR", "FJRN");                  List<DepartureBean> deps = f.lookupDepartures("AR", "FJRN");
194                  for(DepartureBean d : deps) {                  for(DepartureBean d : deps) {

Legend:
Removed from v.420  
changed lines
  Added in v.421

  ViewVC Help
Powered by ViewVC 1.1.20