17 |
import org.simpleframework.xml.core.Persister; |
import org.simpleframework.xml.core.Persister; |
18 |
|
|
19 |
import dk.thoerup.android.traininfo.common.DepartureBean; |
import dk.thoerup.android.traininfo.common.DepartureBean; |
20 |
|
import dk.thoerup.android.traininfo.common.StationBean; |
21 |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
22 |
import dk.thoerup.traininfoservice.Statistics; |
import dk.thoerup.traininfoservice.Statistics; |
23 |
import dk.thoerup.traininfoservice.TraininfoSettings; |
import dk.thoerup.traininfoservice.TraininfoSettings; |
90 |
type = FetchTrainType.valueOf( req.getParameter("type") ); |
type = FetchTrainType.valueOf( req.getParameter("type") ); |
91 |
} |
} |
92 |
|
|
93 |
|
|
94 |
try { |
try { |
95 |
beans = fetcher.cachedLookupDepartures(station, arrival, type); |
beans = fetcher.cachedLookupDepartures(station, arrival, type); |
96 |
beans.arrival = arrival; |
beans.arrival = arrival; |
97 |
} catch (java.io.IOException ioe) { |
} catch (java.io.IOException ioe) { |
98 |
logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); |
logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); |
99 |
Statistics.getInstance().incrementDepartureErrors(); |
Statistics.getInstance().incrementDepartureErrors(); |
100 |
resp.sendError(500); |
beans = generateErrorBean(1); |
|
return; |
|
101 |
} catch (CircuitBreakerException cbe) { |
} catch (CircuitBreakerException cbe) { |
102 |
logger.warning("Circuitbreaker - failing fast, station=" +station); |
logger.warning("Circuitbreaker - failing fast, station=" +station); |
103 |
Statistics.getInstance().incrementDepartureErrors(); |
Statistics.getInstance().incrementDepartureErrors(); |
104 |
resp.sendError(500); |
beans = generateErrorBean(1); |
|
return; |
|
105 |
} catch (StationDAO.NostationException nse) { |
} catch (StationDAO.NostationException nse) { |
106 |
logger.log(Level.WARNING, "Station not in Database, station=" +station); |
logger.log(Level.WARNING, "Station not in Database, station=" +station); |
107 |
Statistics.getInstance().incrementDepartureErrors(); |
Statistics.getInstance().incrementDepartureErrors(); |
134 |
} else { |
} else { |
135 |
resp.sendError(400, "Unknown format"); |
resp.sendError(400, "Unknown format"); |
136 |
} |
} |
137 |
|
} |
138 |
|
|
139 |
|
protected DepartureBean generateErrorBean(int code) { |
140 |
|
DepartureBean bean = new DepartureBean(); |
141 |
|
bean.stationName=""; |
142 |
|
bean.errorCode = code; |
143 |
|
return bean; |
144 |
} |
} |
145 |
|
|
146 |
protected String formatXml(DepartureBean beans) throws ServletException{ |
protected String formatXml(DepartureBean beans) throws ServletException{ |