--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java 2010/07/05 09:48:06 958 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java 2010/09/02 18:37:49 1026 @@ -1,7 +1,6 @@ package dk.thoerup.traininfoservice.banedk; import java.io.IOException; -import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -23,7 +22,6 @@ import org.w3c.dom.Element; import dk.thoerup.circuitbreaker.CircuitBreakerException; -import dk.thoerup.traininfoservice.StationDAO; import dk.thoerup.traininfoservice.Statistics; /** @@ -46,8 +44,9 @@ boolean useTempSite = Boolean.parseBoolean( getServletContext().getInitParameter("usetempsite") ); int cacheTimeout = Integer.parseInt( getServletContext().getInitParameter("cache_timeout") ); + int replyTimeout = Integer.parseInt( getServletContext().getInitParameter("reply_timeout") ); logger.info( "DepartureServlet, use temp site=" + useTempSite + ", cache=" + cacheTimeout); - fetcher = new DepartureFetcher(useTempSite, cacheTimeout); + fetcher = new DepartureFetcher(useTempSite, cacheTimeout, replyTimeout); } @Override @@ -67,9 +66,7 @@ int station = Integer.parseInt( req.getParameter("station") ); String format = req.getParameter("format"); - List beans; - - String stationName = StationDAO.getStationName(station); + DepartureBean beans; try { beans = fetcher.cachedLookupDepartures(station, arrival); @@ -95,14 +92,13 @@ if (format.equalsIgnoreCase("xml")) { resp.setContentType("text/xml"); - resp.getWriter().print( formatXml(beans, stationName) ); + resp.getWriter().print( formatXml(beans, arrival) ); } else if (format.equalsIgnoreCase("html")) { String advStr = req.getParameter("advanced"); boolean advanced = advStr != null ? Boolean.parseBoolean(advStr) : false; req.setAttribute("advanced", advanced); - req.setAttribute("stationname", stationName ); req.setAttribute("departurebeans", beans); req.setAttribute("stationID", station ); getServletContext().getRequestDispatcher("/ViewDepartures.jsp").forward(req,resp); @@ -112,7 +108,7 @@ } - protected String formatXml(List beans, String stationName) throws ServletException{ + protected String formatXml(DepartureBean beans, boolean arrival) throws ServletException{ String xml = ""; try { DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); @@ -121,8 +117,16 @@ Document doc = impl.createDocument(null,null,null); Element root = doc.createElement("departureinfo"); - root.setAttribute("station", stationName); - for (DepartureBean departure : beans) { + root.setAttribute("station", beans.getStationName()); + root.setAttribute("arrival", Boolean.toString(arrival) ); + + for (String notif : beans.notifications) { + Element notElem = doc.createElement("notification"); + notElem.setTextContent(notif); + root.appendChild(notElem); + } + + for (DepartureEntry departure : beans.departureEntries) { Element train = doc.createElement("train"); Element time = doc.createElement("time");