--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java 2009/09/27 19:14:39 348 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java 2009/10/21 08:43:45 462 @@ -24,6 +24,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; +import dk.thoerup.curcuitbreaker.CircuitBreakerException; import dk.thoerup.traininfoservice.DBConnection; /** @@ -39,7 +40,13 @@ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + if (req.getParameter("station") == null) { + resp.sendError(400, "not enough parameters"); + return; + } + int station = Integer.parseInt( req.getParameter("station") ); String format = req.getParameter("format"); @@ -48,12 +55,16 @@ String stationName = getStationName(station); try { - beans = fetcher.lookupDepartures(station); - } catch (java.net.SocketTimeoutException ste) { - logger.warning("Read timed out, station="+station); + beans = fetcher.cachedLookupDepartures(station); + } catch (java.io.IOException ioe) { + logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); + resp.sendError(500); + return; + } catch (CircuitBreakerException cbe) { + logger.warning("Circuitbreaker - failing fast"); resp.sendError(500); return; - } catch (Exception e) { + } catch (Exception e) { logger.log(Level.WARNING, "Unknown exception, station=" +station, e); resp.sendError(500); return;