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

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

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

revision 716 by torben, Mon May 10 06:53:20 2010 UTC revision 717 by torben, Mon May 10 06:59:01 2010 UTC
# Line 37  public class TimetableServlet extends Ht Line 37  public class TimetableServlet extends Ht
37          @Override          @Override
38          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
39                  if (request.getParameter("train") == null) {                  if (request.getParameter("train") == null) {
40                          response.sendError(400, "not enough parameters");                          response.sendError(400, "not enough parameters (train)");
41                            return;
42                    }
43                    if (request.getParameter("type") == null) {
44                            response.sendError(400, "not enough parameters (type)");
45                          return;                          return;
46                  }                  }
47                  Statistics.getInstance().incrementTimetableLookups();                  Statistics.getInstance().incrementTimetableLookups();
48                                    
49                  String train = request.getParameter("train").trim();                  String train = request.getParameter("train").trim();
50                  String trainID;                  String type = request.getParameter("type").trim();
                 String type = request.getParameter("type");  
                   
                 if (type != null) {  
                          trainID = train;  
                 } else { //remove this failover sometime after release of client 0.6.4  
                         String sections[] = train.split(" ");  
                         if (sections.length != 2) {  
                                 response.sendError(400, "Invalid parameter");  
                                 return;  
                         }  
51                                                                    
                         type = lookupType(sections[0]);  
                         trainID = sections[1];  
                 }  
                   
52                  try                  try
53                  {                  {
54                          List<TimetableBean> timetable = fetcher.cachedLookupTimetable(trainID, type);                          List<TimetableBean> timetable = fetcher.cachedLookupTimetable(train, type);
55                                    
56                          String responseXML = formatTimetable(timetable);                          String responseXML = formatTimetable(timetable);
57                                    
58                          response.setContentType("text/xml");                          response.setContentType("text/xml");
59                          response.getWriter().print(responseXML);                          response.getWriter().print(responseXML);
60                  } catch (java.io.IOException ioe) {                  } catch (java.io.IOException ioe) {
61                          logger.warning("(timetable) Read failed, train="+train + ". " + ioe.getMessage());                          logger.warning("(timetable) Read failed, type=" + type + ", train="+train + ". " + ioe.getMessage());
62                          Statistics.getInstance().incrementTimetableErrors();                          Statistics.getInstance().incrementTimetableErrors();
63                          response.sendError(500, "Backend timed out");                          response.sendError(500, "Backend timed out");
64                  } catch (CircuitBreakerException cbe) {                  } catch (CircuitBreakerException cbe) {
# Line 76  public class TimetableServlet extends Ht Line 66  public class TimetableServlet extends Ht
66                          Statistics.getInstance().incrementTimetableErrors();                          Statistics.getInstance().incrementTimetableErrors();
67                          response.sendError(500);                          response.sendError(500);
68                  }catch (Exception e) {                  }catch (Exception e) {
69                          logger.log(Level.WARNING, "failure looking up timetable: train=" +train, e);                          logger.log(Level.WARNING, "failure looking up timetable: type=" + type + ",train=" +train, e);
70                          Statistics.getInstance().incrementTimetableErrors();                          Statistics.getInstance().incrementTimetableErrors();
71                          response.sendError(500);                          response.sendError(500);
72                  }                  }
73                                    
74          }          }
         /*remove /outcomment/deprecate after 0.6.4 release */  
         String lookupType(String trainCode) {  
                 trainCode = trainCode.toLowerCase();  
                   
                 if (trainCode.equals("a") || trainCode.equals("b") || trainCode.equals("bx") || trainCode.equals("c") ||  
                                 trainCode.equals("e") || trainCode.equals("f") || trainCode.equals("h")) {  
                         return "S2";  
                 } else {  
                         return "FJRN";  
                 }  
         }  
75                    
76          String formatTimetable(List<TimetableBean> timetable) {          String formatTimetable(List<TimetableBean> timetable) {
77                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();

Legend:
Removed from v.716  
changed lines
  Added in v.717

  ViewVC Help
Powered by ViewVC 1.1.20