Class BodyParserSAX

java.lang.Object
org.igniterealtime.jbosh.BodyParserSAX
All Implemented Interfaces:
BodyParser

final class BodyParserSAX extends Object implements BodyParser
Implementation of the BodyParser interface which uses the SAX API that is part of the JDK. Due to the fact that we can cache and reuse SAXPArser instances, this has proven to be significantly faster than the use of the javax.xml.stream API introduced in Java 6 while simultaneously providing an implementation accessible to Java 5 users.
  • Field Details

    • LOG

      private static final Logger LOG
      Logger.
    • SAX_FACTORY

      private static final SAXParserFactory SAX_FACTORY
      SAX parser factory.
    • PARSER

      private static final ThreadLocal<SoftReference<SAXParser>> PARSER
      Thread local to contain a SAX parser instance for each thread that attempts to use one. This allows us to gain an order of magnitude of performance as a result of not constructing parsers for each invocation while retaining thread safety.
  • Constructor Details

    • BodyParserSAX

      BodyParserSAX()
  • Method Details

    • parse

      public BodyParserResults parse(String xml) throws BOSHException
      Parses the XML message, extracting the useful data from the initial body element and returning it in a results object.
      Specified by:
      parse in interface BodyParser
      Parameters:
      xml - XML to parse
      Returns:
      useful data parsed out of the XML
      Throws:
      BOSHException - on parse error
    • getSAXParser

      private static SAXParser getSAXParser()
      Gets a SAXParser for use in parsing incoming messages.
      Returns:
      parser instance