1 |
package dk.thoerup.traininfoservice.banedk; |
package dk.thoerup.traininfoservice.banedk; |
2 |
|
|
3 |
|
import java.io.ByteArrayOutputStream; |
4 |
import java.io.IOException; |
import java.io.IOException; |
5 |
import java.util.logging.Level; |
import java.util.logging.Level; |
6 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
11 |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletRequest; |
12 |
import javax.servlet.http.HttpServletResponse; |
import javax.servlet.http.HttpServletResponse; |
13 |
|
|
14 |
|
import org.simpleframework.xml.Serializer; |
15 |
|
import org.simpleframework.xml.core.Persister; |
16 |
|
|
17 |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
import dk.thoerup.circuitbreaker.CircuitBreakerException; |
18 |
import dk.thoerup.traininfoservice.Statistics; |
import dk.thoerup.traininfoservice.Statistics; |
19 |
import dk.thoerup.traininfoservice.banedk.MetroFetcher.MetroBean; |
import dk.thoerup.traininfoservice.banedk.MetroFetcher.MetroBean; |
20 |
import dk.thoerup.traininfoservice.banedk.MetroFetcher.MetroEntry; |
|
21 |
|
|
22 |
|
|
23 |
|
|
52 |
|
|
53 |
resp.setDateHeader("Expires", 0); |
resp.setDateHeader("Expires", 0); |
54 |
resp.setHeader("Cache-Control", "no-cache, must-revalidate"); |
resp.setHeader("Cache-Control", "no-cache, must-revalidate"); |
55 |
|
resp.setContentType("text/xml"); |
56 |
resp.getWriter().print(xml); |
resp.getWriter().print(xml); |
57 |
|
|
58 |
} catch (java.io.IOException ioe) { |
} catch (java.io.IOException ioe) { |
75 |
|
|
76 |
} |
} |
77 |
|
|
78 |
String formatXml(MetroBean metro) { |
String formatXml(MetroBean metro) throws ServletException { |
|
StringBuilder sb = new StringBuilder(); |
|
79 |
|
|
80 |
sb.append("<metrodepatures>\n"); |
Serializer serializer = new Persister(); |
81 |
sb.append(" <head>" + metro.head + "</head>\n"); |
|
82 |
sb.append(" <operations>" + metro.operationInfo + "</operations>\n"); |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
83 |
|
|
84 |
sb.append(" <entries>\n"); |
try { |
85 |
for (MetroEntry entry : metro.entries) { |
serializer.write(metro, out); |
86 |
sb.append(" <entry>\n"); |
} catch (Exception e) { |
87 |
sb.append(" <metro>" + entry.metro + "</metro>\n"); |
throw new ServletException(e); |
|
sb.append(" <destination>" + entry.destination + "</destination>\n"); |
|
|
sb.append(" <minutes>" + entry.minutes + "</minutes>\n"); |
|
|
sb.append(" </entry>\n"); |
|
88 |
} |
} |
|
sb.append(" </entries>\n"); |
|
|
|
|
|
sb.append(" <plan>" + metro.plan + "</plan>\n"); |
|
|
|
|
|
sb.append("</metrodepatures>\n"); |
|
|
|
|
89 |
|
|
90 |
return sb.toString(); |
return out.toString(); |
91 |
} |
} |
92 |
|
|
93 |
} |
} |