24 |
import org.w3c.dom.Document; |
import org.w3c.dom.Document; |
25 |
import org.w3c.dom.Element; |
import org.w3c.dom.Element; |
26 |
|
|
27 |
|
import dk.thoerup.curcuitbreaker.CircuitBreakerException; |
28 |
import dk.thoerup.traininfoservice.DBConnection; |
import dk.thoerup.traininfoservice.DBConnection; |
29 |
|
|
30 |
/** |
/** |
40 |
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); |
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); |
41 |
|
|
42 |
|
|
43 |
|
@Override |
44 |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
45 |
|
if (req.getParameter("station") == null) { |
46 |
|
resp.sendError(400, "not enough parameters"); |
47 |
|
return; |
48 |
|
} |
49 |
|
|
50 |
int station = Integer.parseInt( req.getParameter("station") ); |
int station = Integer.parseInt( req.getParameter("station") ); |
51 |
String format = req.getParameter("format"); |
String format = req.getParameter("format"); |
52 |
|
|
55 |
String stationName = getStationName(station); |
String stationName = getStationName(station); |
56 |
|
|
57 |
try { |
try { |
58 |
beans = fetcher.lookupDepartures(station); |
beans = fetcher.cachedLookupDepartures(station); |
59 |
} catch (java.net.SocketTimeoutException ste) { |
} catch (java.net.SocketTimeoutException ste) { |
60 |
logger.warning("Read timed out, station="+station); |
logger.warning("Read timed out, station="+station); |
61 |
resp.sendError(500); |
resp.sendError(500); |
62 |
return; |
return; |
63 |
} catch (Exception e) { |
} catch (CircuitBreakerException cbe) { |
64 |
|
logger.warning("Circuitbreaker - failing fast"); |
65 |
|
resp.sendError(500); |
66 |
|
return; |
67 |
|
} catch (Exception e) { |
68 |
logger.log(Level.WARNING, "Unknown exception, station=" +station, e); |
logger.log(Level.WARNING, "Unknown exception, station=" +station, e); |
69 |
resp.sendError(500); |
resp.sendError(500); |
70 |
return; |
return; |