--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java 2011/04/21 05:51:25 1372 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java 2011/04/23 08:01:57 1373 @@ -17,6 +17,7 @@ import org.simpleframework.xml.core.Persister; import dk.thoerup.android.traininfo.common.DepartureBean; +import dk.thoerup.android.traininfo.common.StationBean; import dk.thoerup.circuitbreaker.CircuitBreakerException; import dk.thoerup.traininfoservice.Statistics; import dk.thoerup.traininfoservice.TraininfoSettings; @@ -89,19 +90,18 @@ type = FetchTrainType.valueOf( req.getParameter("type") ); } + try { beans = fetcher.cachedLookupDepartures(station, arrival, type); beans.arrival = arrival; } catch (java.io.IOException ioe) { logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); Statistics.getInstance().incrementDepartureErrors(); - resp.sendError(500); - return; + beans = generateErrorBean(1); } catch (CircuitBreakerException cbe) { logger.warning("Circuitbreaker - failing fast, station=" +station); Statistics.getInstance().incrementDepartureErrors(); - resp.sendError(500); - return; + beans = generateErrorBean(1); } catch (StationDAO.NostationException nse) { logger.log(Level.WARNING, "Station not in Database, station=" +station); Statistics.getInstance().incrementDepartureErrors(); @@ -134,7 +134,13 @@ } else { resp.sendError(400, "Unknown format"); } - + } + + protected DepartureBean generateErrorBean(int code) { + DepartureBean bean = new DepartureBean(); + bean.stationName=""; + bean.errorCode = code; + return bean; } protected String formatXml(DepartureBean beans) throws ServletException{