22 |
import org.w3c.dom.Element; |
import org.w3c.dom.Element; |
23 |
|
|
24 |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
|
import dk.thoerup.traininfoservice.StationDAO; |
|
25 |
import dk.thoerup.traininfoservice.Statistics; |
import dk.thoerup.traininfoservice.Statistics; |
26 |
|
|
27 |
/** |
/** |
42 |
public void init() throws ServletException { |
public void init() throws ServletException { |
43 |
super.init(); |
super.init(); |
44 |
|
|
45 |
boolean useTempSite = Boolean.parseBoolean( getServletContext().getInitParameter("usetempsite") ); |
boolean useAzureSite = Boolean.parseBoolean( getServletContext().getInitParameter("useazuresite") ); |
46 |
int cacheTimeout = Integer.parseInt( getServletContext().getInitParameter("cache_timeout") ); |
int cacheTimeout = Integer.parseInt( getServletContext().getInitParameter("cache_timeout") ); |
47 |
logger.info( "DepartureServlet, use temp site=" + useTempSite + ", cache=" + cacheTimeout); |
int replyTimeout = Integer.parseInt( getServletContext().getInitParameter("reply_timeout") ); |
48 |
fetcher = new DepartureFetcher(useTempSite, cacheTimeout); |
logger.info( "DepartureServlet, use azure site=" + useAzureSite + ", cache=" + cacheTimeout); |
49 |
|
fetcher = new DepartureFetcher(useAzureSite, cacheTimeout, replyTimeout); |
50 |
} |
} |
51 |
|
|
52 |
@Override |
@Override |
66 |
int station = Integer.parseInt( req.getParameter("station") ); |
int station = Integer.parseInt( req.getParameter("station") ); |
67 |
String format = req.getParameter("format"); |
String format = req.getParameter("format"); |
68 |
|
|
69 |
DepartureBean beans; |
DepartureBean beans; |
|
|
|
|
String stationName = StationDAO.getStationName(station); |
|
70 |
|
|
71 |
try { |
try { |
72 |
beans = fetcher.cachedLookupDepartures(station, arrival); |
beans = fetcher.cachedLookupDepartures(station, arrival); |
92 |
|
|
93 |
if (format.equalsIgnoreCase("xml")) { |
if (format.equalsIgnoreCase("xml")) { |
94 |
resp.setContentType("text/xml"); |
resp.setContentType("text/xml"); |
95 |
resp.getWriter().print( formatXml(beans, stationName, arrival) ); |
resp.getWriter().print( formatXml(beans, arrival) ); |
96 |
} else if (format.equalsIgnoreCase("html")) { |
} else if (format.equalsIgnoreCase("html")) { |
97 |
|
|
98 |
String advStr = req.getParameter("advanced"); |
String advStr = req.getParameter("advanced"); |
99 |
boolean advanced = advStr != null ? Boolean.parseBoolean(advStr) : false; |
boolean advanced = advStr != null ? Boolean.parseBoolean(advStr) : false; |
100 |
|
|
101 |
req.setAttribute("advanced", advanced); |
req.setAttribute("advanced", advanced); |
|
req.setAttribute("stationname", stationName ); |
|
102 |
req.setAttribute("departurebeans", beans); |
req.setAttribute("departurebeans", beans); |
103 |
req.setAttribute("stationID", station ); |
req.setAttribute("stationID", station ); |
104 |
getServletContext().getRequestDispatcher("/ViewDepartures.jsp").forward(req,resp); |
getServletContext().getRequestDispatcher("/ViewDepartures.jsp").forward(req,resp); |
108 |
|
|
109 |
} |
} |
110 |
|
|
111 |
protected String formatXml(DepartureBean beans, String stationName, boolean arrival) throws ServletException{ |
protected String formatXml(DepartureBean beans, boolean arrival) throws ServletException{ |
112 |
String xml = ""; |
String xml = ""; |
113 |
try { |
try { |
114 |
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); |
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); |
117 |
|
|
118 |
Document doc = impl.createDocument(null,null,null); |
Document doc = impl.createDocument(null,null,null); |
119 |
Element root = doc.createElement("departureinfo"); |
Element root = doc.createElement("departureinfo"); |
120 |
root.setAttribute("station", stationName); |
root.setAttribute("station", beans.getStationName()); |
121 |
root.setAttribute("arrival", Boolean.toString(arrival) ); |
root.setAttribute("arrival", Boolean.toString(arrival) ); |
122 |
|
|
123 |
for (String notif : beans.notifications) { |
for (String notif : beans.notifications) { |