--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java 2010/05/03 07:42:02 697 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java 2010/07/05 09:48:06 958 @@ -6,6 +6,7 @@ import java.util.logging.Logger; import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -23,10 +24,12 @@ import dk.thoerup.circuitbreaker.CircuitBreakerException; import dk.thoerup.traininfoservice.StationDAO; +import dk.thoerup.traininfoservice.Statistics; /** * Servlet implementation class DepartureServlet */ +@WebServlet(urlPatterns={"/DepartureServlet"}) public class DepartureServlet extends HttpServlet { private static final long serialVersionUID = 1L; @@ -48,12 +51,19 @@ } @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; } + boolean arrival = false; + try { + arrival = Integer.parseInt( req.getParameter("arrival")) != 0; + } catch (Exception e) {} + + Statistics.getInstance().incrementDepartureLookups(); + int station = Integer.parseInt( req.getParameter("station") ); String format = req.getParameter("format"); @@ -62,17 +72,20 @@ String stationName = StationDAO.getStationName(station); try { - beans = fetcher.cachedLookupDepartures(station); + beans = fetcher.cachedLookupDepartures(station, arrival); } 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; } @@ -94,7 +107,7 @@ req.setAttribute("stationID", station ); getServletContext().getRequestDispatcher("/ViewDepartures.jsp").forward(req,resp); } else { - throw new ServletException("Unknown format"); + resp.sendError(400, "Unknown format"); } } @@ -160,7 +173,7 @@ //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); - transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "1"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); java.io.StringWriter sw = new java.io.StringWriter(); StreamResult sr = new StreamResult(sw);