/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureServlet.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1303 by torben, Tue Apr 19 11:52:39 2011 UTC revision 1801 by torben, Wed May 9 17:23:50 2012 UTC
# Line 17  import org.simpleframework.xml.Serialize Line 17  import org.simpleframework.xml.Serialize
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;
# Line 63  public class DepartureServlet extends Ht Line 64  public class DepartureServlet extends Ht
64    
65          @Override          @Override
66          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {                    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {          
67                  if (req.getParameter("station") == null) {                  if (req.getParameter("station") == null || req.getParameter("station").equals("") ) {
68                          resp.sendError(400, "not enough parameters (station)");                          resp.sendError(400, "not enough parameters (station)");
69                          return;                          return;
70                  }                  }
71                  if (req.getParameter("format") == null) {                  if (req.getParameter("format") == null || req.getParameter("format").equals("")) {
72                          resp.sendError(400, "not enough parameters (format)");                          resp.sendError(400, "not enough parameters (format)");
73                          return;                                          return;                
74                  }                  }
# Line 89  public class DepartureServlet extends Ht Line 90  public class DepartureServlet extends Ht
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);                          resp.sendError(500, "backend didnt answer");
101                          return;                          return;
102                  } catch (CircuitBreakerException cbe) {                  } catch (CircuitBreakerException cbe) {
103                          logger.warning("Circuitbreaker - failing fast, station=" +station);                          logger.warning("Circuitbreaker - failing fast, station=" +station);
104                          Statistics.getInstance().incrementDepartureErrors();                          Statistics.getInstance().incrementDepartureErrors();
105                          resp.sendError(500);                          beans = generateErrorBean(1);
                         return;  
106                  } catch (StationDAO.NostationException nse) {                  } catch (StationDAO.NostationException nse) {
107                          logger.log(Level.WARNING, "Station not in Database, station=" +station);                          logger.log(Level.WARNING, "Station not in Database, station=" +station);
108                          Statistics.getInstance().incrementDepartureErrors();                          Statistics.getInstance().incrementDepartureErrors();
# Line 134  public class DepartureServlet extends Ht Line 135  public class DepartureServlet extends Ht
135                  } else {                  } else {
136                          resp.sendError(400, "Unknown format");                                            resp.sendError(400, "Unknown format");                  
137                  }                  }
138            }
139            
140            protected DepartureBean generateErrorBean(int code) {
141                    DepartureBean bean = new DepartureBean();
142                    bean.stationName="";
143                    bean.errorCode = code;
144                    return bean;
145          }          }
146    
147          protected String formatXml(DepartureBean beans) throws ServletException{          protected String formatXml(DepartureBean beans) throws ServletException{

Legend:
Removed from v.1303  
changed lines
  Added in v.1801

  ViewVC Help
Powered by ViewVC 1.1.20