On Wed, Mar 7, 2012 at 5:12 AM, Mike Mahoney <[email protected]> wrote: > I've been looking into Vysper-18, 'Recognize and act upon closing stream > tag'. I think I have a fix for it, but I wanted to get some input before > doing a commit. Here is what I'm doing: > > 1. I noticed that XMLParser successfully determines the end of the stream > document on lines 482-484, and notifies its content handler. > > 2. The Parser's content handler, XMPPContentHandler, ignores the > endDocument() call. Instead of just ignoring it, I modified the > XMLElementListener interface to be as follows: > > public interface XMLElementListener { > void element(XMLElement element); > void close(); > boolean isClosed(); > } > > and implemented this updated interface in XMPPDecoder.MinaStanzaListener. I > then gave the MinaStanzaListener a boolean closed field so it could track its > state. > > 3. In XMPPDecoder.doDecode() I modified the end of the method as follows: > > XMPPContentHandler contentHandler = (XMPPContentHandler) > reader.getContentHandler(); > XMLElementListener listener = new MinaStanzaListener(out); > contentHandler.setListener(listener); > > reader.parse(in, CharsetUtil.UTF8_DECODER); // If parsing find the end of > the document, then the listener's close() will be called. > > if (listener.isClosed()) { > session.close(false); > return true; > } else { > // we have parsed what we got, invoke again when more data is available > return false; > } > > The call to session.close() then triggers the sessionClosed() handler in > XmppIoHandlerAdapter, which cleans up the Vysper SessionContext. > > I'm particularly looking for any thoughts on the session closing. I'm not a > Mina expert by any means, so I want to make sure the close in > XMPPDecoder.doDecode() handles everything cleanly. I realize this doesn't > handle the BOSH case, but I can tackle that next.
I find it a bit weird to do session management in the XML decoding code. Instead, could we not send a special marker (similar to SslFilter.SESSION_SECURED) on the end of document. It could then be detected in XmppIoHandlerAdapter where the session close would make more sense I think. Do you think that would work? /niklas
