36 |
|
|
37 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
38 |
try { |
try { |
39 |
|
String data = ""; |
40 |
String data = getData(request); |
String uri = request.getParameter("uri"); |
41 |
|
|
42 |
|
if (uri != null) { |
43 |
|
boolean require = Boolean.parseBoolean( request.getParameter("requiredata") ); |
44 |
|
data = hasData(uri, require); |
45 |
|
} else { |
46 |
|
data = getData(request); |
47 |
|
} |
48 |
|
|
49 |
PrintWriter out = response.getWriter(); |
PrintWriter out = response.getWriter(); |
50 |
out.print(data); |
out.print(data); |
51 |
|
|
|
System.out.println("CompareStations completed"); |
|
52 |
} catch (Exception e) { |
} catch (Exception e) { |
53 |
throw new ServletException(e); |
throw new ServletException(e); |
54 |
} |
} |
64 |
|
|
65 |
StringBuilder sb = new StringBuilder(); |
StringBuilder sb = new StringBuilder(); |
66 |
sb.append("<html>"); |
sb.append("<html>"); |
67 |
sb.append("<head></head>"); |
sb.append("<head>"); |
68 |
|
sb.append("<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>\n"); |
69 |
|
sb.append("<script type='text/javascript' src='compareloader.js'></script>\n"); |
70 |
|
|
71 |
|
sb.append("</head>"); |
72 |
sb.append("<body>"); |
sb.append("<body>"); |
73 |
|
|
74 |
StationDAO dao = new StationDAO(); |
StationDAO dao = new StationDAO(); |
94 |
for (StationEntry station : bean.entries) { |
for (StationEntry station : bean.entries) { |
95 |
if (station.isRegional() || station.isStrain()) { |
if (station.isRegional() || station.isStrain()) { |
96 |
if (station.isRegional() ) { |
if (station.isRegional() ) { |
97 |
String id = URLEncoder.encode(station.getRegional(), "ISO-8859-1"); |
//String id = URLEncoder.encode(station.getRegional(), "ISO-8859-1"); |
98 |
|
String id = station.getRegional(); |
99 |
String uri = "/Trafikinformation/AfgangAnkomst/Afgang/" + id + "/Fjerntog"; |
String uri = "/Trafikinformation/AfgangAnkomst/Afgang/" + id + "/Fjerntog"; |
100 |
|
|
|
String data = hasData(uri, true); |
|
101 |
|
|
102 |
sb.append( "<li><a target='_blank' href='http://trafikinfo.bane.dk" + uri + "'>" + station.getName() + "</a> " + data + "</li>\n" ); |
sb.append( "<li><a target='_blank' href='http://trafikinfo.bane.dk" + uri + "'>" + station.getName() + "</a> <span class='uri' requiredata='true' uri='" + uri + "'></span> </li>\n" ); |
103 |
} |
} |
104 |
if (station.isStrain() ) { |
if (station.isStrain() ) { |
105 |
String id = URLEncoder.encode(station.getStrain(), "ISO-8859-1"); |
//String id = URLEncoder.encode(station.getStrain(), "ISO-8859-1"); |
106 |
|
String id = station.getStrain(); |
107 |
String uri = "/Trafikinformation/AfgangAnkomst/Afgang/" + id + "/S-Tog"; |
String uri = "/Trafikinformation/AfgangAnkomst/Afgang/" + id + "/S-Tog"; |
108 |
|
|
|
String data = hasData(uri, true); |
|
109 |
|
|
110 |
sb.append( "<li><a target='_blank' href='http://trafikinfo.bane.dk" + uri + "'>" + station.getName() + "</a> " + data + "</li>\n" ); |
sb.append( "<li><a target='_blank' href='http://trafikinfo.bane.dk" + uri + "'>" + station.getName() + "</a> <span class='uri' requiredata='true' uri='" + uri + "'></span> </li>\n" ); |
111 |
} |
} |
112 |
|
|
113 |
dbStations.add(station.getName()); |
dbStations.add(station.getName()); |
132 |
for(String s : tmpBanedkStations) { |
for(String s : tmpBanedkStations) { |
133 |
String uri = banedkStations.get(s); |
String uri = banedkStations.get(s); |
134 |
String disabled = ""; |
String disabled = ""; |
135 |
String data = hasData(uri, false); |
//String data = hasData(uri, false); |
136 |
|
|
137 |
try { |
try { |
138 |
boolean tmpdisabled = dao.hasDisabledStation(s); |
boolean tmpdisabled = dao.hasDisabledStation(s); |
142 |
throw new ServletException(e); |
throw new ServletException(e); |
143 |
} |
} |
144 |
|
|
145 |
sb.append( "<li><a target='_blank' href='http://trafikinfo.bane.dk" + uri + "'>" + s + "</a> " + data + "" + disabled + "</li>\n" ); |
sb.append( "<li><a target='_blank' href='http://trafikinfo.bane.dk" + uri + "'>" + s + "</a> <span class='uri' requiredata='false' uri='" + uri + "'></span>" + disabled + "</li>\n" ); |
146 |
} |
} |
147 |
sb.append("</ul>"); |
sb.append("</ul>"); |
148 |
|
|
183 |
String hasDataWorker(String uri, boolean requiredata) throws Exception { |
String hasDataWorker(String uri, boolean requiredata) throws Exception { |
184 |
String returnVal = ""; |
String returnVal = ""; |
185 |
|
|
186 |
|
String parts[] = uri.split("\\/"); |
187 |
|
String id = URLEncoder.encode(parts[4], "ISO-8859-1"); |
188 |
|
String uri2 = "/TrafikInformation/AfgangAnkomst/Afgang/" + id + "/" + parts[5]; |
189 |
|
|
190 |
CircuitBreaker cb = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); |
CircuitBreaker cb = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); |
191 |
|
|
192 |
JsoupInvocation jsoup = new JsoupInvocation(new URL("http://trafikinfo.bane.dk" + uri), 2000); |
JsoupInvocation jsoup = new JsoupInvocation(new URL("http://trafikinfo.bane.dk" + uri2), 2000); |
193 |
|
|
194 |
Document doc = (Document) cb.invoke(jsoup); |
Document doc = (Document) cb.invoke(jsoup); |
195 |
|
|