1 |
package dk.thoerup.traininfoservice.banedk; |
package dk.thoerup.traininfoservice.banedk; |
2 |
|
|
|
import java.io.File; |
|
3 |
import java.io.IOException; |
import java.io.IOException; |
|
import java.io.StringReader; |
|
4 |
import java.io.StringWriter; |
import java.io.StringWriter; |
5 |
import java.util.logging.Level; |
import java.util.logging.Level; |
6 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
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; |
|
import javax.xml.transform.Source; |
|
13 |
import javax.xml.transform.Templates; |
import javax.xml.transform.Templates; |
|
import javax.xml.transform.Transformer; |
|
14 |
import javax.xml.transform.TransformerFactory; |
import javax.xml.transform.TransformerFactory; |
|
import javax.xml.transform.stream.StreamResult; |
|
|
import javax.xml.transform.stream.StreamSource; |
|
15 |
|
|
16 |
import org.simpleframework.xml.Serializer; |
import org.simpleframework.xml.Serializer; |
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.circuitbreaker.CircuitBreakerException; |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
|
import dk.thoerup.traininfoservice.StationDAO; |
|
21 |
import dk.thoerup.traininfoservice.Statistics; |
import dk.thoerup.traininfoservice.Statistics; |
22 |
|
import dk.thoerup.traininfoservice.TraininfoSettings; |
23 |
|
import dk.thoerup.traininfoservice.banedk.DepartureFetcher.FetchTrainType; |
24 |
|
import dk.thoerup.traininfoservice.db.StationDAO; |
25 |
|
|
26 |
/** |
/** |
27 |
* Servlet implementation class DepartureServlet |
* Servlet implementation class DepartureServlet |
44 |
public void init() throws ServletException { |
public void init() throws ServletException { |
45 |
super.init(); |
super.init(); |
46 |
|
|
47 |
boolean useAzureSite = Boolean.parseBoolean( getServletContext().getInitParameter("useazuresite") ); |
|
48 |
int cacheTimeout = Integer.parseInt( getServletContext().getInitParameter("cache_timeout") ); |
TraininfoSettings settings = (TraininfoSettings) getServletContext().getAttribute("settings"); |
49 |
int replyTimeout = Integer.parseInt( getServletContext().getInitParameter("reply_timeout") ); |
fetcher = new DepartureFetcher(settings); |
|
logger.info( "DepartureServlet, use azure site=" + useAzureSite + ", cache=" + cacheTimeout); |
|
|
fetcher = new DepartureFetcher(useAzureSite, cacheTimeout, replyTimeout); |
|
50 |
|
|
51 |
|
/* |
52 |
xslTransFact = TransformerFactory.newInstance(); |
xslTransFact = TransformerFactory.newInstance(); |
53 |
|
|
54 |
String xslPath = getServletContext().getRealPath("/departures.xsl"); |
String xslPath = getServletContext().getRealPath("/departures.xsl"); |
58 |
xslTemplate = xslTransFact.newTemplates(stylesheet); |
xslTemplate = xslTransFact.newTemplates(stylesheet); |
59 |
} catch (Exception e) { |
} catch (Exception e) { |
60 |
throw new ServletException(e); |
throw new ServletException(e); |
61 |
} |
}*/ |
62 |
} |
} |
63 |
|
|
64 |
@Override |
@Override |
82 |
int station = Integer.parseInt( req.getParameter("station") ); |
int station = Integer.parseInt( req.getParameter("station") ); |
83 |
String format = req.getParameter("format"); |
String format = req.getParameter("format"); |
84 |
|
|
85 |
DepartureBean beans; |
DepartureBean beans; |
86 |
|
|
87 |
|
DepartureFetcher.FetchTrainType type = FetchTrainType.BOTH; |
88 |
|
if ( req.getParameter("type") != null) { |
89 |
|
type = FetchTrainType.valueOf( req.getParameter("type") ); |
90 |
|
} |
91 |
|
|
92 |
try { |
try { |
93 |
beans = fetcher.cachedLookupDepartures(station, arrival); |
beans = fetcher.cachedLookupDepartures(station, arrival, type); |
94 |
beans.arrival = arrival; |
beans.arrival = arrival; |
95 |
} catch (java.io.IOException ioe) { |
} catch (java.io.IOException ioe) { |
96 |
logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); |
logger.warning("Read failed, station="+station + ". " + ioe.getMessage() ); |
151 |
|
|
152 |
return out.toString(); |
return out.toString(); |
153 |
} |
} |
154 |
|
/* |
155 |
protected String xmlToHtml(String input) throws ServletException { |
protected String xmlToHtml(String input) throws ServletException { |
156 |
|
|
157 |
try { |
try { |
166 |
} catch (Exception e) { |
} catch (Exception e) { |
167 |
throw new ServletException(e); |
throw new ServletException(e); |
168 |
} |
} |
169 |
} |
}*/ |
170 |
|
|
171 |
} |
} |