Class StanzaHandler

java.lang.Object
org.jivesoftware.openfire.net.StanzaHandler
Direct Known Subclasses:
ClientStanzaHandler, ComponentStanzaHandler, MultiplexerStanzaHandler, RespondingServerStanzaHandler, ServerStanzaHandler

public abstract class StanzaHandler extends Object
A StanzaHandler is the main responsible for handling incoming stanzas. Some stanzas like startTLS are totally managed by this class. The rest of the stanzas are just forwarded to the router.
Author:
Gaston Dombiak
  • Field Details

    • PROPERTY_OVERWRITE_EMPTY_TO

      public static final SystemProperty<Boolean> PROPERTY_OVERWRITE_EMPTY_TO
    • connection

      protected Connection connection
    • sessionCreated

      protected boolean sessionCreated
    • startedTLS

      protected boolean startedTLS
    • startedSASL

      protected boolean startedSASL
    • saslStatus

      protected SASLAuthentication.Status saslStatus
      SASL status based on the last SASL interaction
    • waitingCompressionACK

      protected boolean waitingCompressionACK
    • session

      protected LocalSession session
      Session associated with the socket reader.
    • router

      protected PacketRouter router
      Router used to route incoming packets to the correct channels.
  • Constructor Details

    • StanzaHandler

      public StanzaHandler(PacketRouter router, Connection connection)
      Creates a dedicated reader for a socket.
      Parameters:
      router - the router for sending packets that were read.
      connection - the connection being read.
  • Method Details

    • setSession

      public void setSession(LocalSession session)
    • process

      public void process(String stanza, XMPPPacketReader reader) throws Exception
      Throws:
      Exception
    • initiateSession

      protected void initiateSession(String stanza, XMPPPacketReader reader) throws Exception
      Throws:
      Exception
    • processStanza

      protected void processStanza(String stanza, XMPPPacketReader reader) throws Exception
      Throws:
      Exception
    • processIQ

      protected void processIQ(org.xmpp.packet.IQ packet) throws UnauthorizedException
      Process the received IQ packet. Registered PacketInterceptor will be invoked before and after the packet was routed.

      Subclasses may redefine this method for different reasons such as modifying the sender of the packet to avoid spoofing, rejecting the packet or even process the packet in another thread.

      Parameters:
      packet - the received packet.
      Throws:
      UnauthorizedException - if service is not available to sender.
    • processPresence

      protected void processPresence(org.xmpp.packet.Presence packet) throws UnauthorizedException
      Process the received Presence packet. Registered PacketInterceptor will be invoked before and after the packet was routed.

      Subclasses may redefine this method for different reasons such as modifying the sender of the packet to avoid spoofing, rejecting the packet or even process the packet in another thread.

      Parameters:
      packet - the received packet.
      Throws:
      UnauthorizedException - if service is not available to sender.
    • processMessage

      protected void processMessage(org.xmpp.packet.Message packet) throws UnauthorizedException
      Process the received Message packet. Registered PacketInterceptor will be invoked before and after the packet was routed.

      Subclasses may redefine this method for different reasons such as modifying the sender of the packet to avoid spoofing, rejecting the packet or even process the packet in another thread.

      Parameters:
      packet - the received packet.
      Throws:
      UnauthorizedException - if service is not available to sender.
    • negotiateTLS

      protected boolean negotiateTLS()
      Tries to encrypt the connection using TLS. If the connection is encrypted then reset the parser to use the new encrypted reader. But if the connection failed to be encrypted then send a stanza and close the connection.
      Returns:
      true if the connection was encrypted.
    • tlsNegotiated

      protected void tlsNegotiated(org.xmlpull.v1.XmlPullParser xpp) throws org.xmlpull.v1.XmlPullParserException, IOException
      TLS negotiation was successful so open a new stream and offer the new stream features. The new stream features will include available SASL mechanisms and specific features depending on the session type such as auth for Non-SASL authentication and register for in-band registration.
      Throws:
      org.xmlpull.v1.XmlPullParserException
      IOException
    • saslSuccessful

      protected void saslSuccessful()
      After SASL authentication was successful we should open a new stream and offer new stream features such as resource binding and session establishment. Notice that resource binding and session establishment should only be offered to clients (i.e. not to servers or external components)
    • compressClient

      protected boolean compressClient(org.dom4j.Element doc)
      Start using compression but first check if the connection can and should use compression. The connection will be closed if the requested method is not supported, if the connection is already using compression or if client requested to use compression but this feature is disabled.
      Parameters:
      doc - the element sent by the client requesting compression. Compression method is included.
      Returns:
      true if it was possible to use compression.
    • compressionSuccessful

      protected void compressionSuccessful()
      After compression was successful we should open a new stream and offer new stream features such as resource binding and session establishment. Notice that resource binding and session establishment should only be offered to clients (i.e. not to servers or external components)
    • isStreamManagementStanza

      protected boolean isStreamManagementStanza(org.dom4j.Element stanza)
      Determines whether stanza's namespace matches XEP-0198 namespace
      Parameters:
      stanza - Stanza to be checked
      Returns:
      whether stanza's namespace matches XEP-0198 namespace
    • getStreamHeader

      protected org.dom4j.Document getStreamHeader()
    • closeNeverEncryptedConnection

      protected void closeNeverEncryptedConnection()
      Close the connection since TLS was mandatory and the entity never negotiated TLS. Before closing the connection a stream error will be sent to the entity.
    • createSession

      protected void createSession(org.xmlpull.v1.XmlPullParser xpp) throws org.xmlpull.v1.XmlPullParserException, IOException
      Uses the XPP to grab the opening stream tag and create an active session object. The session to create will depend on the sent namespace. In all cases, the method obtains the opening stream tag, checks for errors, and either creates a session or returns an error and kills the connection. If the connection remains open, the XPP will be set to be ready for the first packet. A call to next() should result in an START_TAG state with the first packet in the stream.
      Parameters:
      xpp - the pull parser
      Throws:
      org.xmlpull.v1.XmlPullParserException - if an exception occurs reading from the pull parser
      IOException - if an IO exception occurs reading from the pull parser
    • isHostUnknown

      protected boolean isHostUnknown(String host)
    • getAddress

      public org.xmpp.packet.JID getAddress()
      Obtain the address of the XMPP entity for which this StanzaHandler handles stanzas. Note that the value that is returned for this method can change over time. For example, if no session has been established yet, this method will return null, or, if resource binding occurs, the returned value might change. Values obtained from this method are therefore best not cached.
      Returns:
      The address of the XMPP entity for.
    • isStartOfStream

      protected boolean isStartOfStream(String xml)
      Checks if the provided XML data represents the beginning of a new XMPP stream.
      Parameters:
      xml - The XML to verify
      Returns:
      'true' if the provided data represents the beginning of an XMPP stream.
    • isEndOfStream

      protected boolean isEndOfStream(String xml)
      Checks if the provided XML data represents the end / closing of an XMPP stream.
      Parameters:
      xml - The XML to verify
      Returns:
      'true' if the provided data represents the end of an XMPP stream.