6 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
7 |
|
|
8 |
import javax.servlet.ServletException; |
import javax.servlet.ServletException; |
9 |
|
import javax.servlet.annotation.WebServlet; |
10 |
import javax.servlet.http.HttpServlet; |
import javax.servlet.http.HttpServlet; |
11 |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletRequest; |
12 |
import javax.servlet.http.HttpServletResponse; |
import javax.servlet.http.HttpServletResponse; |
29 |
/** |
/** |
30 |
* Servlet implementation class DepartureServlet |
* Servlet implementation class DepartureServlet |
31 |
*/ |
*/ |
32 |
|
@WebServlet(urlPatterns={"/DepartureServlet"}) |
33 |
public class DepartureServlet extends HttpServlet { |
public class DepartureServlet extends HttpServlet { |
34 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
35 |
|
|
56 |
resp.sendError(400, "not enough parameters"); |
resp.sendError(400, "not enough parameters"); |
57 |
return; |
return; |
58 |
} |
} |
59 |
|
|
60 |
|
boolean arrival = false; |
61 |
|
try { |
62 |
|
arrival = Integer.parseInt( req.getParameter("arrival")) != 0; |
63 |
|
} catch (Exception e) {} |
64 |
|
|
65 |
Statistics.getInstance().incrementDepartureLookups(); |
Statistics.getInstance().incrementDepartureLookups(); |
66 |
|
|
67 |
int station = Integer.parseInt( req.getParameter("station") ); |
int station = Integer.parseInt( req.getParameter("station") ); |
72 |
String stationName = StationDAO.getStationName(station); |
String stationName = StationDAO.getStationName(station); |
73 |
|
|
74 |
try { |
try { |
75 |
beans = fetcher.cachedLookupDepartures(station); |
beans = fetcher.cachedLookupDepartures(station, arrival); |
76 |
} catch (java.io.IOException ioe) { |
} catch (java.io.IOException ioe) { |
77 |
logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); |
logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); |
78 |
|
Statistics.getInstance().incrementDepartureErrors(); |
79 |
resp.sendError(500); |
resp.sendError(500); |
80 |
return; |
return; |
81 |
} catch (CircuitBreakerException cbe) { |
} catch (CircuitBreakerException cbe) { |
82 |
logger.warning("Circuitbreaker - failing fast"); |
logger.warning("Circuitbreaker - failing fast"); |
83 |
|
Statistics.getInstance().incrementDepartureErrors(); |
84 |
resp.sendError(500); |
resp.sendError(500); |
85 |
return; |
return; |
86 |
} catch (Exception e) { |
} catch (Exception e) { |
87 |
logger.log(Level.WARNING, "Unknown exception, station=" +station, e); |
logger.log(Level.WARNING, "Unknown exception, station=" +station, e); |
88 |
|
Statistics.getInstance().incrementDepartureErrors(); |
89 |
resp.sendError(500); |
resp.sendError(500); |
90 |
return; |
return; |
91 |
} |
} |
107 |
req.setAttribute("stationID", station ); |
req.setAttribute("stationID", station ); |
108 |
getServletContext().getRequestDispatcher("/ViewDepartures.jsp").forward(req,resp); |
getServletContext().getRequestDispatcher("/ViewDepartures.jsp").forward(req,resp); |
109 |
} else { |
} else { |
110 |
throw new ServletException("Unknown format"); |
resp.sendError(400, "Unknown format"); |
111 |
} |
} |
112 |
|
|
113 |
} |
} |
173 |
//transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); |
//transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); |
174 |
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); |
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); |
175 |
transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); |
transformer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); |
176 |
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); |
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "1"); |
177 |
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); |
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); |
178 |
java.io.StringWriter sw = new java.io.StringWriter(); |
java.io.StringWriter sw = new java.io.StringWriter(); |
179 |
StreamResult sr = new StreamResult(sw); |
StreamResult sr = new StreamResult(sw); |