01: /******************************************************************************
02: * ResponderUTCSWF.java
03: * ****************************************************************************/package org.openlaszlo.servlets.responders;
04:
05: import java.io.*;
06: import java.util.Properties;
07: import javax.servlet.ServletConfig;
08: import javax.servlet.ServletException;
09: import javax.servlet.ServletOutputStream;
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12: import org.openlaszlo.utils.FileUtils;
13: import org.openlaszlo.utils.SWFUtils;
14: import org.apache.log4j.Logger;
15:
16: /**
17: * Send out a response that current utc in a SWF
18: */
19: public final class ResponderUTCSWF extends ResponderAdmin {
20: private static Logger mLogger = Logger
21: .getLogger(ResponderUTCSWF.class);
22:
23: public void init(String reqName, ServletConfig config,
24: Properties prop) throws ServletException, IOException {
25: super .init(reqName, config, prop);
26: }
27:
28: protected void respondAdmin(HttpServletRequest req,
29: HttpServletResponse res) throws IOException {
30: ServletOutputStream out = res.getOutputStream();
31: InputStream in = null;
32: try {
33: res.setContentType("application/x-shockwave-flash");
34: long utc = System.currentTimeMillis();
35: String s = "" + utc;
36: in = SWFUtils.getErrorMessageSWF(s);
37: res.setContentLength(in.available());
38: FileUtils.sendToStream(in, out);
39: } catch (FileUtils.StreamWritingException e) {
40: mLogger.warn(
41: /* (non-Javadoc)
42: * @i18n.test
43: * @org-mes="StreamWritingException while sending utcswf: " + p[0]
44: */
45: org.openlaszlo.i18n.LaszloMessages.getMessage(
46: ResponderUTCSWF.class.getName(), "051018-54",
47: new Object[] { e.getMessage() }));
48: } finally {
49: FileUtils.close(in);
50: FileUtils.close(out);
51: }
52: }
53:
54: public int getMimeType() {
55: return MIME_TYPE_SWF;
56: }
57: }
|