XMPP / XML Frame Decoder

Nicholas Hagen nicholas.hagen at znetdevelopment.com
Wed Mar 24 22:18:27 EDT 2010


That is what my parser does.  Essentially, I expect the first byte (using purely byte[]) to be either whitespace or a open bracket (<).  I then read until I find a matching close bracket maintaining a counter of other open nodes and decrementing with each close node until I finally read the matching close bracket.  The result is a single complete stanza message.  As noted, you would need to have a max configurable buffer size in which the entire packet is thrown away when too much data is read and a close bracket not found.  This works really nice using the mark and reset methods in Netty so that you are not affected by fragmentation.  Once a message is finally processed and sent up the stack, it starts over again expecting whitespace or an open node.  I really think it needs to parse one stanza at a time though.  Handlers higher in the stack can handle batching multiple stanzas.  Similarly, you can have other intermediary handlers to do XML parsing such as DOM, SAX, JAXB, etc.  Those handlers would be completely transparent to XMPP and is purely used to convert a String to an XML representation that is passed to business handlers that process the XML.

Nick

=================================
Nicholas Hagen
Z|NET Development, LLC
www.znetdevelopment.com
=================================
Now Available:  Push RSS
RSS Viewer for iPhone OS 3
www.znetdevelopment.com/znet/iphone.html
=================================

On Mar 24, 2010, at 9:23 PM, ram_m wrote:

> 
> In general for xml parsing, there has to be a minimum amount of data that
> needs to be read, for any meaning full parsing, For XMPP an individual
> stanza would mostly be the minimum to take some action. Ofcourse, the basic
> assumption or implementation choice has to be made with regarding to the
> size of the stanza for the server to protect itself.
> 
> I am thinking at a minimum for an XML based protocol is to read one full
> opening node into a buffer and handover it to the next layer, so it would
> mostly act as a SAX parser.
> 
> -- 
> View this message in context: http://n2.nabble.com/XMPP-XML-Frame-Decoder-tp4717020p4795077.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users




More information about the netty-users mailing list