--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java 2010/02/05 19:15:12 585 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java 2010/05/10 06:53:20 716 @@ -1,9 +1,6 @@ package dk.thoerup.traininfoservice.banedk; import java.io.IOException; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.Statement; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -25,7 +22,8 @@ import org.w3c.dom.Element; import dk.thoerup.circuitbreaker.CircuitBreakerException; -import dk.thoerup.traininfoservice.DBConnection; +import dk.thoerup.traininfoservice.StationDAO; +import dk.thoerup.traininfoservice.Statistics; /** * Servlet implementation class DepartureServlet @@ -51,31 +49,35 @@ } @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req.getParameter("station") == null) { resp.sendError(400, "not enough parameters"); return; } + Statistics.getInstance().incrementDepartureLookups(); int station = Integer.parseInt( req.getParameter("station") ); String format = req.getParameter("format"); List beans; - String stationName = getStationName(station); + String stationName = StationDAO.getStationName(station); try { beans = fetcher.cachedLookupDepartures(station); } catch (java.io.IOException ioe) { logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); + Statistics.getInstance().incrementDepartureErrors(); resp.sendError(500); return; } catch (CircuitBreakerException cbe) { logger.warning("Circuitbreaker - failing fast"); + Statistics.getInstance().incrementDepartureErrors(); resp.sendError(500); return; } catch (Exception e) { logger.log(Level.WARNING, "Unknown exception, station=" +station, e); + Statistics.getInstance().incrementDepartureErrors(); resp.sendError(500); return; } @@ -147,6 +149,10 @@ note.setTextContent( departure.getNote() ); train.appendChild(note); + Element type = doc.createElement("type"); + type.setTextContent( departure.getType() ); + train.appendChild(type); + root.appendChild(train); } @@ -173,27 +179,4 @@ return xml; } - protected String getStationName(int stationID) { - String station = ""; - - Connection conn = null; - try { - conn = DBConnection.getConnection(); - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT name FROM trainstations WHERE id=" + stationID); - if (rs.next()) { - station = rs.getString(1); - } - - } catch (Exception e) { - } finally { - try { - if (conn != null && !conn.isClosed()) - conn.close(); - } catch (Exception e) {} - } - - return station; - } - }