1 |
package dk.thoerup.traininfoservice;
|
2 |
|
3 |
import java.io.IOException;
|
4 |
|
5 |
import javax.servlet.ServletException;
|
6 |
import javax.servlet.http.HttpServlet;
|
7 |
import javax.servlet.http.HttpServletRequest;
|
8 |
import javax.servlet.http.HttpServletResponse;
|
9 |
|
10 |
import org.simpleframework.xml.Serializer;
|
11 |
import org.simpleframework.xml.core.Persister;
|
12 |
|
13 |
import dk.thoerup.android.traininfo.common.StationBean;
|
14 |
|
15 |
|
16 |
//@WebServlet(urlPatterns={"/LoadStations"})
|
17 |
|
18 |
public class LoadStations extends HttpServlet {
|
19 |
private static final long serialVersionUID = 1L;
|
20 |
|
21 |
public LoadStations() {
|
22 |
super();
|
23 |
}
|
24 |
|
25 |
|
26 |
@Override
|
27 |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
28 |
String url = "http://app.t-hoerup.dk/TrainInfoService/LocateStations?dump";
|
29 |
|
30 |
String xml = DownloadUtil.getContentString(url, 5000, "ISO-8859-1");
|
31 |
|
32 |
Serializer serializer = new Persister();
|
33 |
StationBean stations;
|
34 |
try {
|
35 |
stations = serializer.read(StationBean.class, xml);
|
36 |
} catch (Exception e) {
|
37 |
throw new ServletException(e);
|
38 |
}
|
39 |
|
40 |
StationDAO stationdao = new StationDAO();
|
41 |
int count = stationdao.saveStations(stations);
|
42 |
|
43 |
resp.getWriter().print("Saved " + count + " entries");
|
44 |
|
45 |
}
|
46 |
|
47 |
}
|