01: /******************************************************************************
02: * ResponderCONNECTIONLOGOUT.java
03: * ****************************************************************************/package org.openlaszlo.servlets.responders;
04:
05: import java.io.*;
06: import java.util.*;
07: import javax.servlet.*;
08: import javax.servlet.http.*;
09: import org.openlaszlo.auth.*;
10: import org.openlaszlo.connection.*;
11: import org.openlaszlo.media.*;
12: import org.openlaszlo.utils.*;
13: import org.openlaszlo.xml.internal.*;
14: import org.apache.log4j.*;
15:
16: public final class ResponderCONNECTIONLOGOUT extends
17: ResponderConnection {
18: private static Logger mLogger = Logger
19: .getLogger(ResponderCONNECTIONLOGOUT.class);
20:
21: protected void respondImpl(HttpServletRequest req,
22: HttpServletResponse res, Application app, int serial,
23: String username) throws IOException {
24: Authentication auth = app.getAuthenticator();
25:
26: String xml;
27: String status = "error";
28: StringBuffer buf = new StringBuffer();
29: try {
30: int code = auth.logout(req, res, getAuthParam(req), buf);
31: status = (code == 0 ? "success" : "failure");
32: String xmlResponse = buf.toString();
33: int i = xmlResponse.indexOf("<authentication>");
34: if (i != -1) {
35: xmlResponse = xmlResponse.substring(i);
36:
37: xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
38: + "<!DOCTYPE laszlo-data>" + "<resultset s=\""
39: + serial + "\">" + "<logout status=\"" + status
40: + "\">" + xmlResponse + "</logout></resultset>";
41:
42: } else {
43: xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
44: + "<!DOCTYPE laszlo-data>"
45: + "<resultset s=\""
46: + serial
47: + "\">"
48: + "<logout status=\"error\">"
49: + "<error message=\"could not find <authentication> element\" />"
50: + "</logout></resultset>";
51: mLogger
52: .warn("could not find <authentication> element: "
53: + xmlResponse);
54: }
55: } catch (AuthenticationException e) {
56: xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
57: + "<!DOCTYPE laszlo-data>" + "<resultset s=\""
58: + serial + "\">" + "<logout status=\"error\">"
59: + "<error message=\"authentication exception\" />"
60: + "</logout></resultset>";
61: mLogger.warn(
62: /* (non-Javadoc)
63: * @i18n.test
64: * @org-mes="AuthenticationException"
65: */
66: org.openlaszlo.i18n.LaszloMessages.getMessage(
67: ResponderCONNECTIONLOGOUT.class.getName(),
68: "051018-73"), e);
69: }
70:
71: res.setContentType(MimeType.SWF);
72:
73: ServletOutputStream sos = res.getOutputStream();
74: try {
75: InputStream swfbytes = DataCompiler.compile(xml,
76: mSWFVersionNum);
77: FileUtils.sendToStream(swfbytes, sos);
78: sos.flush();
79: } catch (FileUtils.StreamWritingException e) {
80: mLogger.warn(
81: /* (non-Javadoc)
82: * @i18n.test
83: * @org-mes="StreamWritingException while sending connection logout response: " + p[0]
84: */
85: org.openlaszlo.i18n.LaszloMessages.getMessage(
86: ResponderCONNECTIONLOGOUT.class.getName(),
87: "051018-91", new Object[] { e.getMessage() }));
88: } catch (DataCompilerException e) {
89: respondWithExceptionSWF(res, e);
90: return;
91: } finally {
92: FileUtils.close(sos);
93: }
94: }
95: }
|