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