001: /******************************************************************************
002: * ResponderCONNECTIONLOGIN.java
003: * ****************************************************************************/package org.openlaszlo.servlets.responders;
004:
005: import java.io.*;
006: import java.util.*;
007: import javax.servlet.*;
008: import javax.servlet.http.*;
009: import org.openlaszlo.auth.*;
010: import org.openlaszlo.connection.*;
011: import org.openlaszlo.media.*;
012: import org.openlaszlo.utils.*;
013: import org.openlaszlo.xml.internal.*;
014: import org.apache.log4j.*;
015:
016: public final class ResponderCONNECTIONLOGIN extends ResponderConnection {
017: private static Logger mLogger = Logger
018: .getLogger(ResponderCONNECTIONLOGIN.class);
019:
020: protected void respondImpl(HttpServletRequest req,
021: HttpServletResponse res, Application app, int serial,
022: String username) throws IOException {
023: Authentication auth = app.getAuthenticator();
024:
025: String xml;
026: String status = "error";
027: StringBuffer buf = new StringBuffer();
028: try {
029: int code = auth.login(req, res, getAuthParam(req), buf);
030: status = (code == 0 ? "success" : "failure");
031: String xmlResponse = buf.toString();
032: int i = xmlResponse.indexOf("<authentication>");
033: if (i != -1) {
034: xmlResponse = xmlResponse.substring(i);
035:
036: xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
037: + "<!DOCTYPE laszlo-data>" + "<resultset s=\""
038: + serial + "\">" + "<login status=\"" + status
039: + "\">" + xmlResponse + "</login></resultset>";
040:
041: } else {
042: xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
043: + "<!DOCTYPE laszlo-data>"
044: + "<resultset s=\""
045: + serial
046: + "\">"
047: + "<login status=\"error\">"
048: + "<error message=\"could not find <authentication> element\" />"
049: + "</login></resultset>";
050: mLogger.warn(
051: /* (non-Javadoc)
052: * @i18n.test
053: * @org-mes="could not find <authentication> element: " + p[0]
054: */
055: org.openlaszlo.i18n.LaszloMessages.getMessage(
056: ResponderCONNECTIONLOGIN.class.getName(),
057: "051018-64", new Object[] { xmlResponse }));
058: }
059: } catch (AuthenticationException e) {
060: xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
061: + "<!DOCTYPE laszlo-data>" + "<resultset s=\""
062: + serial + "\">" + "<login status=\"error\">"
063: + "<error message=\"authentication exception\" />"
064: + "</login></resultset>";
065: mLogger.warn(
066: /* (non-Javadoc)
067: * @i18n.test
068: * @org-mes="AuthenticationException"
069: */
070: org.openlaszlo.i18n.LaszloMessages.getMessage(
071: ResponderCONNECTIONLOGIN.class.getName(),
072: "051018-80"), e);
073: }
074:
075: res.setContentType(MimeType.SWF);
076:
077: ServletOutputStream sos = res.getOutputStream();
078: try {
079: InputStream swfbytes = DataCompiler.compile(xml,
080: mSWFVersionNum);
081: FileUtils.sendToStream(swfbytes, sos);
082: sos.flush();
083: } catch (FileUtils.StreamWritingException e) {
084: mLogger.warn(
085: /* (non-Javadoc)
086: * @i18n.test
087: * @org-mes="StreamWritingException while sending connection login response: "
088: */
089: org.openlaszlo.i18n.LaszloMessages.getMessage(
090: ResponderCONNECTIONLOGIN.class.getName(),
091: "051018-98")
092: + e.getMessage());
093: } catch (DataCompilerException e) {
094: respondWithExceptionSWF(res, e);
095: return;
096: } finally {
097: FileUtils.close(sos);
098: }
099: }
100: }
|