--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableServlet.java 2010/05/10 06:53:20 716 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableServlet.java 2010/05/10 06:59:01 717 @@ -37,38 +37,28 @@ @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) { @@ -76,23 +66,12 @@ 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();