--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableServlet.java 2010/05/03 07:42:02 697 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableServlet.java 2010/06/11 17:12:29 836 @@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletResponse; import dk.thoerup.circuitbreaker.CircuitBreakerException; +import dk.thoerup.traininfoservice.Statistics; /** * Servlet implementation class TimetableServlet @@ -36,58 +37,41 @@ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("train") == null) { - response.sendError(400, "not enough parameters"); + response.sendError(400, "not enough parameters (train)"); return; } + if (request.getParameter("type") == null) { + response.sendError(400, "not enough parameters (type)"); + return; + } + Statistics.getInstance().incrementTimetableLookups(); String train = request.getParameter("train").trim(); - String trainID; - String type = request.getParameter("type"); - - if (type != null) { - trainID = train; - } else { //remove this failover sometime after release of client 0.6.4 - String sections[] = train.split(" "); - if (sections.length != 2) { - response.sendError(400, "Invalid parameter"); - return; - } + String type = request.getParameter("type").trim(); - type = lookupType(sections[0]); - trainID = sections[1]; - } - try { - List timetable = fetcher.cachedLookupTimetable(trainID, type); + List timetable = fetcher.cachedLookupTimetable(train, type); String responseXML = formatTimetable(timetable); response.setContentType("text/xml"); response.getWriter().print(responseXML); } catch (java.io.IOException ioe) { - logger.warning("(timetable) Read failed, train="+train + ". " + ioe.getMessage()); + logger.warning("(timetable) Read failed, type=" + type + ", train="+train + ". " + ioe.getMessage()); + Statistics.getInstance().incrementTimetableErrors(); response.sendError(500, "Backend timed out"); } catch (CircuitBreakerException cbe) { logger.warning("Circuitbreaker - failing fast"); + Statistics.getInstance().incrementTimetableErrors(); response.sendError(500); }catch (Exception e) { - logger.log(Level.WARNING, "failure looking up timetable: train=" +train, e); + logger.log(Level.WARNING, "failure looking up timetable: type=" + type + ",train=" +train, e); + Statistics.getInstance().incrementTimetableErrors(); response.sendError(500); } } - /*remove /outcomment/deprecate after 0.6.4 release */ - String lookupType(String trainCode) { - trainCode = trainCode.toLowerCase(); - - if (trainCode.equals("a") || trainCode.equals("b") || trainCode.equals("bx") || trainCode.equals("c") || - trainCode.equals("e") || trainCode.equals("f") || trainCode.equals("h")) { - return "S2"; - } else { - return "FJRN"; - } - } String formatTimetable(List timetable) { StringBuffer sb = new StringBuffer(); @@ -103,6 +87,7 @@ sb.append("").append( bean.getStation() ).append(""); sb.append("").append( bean.getArrival() ).append(""); sb.append("").append( bean.getDeparture() ).append(""); + sb.append("").append( bean.getStationId() ).append(""); sb.append(""); }