5 |
import java.net.URL; |
import java.net.URL; |
6 |
import java.util.ArrayList; |
import java.util.ArrayList; |
7 |
import java.util.List; |
import java.util.List; |
8 |
|
import java.util.Map; |
9 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
10 |
|
|
11 |
import com.gargoylesoftware.htmlunit.Page; |
import com.gargoylesoftware.htmlunit.Page; |
15 |
import com.gargoylesoftware.htmlunit.html.HtmlElement; |
import com.gargoylesoftware.htmlunit.html.HtmlElement; |
16 |
import com.gargoylesoftware.htmlunit.html.HtmlPage; |
import com.gargoylesoftware.htmlunit.html.HtmlPage; |
17 |
|
|
18 |
|
import dk.thoerup.circuitbreaker.CircuitBreaker; |
19 |
|
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
20 |
|
|
21 |
public class TimetableFetcher { |
public class TimetableFetcher { |
22 |
|
|
23 |
class NullRefreshHandler implements RefreshHandler { |
class NullRefreshHandler implements RefreshHandler { |
26 |
|
|
27 |
} |
} |
28 |
|
|
29 |
TimeoutCache<String, List<TimetableBean>> cache = new TimeoutCache<String,List<TimetableBean>>(120 * 1000); |
Map<String, List<TimetableBean>> cache = new TimeoutMap<String,List<TimetableBean>>(120 * 1000); |
30 |
|
|
31 |
|
|
32 |
Logger logger = Logger.getLogger(TimetableFetcher.class.getName()); |
Logger logger = Logger.getLogger(TimetableFetcher.class.getName()); |
33 |
|
|
34 |
|
private boolean useTempSite; |
35 |
|
|
36 |
|
public TimetableFetcher(boolean tmpSite) { |
37 |
|
useTempSite = tmpSite; |
38 |
|
} |
39 |
|
|
40 |
|
|
41 |
List<TimetableBean> cachedLookupTimetable(String trainID, String type) throws Exception { |
List<TimetableBean> cachedLookupTimetable(String trainID, String type) throws Exception { |
42 |
String key = trainID+type; |
String key = trainID+type; |
50 |
} |
} |
51 |
return list; |
return list; |
52 |
} |
} |
53 |
|
|
54 |
|
List<TimetableBean> lookupTimetable(String trainID, String type) throws Exception { |
55 |
|
if (useTempSite == false ){ |
56 |
|
return lookupTimetableRealSite(trainID, type); |
57 |
|
} else { |
58 |
|
return new ArrayList<TimetableBean>(); // no timetable data on temp site |
59 |
|
} |
60 |
|
} |
61 |
|
|
62 |
List<TimetableBean> lookupTimetable(String trainID, String type) throws Exception { |
List<TimetableBean> lookupTimetableRealSite(String trainID, String type) throws Exception { |
63 |
List<TimetableBean> timetableList = new ArrayList<TimetableBean>(); |
List<TimetableBean> timetableList = new ArrayList<TimetableBean>(); |
64 |
|
|
65 |
String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276"; |
String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276"; |
72 |
webClient.setCssEnabled(false); |
webClient.setCssEnabled(false); |
73 |
|
|
74 |
|
|
75 |
final HtmlPage page = webClient.getPage(url); |
BanedkInvocation wrapper = new BanedkInvocation(webClient, url); |
76 |
|
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); |
77 |
|
|
78 |
|
HtmlPage page = (HtmlPage) breaker.invoke(wrapper); |
79 |
|
|
80 |
|
|
81 |
boolean currentStation = false; |
boolean currentStation = false; |
82 |
boolean currentStationSaved = false; |
boolean currentStationSaved = false; |