23 |
|
|
24 |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
25 |
import dk.thoerup.traininfoservice.StationDAO; |
import dk.thoerup.traininfoservice.StationDAO; |
26 |
|
import dk.thoerup.traininfoservice.Statistics; |
27 |
|
|
28 |
/** |
/** |
29 |
* Servlet implementation class DepartureServlet |
* Servlet implementation class DepartureServlet |
49 |
} |
} |
50 |
|
|
51 |
@Override |
@Override |
52 |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
53 |
if (req.getParameter("station") == null) { |
if (req.getParameter("station") == null) { |
54 |
resp.sendError(400, "not enough parameters"); |
resp.sendError(400, "not enough parameters"); |
55 |
return; |
return; |
56 |
} |
} |
57 |
|
Statistics.getInstance().incrementDepartureLookups(); |
58 |
|
|
59 |
int station = Integer.parseInt( req.getParameter("station") ); |
int station = Integer.parseInt( req.getParameter("station") ); |
60 |
String format = req.getParameter("format"); |
String format = req.getParameter("format"); |
67 |
beans = fetcher.cachedLookupDepartures(station); |
beans = fetcher.cachedLookupDepartures(station); |
68 |
} catch (java.io.IOException ioe) { |
} catch (java.io.IOException ioe) { |
69 |
logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); |
logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); |
70 |
|
Statistics.getInstance().incrementDepartureErrors(); |
71 |
resp.sendError(500); |
resp.sendError(500); |
72 |
return; |
return; |
73 |
} catch (CircuitBreakerException cbe) { |
} catch (CircuitBreakerException cbe) { |
74 |
logger.warning("Circuitbreaker - failing fast"); |
logger.warning("Circuitbreaker - failing fast"); |
75 |
|
Statistics.getInstance().incrementDepartureErrors(); |
76 |
resp.sendError(500); |
resp.sendError(500); |
77 |
return; |
return; |
78 |
} catch (Exception e) { |
} catch (Exception e) { |
79 |
logger.log(Level.WARNING, "Unknown exception, station=" +station, e); |
logger.log(Level.WARNING, "Unknown exception, station=" +station, e); |
80 |
|
Statistics.getInstance().incrementDepartureErrors(); |
81 |
resp.sendError(500); |
resp.sendError(500); |
82 |
return; |
return; |
83 |
} |
} |
149 |
note.setTextContent( departure.getNote() ); |
note.setTextContent( departure.getNote() ); |
150 |
train.appendChild(note); |
train.appendChild(note); |
151 |
|
|
152 |
|
Element type = doc.createElement("type"); |
153 |
|
type.setTextContent( departure.getType() ); |
154 |
|
train.appendChild(type); |
155 |
|
|
156 |
root.appendChild(train); |
root.appendChild(train); |
157 |
} |
} |
158 |
|
|