--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableServlet.java 2011/04/21 05:51:25 1372 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableServlet.java 2011/04/23 08:01:57 1373 @@ -15,6 +15,7 @@ import org.simpleframework.xml.Serializer; import org.simpleframework.xml.core.Persister; +import dk.thoerup.android.traininfo.common.DepartureBean; import dk.thoerup.android.traininfo.common.TimetableBean; import dk.thoerup.circuitbreaker.CircuitBreakerException; import dk.thoerup.traininfoservice.Statistics; @@ -56,29 +57,40 @@ String train = request.getParameter("train").trim(); String type = request.getParameter("type").trim(); - + + + TimetableBean timetable = null; try { - TimetableBean timetable = fetcher.cachedLookupTimetable(train, type); - - String responseXML = formatTimetable(timetable); + timetable = fetcher.cachedLookupTimetable(train, type); - response.setContentType("text/xml"); - response.getWriter().print(responseXML); } catch (java.io.IOException ioe) { logger.warning("(timetable) Read failed, type=" + type + ", train="+train + ". " + ioe.getMessage()); Statistics.getInstance().incrementTimetableErrors(); - response.sendError(500, "Backend timed out"); + timetable = generateErrorBean(1); } catch (CircuitBreakerException cbe) { logger.warning("Circuitbreaker - failing fast, type=" + type + ", train="+train); - Statistics.getInstance().incrementTimetableErrors(); - response.sendError(500); + Statistics.getInstance().incrementTimetableErrors(); + timetable = generateErrorBean(1); }catch (Exception e) { logger.log(Level.WARNING, "failure looking up timetable: type=" + type + ",train=" +train, e); Statistics.getInstance().incrementTimetableErrors(); response.sendError(500); } + if (timetable != null) { + String responseXML = formatTimetable(timetable); + + response.setContentType("text/xml"); + response.getWriter().print(responseXML); + } + + } + + protected TimetableBean generateErrorBean(int code) { + TimetableBean bean = new TimetableBean(); + bean.errorCode = code; + return bean; } String formatTimetable(TimetableBean timetable) throws ServletException {