KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > servlets > responders > ResponderUTCSWF


1 /******************************************************************************
2  * ResponderUTCSWF.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.servlets.responders;
11
12 import java.io.*;
13 import java.util.Properties JavaDoc;
14 import javax.servlet.ServletConfig JavaDoc;
15 import javax.servlet.ServletException JavaDoc;
16 import javax.servlet.ServletOutputStream JavaDoc;
17 import javax.servlet.http.HttpServletRequest JavaDoc;
18 import javax.servlet.http.HttpServletResponse JavaDoc;
19 import org.openlaszlo.utils.FileUtils;
20 import org.openlaszlo.utils.SWFUtils;
21 import org.apache.log4j.Logger;
22
23 /**
24  * Send out a response that current utc in a SWF
25  */

26 public final class ResponderUTCSWF extends ResponderAdmin
27 {
28     private static Logger mLogger = Logger.getLogger(ResponderUTCSWF.class);
29
30     public void init(String JavaDoc reqName, ServletConfig JavaDoc config, Properties JavaDoc prop)
31         throws ServletException JavaDoc, IOException
32     {
33         super.init(reqName, config, prop);
34     }
35
36     protected void respondAdmin(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
37         throws IOException
38     {
39         ServletOutputStream JavaDoc out = res.getOutputStream();
40         InputStream in = null;
41         try {
42             res.setContentType ("application/x-shockwave-flash");
43             long utc = System.currentTimeMillis();
44             String JavaDoc s = "" + utc;
45             in = SWFUtils.getErrorMessageSWF(s);
46             res.setContentLength(in.available());
47             FileUtils.sendToStream(in, out);
48         } catch (FileUtils.StreamWritingException e) {
49             mLogger.warn("StreamWritingException while sending utcswf: " + e.getMessage());
50         } finally {
51             FileUtils.close(in);
52             FileUtils.close(out);
53         }
54     }
55
56     public int getMimeType()
57     {
58         return MIME_TYPE_SWF;
59     }
60 }
61
Popular Tags