/[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 1091 by torben, Tue Sep 21 15:46:02 2010 UTC revision 1190 by torben, Fri Nov 12 18:33:38 2010 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfoservice.banedk;  package dk.thoerup.traininfoservice.banedk;
2    
3  import java.io.ByteArrayInputStream;  import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;  
4  import java.io.File;  import java.io.File;
5  import java.io.IOException;  import java.io.IOException;
6    import java.io.StringWriter;
7  import java.util.logging.Level;  import java.util.logging.Level;
8  import java.util.logging.Logger;  import java.util.logging.Logger;
9    
# Line 25  import org.simpleframework.xml.core.Pers Line 25  import org.simpleframework.xml.core.Pers
25    
26  import dk.thoerup.android.traininfo.common.DepartureBean;  import dk.thoerup.android.traininfo.common.DepartureBean;
27  import dk.thoerup.circuitbreaker.CircuitBreakerException;  import dk.thoerup.circuitbreaker.CircuitBreakerException;
28    import dk.thoerup.traininfoservice.StationDAO;
29  import dk.thoerup.traininfoservice.Statistics;  import dk.thoerup.traininfoservice.Statistics;
30    
31  /**  /**
# Line 69  public class DepartureServlet extends Ht Line 70  public class DepartureServlet extends Ht
70          @Override          @Override
71          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {                    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {          
72                  if (req.getParameter("station") == null) {                  if (req.getParameter("station") == null) {
73                          resp.sendError(400, "not enough parameters");                          resp.sendError(400, "not enough parameters (station)");
74                          return;                          return;
75                  }                  }
76                    if (req.getParameter("format") == null) {
77                            resp.sendError(400, "not enough parameters (format)");
78                            return;                
79                    }
80                                    
81                  boolean arrival = false;                  boolean arrival = false;
82                  try {                  try {
# Line 94  public class DepartureServlet extends Ht Line 99  public class DepartureServlet extends Ht
99                          resp.sendError(500);                          resp.sendError(500);
100                          return;                          return;
101                  } catch (CircuitBreakerException cbe) {                  } catch (CircuitBreakerException cbe) {
102                          logger.warning("Circuitbreaker - failing fast");                          logger.warning("Circuitbreaker - failing fast, station=" +station);
103                          Statistics.getInstance().incrementDepartureErrors();                          Statistics.getInstance().incrementDepartureErrors();
104                          resp.sendError(500);                          resp.sendError(500);
105                          return;                          return;
106                    } catch (StationDAO.NostationException nse) {
107                            logger.log(Level.WARNING, "Station not in Database, station=" +station);
108                            Statistics.getInstance().incrementDepartureErrors();
109                            resp.sendError(400, "invalid station ID");
110                            return;                
111                  } catch (Exception e) {                                  } catch (Exception e) {                
112                          logger.log(Level.WARNING, "Unknown exception, station=" +station, e);                          logger.log(Level.WARNING, "Unknown exception, station=" +station, e);
113                          Statistics.getInstance().incrementDepartureErrors();                          Statistics.getInstance().incrementDepartureErrors();
# Line 132  public class DepartureServlet extends Ht Line 142  public class DepartureServlet extends Ht
142                                    
143                  Serializer serializer = new Persister();                  Serializer serializer = new Persister();
144    
145                  ByteArrayOutputStream out = new ByteArrayOutputStream();                  StringWriter out = new StringWriter();
146    
147                  try {                  try {
148                          serializer.write(beans, out);                          serializer.write(beans, out);
# Line 149  public class DepartureServlet extends Ht Line 159  public class DepartureServlet extends Ht
159                          Transformer trans = xslTemplate.newTransformer();                                                Transformer trans = xslTemplate.newTransformer();                      
160                                    
161                          Source xml = new StreamSource( new ByteArrayInputStream(input.getBytes() ));                          Source xml = new StreamSource( new ByteArrayInputStream(input.getBytes() ));
162                          ByteArrayOutputStream out = new ByteArrayOutputStream();                          StringWriter out = new StringWriter();
163                          trans.transform(xml, new StreamResult(out));                                      trans.transform(xml, new StreamResult(out));            
164                                    
165                          return out.toString();                          return out.toString();

Legend:
Removed from v.1091  
changed lines
  Added in v.1190

  ViewVC Help
Powered by ViewVC 1.1.20