Class SocketConnection
- java.lang.Object
-
- org.jivesoftware.openfire.net.SocketConnection
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Connection
public class SocketConnection extends Object implements Connection
Deprecated.Old, pre NIO / MINA code. Should not be used as NIO offers better performance. Currently only in use for s2s.An object to track the state of a XMPP client-server session. Currently this class contains the socket channel connecting the client and server.- Author:
- Iain Shigeoka
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.Connection
Connection.ClientAuth, Connection.CompressionPolicy, Connection.State, Connection.TLSPolicy
-
-
Constructor Summary
Constructors Constructor Description SocketConnection(PacketDeliverer backupDeliverer, Socket socket, boolean isSecure)Deprecated.Create a new session using the supplied socket.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCompression()Deprecated.Adds the compression filter to the connection but only filter incoming traffic.voidclose()Deprecated.Closes the connection after trying to send a stream end tag.voiddeliver(org.xmpp.packet.Packet packet)Deprecated.Delivers the packet to this connection without checking the recipient.voiddeliverRawText(String text)Deprecated.Delivers raw text to this connection.voidforceClose()Deprecated.Closes the connection without sending any data (not even a stream end-tag).byte[]getAddress()Deprecated.Returns the raw IP address of thisInetAddressobject.Connection.CompressionPolicygetCompressionPolicy()Deprecated.Returns whether compression is optional or is disabled.ConnectionConfigurationgetConfiguration()Deprecated.Returns a representation of the desired state for this connection.StringgetHostAddress()Deprecated.Returns the IP address string in textual presentation.StringgetHostName()Deprecated.Gets the host name for this IP address.longgetIdleTimeout()Deprecated.static Collection<SocketConnection>getInstances()Deprecated.Certificate[]getLocalCertificates()Deprecated.Returns the local underlyingX509Certificatechain for the connection.intgetMajorXMPPVersion()Deprecated.Returns the major version of XMPP being used by this connection (major_version.minor_version.intgetMinorXMPPVersion()Deprecated.Returns the minor version of XMPP being used by this connection (major_version.minor_version.PacketDeliverergetPacketDeliverer()Deprecated.Returns the packet deliverer to use when delivering a packet over the socket fails.Certificate[]getPeerCertificates()Deprecated.Returns the underlyingX509Certificatefor the connection of the peer.intgetPort()Deprecated.Returns the port that the connection uses.Connection.TLSPolicygetTlsPolicy()Deprecated.Returns whether TLS is mandatory, optional or is disabled.TLSStreamHandlergetTLSStreamHandler()Deprecated.Returns the stream handler responsible for securing the plain connection and providing the corresponding input and output streams.WritergetWriter()Deprecated.Returns the Writer used to send data to the connection.voidinit(LocalSession owner)Deprecated.Initializes the connection with it's owning session.booleanisClosed()Deprecated.Returns true if the connection/session is closed.booleanisCompressed()Deprecated.Returns true if the connection is using compression.booleanisFlashClient()Deprecated.Returns true if the connected client is a flash client.booleanisSecure()Deprecated.Returns true if this connection is secure.booleanisUsingSelfSignedCertificate()Deprecated.Returns true if the other peer of this session presented a self-signed certificate.voidregisterCloseListener(ConnectionCloseListener listener, Object handbackMessage)Deprecated.Registers a listener for close event notification.voidreinit(LocalSession owner)Deprecated.Reinitializes the connection to switch to a different session.voidremoveCloseListener(ConnectionCloseListener listener)Deprecated.Removes a registered close event listener.voidsetCompressionPolicy(Connection.CompressionPolicy compressionPolicy)Deprecated.Sets whether compression is enabled or is disabled.voidsetFlashClient(boolean flashClient)Deprecated.Sets whether the connected client is a flash client.voidsetIdleTimeout(long timeout)Deprecated.Sets the number of milliseconds a connection has to be idle to be closed.voidsetSocketReader(SocketReader socketReader)Deprecated.voidsetTlsPolicy(Connection.TLSPolicy tlsPolicy)Deprecated.Sets whether TLS is mandatory, optional or is disabled.voidsetUsingSelfSignedCertificate(boolean isSelfSigned)Deprecated.Keeps track if the other peer of this session presented a self-signed certificate.voidsetXMPPVersion(int majorVersion, int minorVersion)Deprecated.Sets the XMPP version information.voidstartCompression()Deprecated.Start compressing outgoing traffic for this connection.voidstartTLS(boolean clientMode, boolean directTLS)Deprecated.Secures the plain connection by negotiating TLS with the other peer.voidsystemShutdown()Deprecated.Notification message indicating that the server is being shutdown.StringtoString()Deprecated.booleanvalidate()Deprecated.Verifies that the connection is still live.
-
-
-
Constructor Detail
-
SocketConnection
public SocketConnection(PacketDeliverer backupDeliverer, Socket socket, boolean isSecure) throws IOException
Deprecated.Create a new session using the supplied socket.- Parameters:
backupDeliverer- the packet deliverer this connection will use when socket is closed.socket- the socket to represent.isSecure- true if this is a secure connection.- Throws:
IOException- if there was a socket error while sending the packet.
-
-
Method Detail
-
getInstances
public static Collection<SocketConnection> getInstances()
Deprecated.
-
getTLSStreamHandler
public TLSStreamHandler getTLSStreamHandler()
Deprecated.Returns the stream handler responsible for securing the plain connection and providing the corresponding input and output streams.- Returns:
- the stream handler responsible for securing the plain connection and providing the corresponding input and output streams.
-
startTLS
public void startTLS(boolean clientMode, boolean directTLS) throws IOExceptionDeprecated.Description copied from interface:ConnectionSecures the plain connection by negotiating TLS with the other peer. In a server-2-server connection the server requesting the TLS negotiation will be the client and the other server will be the server during the TLS negotiation. Therefore, the server requesting the TLS negotiation must passtruein theclientModeparameter and the server receiving the TLS request must passfalsein theclientModeparameter.In the case of client-2-server the XMPP server must pass
falsein theclientModeparameter since it will behave as the server in the TLS negotiation.- Specified by:
startTLSin interfaceConnection- Parameters:
clientMode- boolean indicating if this entity is a client or a server in the TLS negotiation.directTLS- boolean indicating if the negotiation is directTLS (true) or startTLS (false).- Throws:
IOException
-
addCompression
public void addCompression()
Deprecated.Description copied from interface:ConnectionAdds the compression filter to the connection but only filter incoming traffic. Do not filter outgoing traffic since we still need to send an uncompressed stanza to the client indicating that he can start compressing the traffic. After we sent the uncompresses stanza we can start compression outgoing traffic as well.- Specified by:
addCompressionin interfaceConnection
-
startCompression
public void startCompression()
Deprecated.Description copied from interface:ConnectionStart compressing outgoing traffic for this connection. Compression will only be available after TLS has been negotiated. This means that a connection can never be using compression before TLS. However, it is possible to use compression without TLS.- Specified by:
startCompressionin interfaceConnection
-
getConfiguration
public ConnectionConfiguration getConfiguration()
Deprecated.Description copied from interface:ConnectionReturns a representation of the desired state for this connection. Note that this is different from the current state of the connection. For example, TLS can be required by configuration, but while the connection has yet to be fully initialized, the current state might not be TLS-encrypted.- Specified by:
getConfigurationin interfaceConnection- Returns:
- The desired configuration for the connection (never null).
-
validate
public boolean validate()
Deprecated.Description copied from interface:ConnectionVerifies that the connection is still live. Typically this is done by sending a whitespace character between packets.- Specified by:
validatein interfaceConnection- Returns:
- true if the socket remains valid, false otherwise.
-
init
public void init(LocalSession owner)
Deprecated.Description copied from interface:ConnectionInitializes the connection with it's owning session. Allows the connection class to configure itself with session related information (e.g. stream ID).- Specified by:
initin interfaceConnection- Parameters:
owner- the session that owns this connection
-
reinit
public void reinit(LocalSession owner)
Deprecated.Description copied from interface:ConnectionReinitializes the connection to switch to a different session. This allows for XEP-0198 resumption and transport-switching.- Specified by:
reinitin interfaceConnection- Parameters:
owner- The new session now owning the connection.
-
registerCloseListener
public void registerCloseListener(ConnectionCloseListener listener, Object handbackMessage)
Deprecated.Description copied from interface:ConnectionRegisters a listener for close event notification. Registrations after the Session is closed will be immediately notified before the registration call returns (within the context of the registration call). An optional handback object can be associated with the registration if the same listener is registered to listen for multiple connection closures.- Specified by:
registerCloseListenerin interfaceConnection- Parameters:
listener- the listener to register for events.handbackMessage- the object to send in the event notification.
-
removeCloseListener
public void removeCloseListener(ConnectionCloseListener listener)
Deprecated.Description copied from interface:ConnectionRemoves a registered close event listener. Registered listeners must be able to receive close events up until the time this method returns. (i.e. it is possible to call unregister, receive a close event registration, and then have the unregister call return.)- Specified by:
removeCloseListenerin interfaceConnection- Parameters:
listener- the listener to deregister for close events.
-
getAddress
public byte[] getAddress() throws UnknownHostExceptionDeprecated.Description copied from interface:ConnectionReturns the raw IP address of thisInetAddressobject. The result is in network byte order: the highest order byte of the address is ingetAddress()[0].- Specified by:
getAddressin interfaceConnection- Returns:
- the raw IP address of this object.
- Throws:
UnknownHostException- if IP address of host could not be determined.
-
getHostAddress
public String getHostAddress() throws UnknownHostException
Deprecated.Description copied from interface:ConnectionReturns the IP address string in textual presentation.- Specified by:
getHostAddressin interfaceConnection- Returns:
- the raw IP address in a string format.
- Throws:
UnknownHostException- if IP address of host could not be determined.
-
getHostName
public String getHostName() throws UnknownHostException
Deprecated.Description copied from interface:ConnectionGets the host name for this IP address.If this InetAddress was created with a host name, this host name will be remembered and returned; otherwise, a reverse name lookup will be performed and the result will be returned based on the system configured name lookup service. If a lookup of the name service is required, call
getCanonicalHostName.If there is a security manager, its
checkConnectmethod is first called with the hostname and-1as its arguments to see if the operation is allowed. If the operation is not allowed, it will return the textual representation of the IP address.- Specified by:
getHostNamein interfaceConnection- Returns:
- the host name for this IP address, or if the operation is not allowed by the security check, the textual representation of the IP address.
- Throws:
UnknownHostException- if IP address of host could not be determined.- See Also:
InetAddress.getCanonicalHostName(),SecurityManager.checkConnect(java.lang.String, int)
-
getPort
public int getPort()
Deprecated.Returns the port that the connection uses.- Returns:
- the port that the connection uses.
-
getWriter
public Writer getWriter()
Deprecated.Returns the Writer used to send data to the connection. The writer should be used with caution. In the majority of cases, thedeliver(Packet)method should be used to send data instead of using the writer directly. You must synchronize on the writer before writing data to it to ensure data consistency:Writer writer = connection.getWriter(); synchronized(writer) { // write data.... }- Returns:
- the Writer for this connection.
-
isClosed
public boolean isClosed()
Deprecated.Description copied from interface:ConnectionReturns true if the connection/session is closed.- Specified by:
isClosedin interfaceConnection- Returns:
- true if the connection is closed.
-
isSecure
public boolean isSecure()
Deprecated.Description copied from interface:ConnectionReturns true if this connection is secure.- Specified by:
isSecurein interfaceConnection- Returns:
- true if the connection is secure (e.g. SSL/TLS)
-
isCompressed
public boolean isCompressed()
Deprecated.Description copied from interface:ConnectionReturns true if the connection is using compression.- Specified by:
isCompressedin interfaceConnection- Returns:
- true if the connection is using compression.
-
getTlsPolicy
public Connection.TLSPolicy getTlsPolicy()
Deprecated.Description copied from interface:ConnectionReturns whether TLS is mandatory, optional or is disabled. When TLS is mandatory clients are required to secure their connections or otherwise their connections will be closed. On the other hand, when TLS is disabled clients are not allowed to secure their connections using TLS. Their connections will be closed if they try to secure the connection. in this last case.- Specified by:
getTlsPolicyin interfaceConnection- Returns:
- whether TLS is mandatory, optional or is disabled.
-
setTlsPolicy
public void setTlsPolicy(Connection.TLSPolicy tlsPolicy)
Deprecated.Sets whether TLS is mandatory, optional or is disabled. When TLS is mandatory clients are required to secure their connections or otherwise their connections will be closed. On the other hand, when TLS is disabled clients are not allowed to secure their connections using TLS. Their connections will be closed if they try to secure the connection. in this last case.- Specified by:
setTlsPolicyin interfaceConnection- Parameters:
tlsPolicy- whether TLS is mandatory, optional or is disabled.
-
getCompressionPolicy
public Connection.CompressionPolicy getCompressionPolicy()
Deprecated.Description copied from interface:ConnectionReturns whether compression is optional or is disabled.- Specified by:
getCompressionPolicyin interfaceConnection- Returns:
- whether compression is optional or is disabled.
-
setCompressionPolicy
public void setCompressionPolicy(Connection.CompressionPolicy compressionPolicy)
Deprecated.Sets whether compression is enabled or is disabled.- Specified by:
setCompressionPolicyin interfaceConnection- Parameters:
compressionPolicy- whether Compression is enabled or is disabled.
-
getIdleTimeout
public long getIdleTimeout()
Deprecated.
-
setIdleTimeout
public void setIdleTimeout(long timeout)
Deprecated.Sets the number of milliseconds a connection has to be idle to be closed. Sending stanzas to the client is not considered as activity. We are only considering the connection active when the client sends some data or hearbeats (i.e. whitespaces) to the server.- Parameters:
timeout- the number of milliseconds a connection has to be idle to be closed.
-
getMajorXMPPVersion
public int getMajorXMPPVersion()
Deprecated.Description copied from interface:ConnectionReturns the major version of XMPP being used by this connection (major_version.minor_version. In most cases, the version should be "1.0". However, older clients using the "Jabber" protocol do not set a version. In that case, the version is "0.0".- Specified by:
getMajorXMPPVersionin interfaceConnection- Returns:
- the major XMPP version being used by this connection.
-
getMinorXMPPVersion
public int getMinorXMPPVersion()
Deprecated.Description copied from interface:ConnectionReturns the minor version of XMPP being used by this connection (major_version.minor_version. In most cases, the version should be "1.0". However, older clients using the "Jabber" protocol do not set a version. In that case, the version is "0.0".- Specified by:
getMinorXMPPVersionin interfaceConnection- Returns:
- the minor XMPP version being used by this connection.
-
setXMPPVersion
public void setXMPPVersion(int majorVersion, int minorVersion)Deprecated.Sets the XMPP version information. In most cases, the version should be "1.0". However, older clients using the "Jabber" protocol do not set a version. In that case, the version is "0.0".- Specified by:
setXMPPVersionin interfaceConnection- Parameters:
majorVersion- the major version.minorVersion- the minor version.
-
isFlashClient
public boolean isFlashClient()
Deprecated.Description copied from interface:ConnectionReturns true if the connected client is a flash client. Flash clients need to receive a special character (i.e. \0) at the end of each xml packet. Flash clients may send the character \0 in incoming packets and may start a connection using another openning tag such as: "flash:client".- Specified by:
isFlashClientin interfaceConnection- Returns:
- true if the connected client is a flash client.
-
setFlashClient
public void setFlashClient(boolean flashClient)
Deprecated.Sets whether the connected client is a flash client. Flash clients need to receive a special character (i.e. \0) at the end of each xml packet. Flash clients may send the character \0 in incoming packets and may start a connection using another openning tag such as: "flash:client".- Specified by:
setFlashClientin interfaceConnection- Parameters:
flashClient- true if the if the connection is a flash client.
-
getLocalCertificates
public Certificate[] getLocalCertificates()
Deprecated.Description copied from interface:ConnectionReturns the local underlyingX509Certificatechain for the connection.- Specified by:
getLocalCertificatesin interfaceConnection- Returns:
- an ordered array of certificates, with the local certificate
first followed by any certificate authorities. If no certificates
is present for the connection, then
nullis returned.
-
getPeerCertificates
public Certificate[] getPeerCertificates()
Deprecated.Description copied from interface:ConnectionReturns the underlyingX509Certificatefor the connection of the peer.- Specified by:
getPeerCertificatesin interfaceConnection- Returns:
- an ordered array of peer certificates, with the peer's own certificate first followed by any certificate authorities.
-
setUsingSelfSignedCertificate
public void setUsingSelfSignedCertificate(boolean isSelfSigned)
Deprecated.Description copied from interface:ConnectionKeeps track if the other peer of this session presented a self-signed certificate. When using self-signed certificate for server-2-server sessions then SASL EXTERNAL will not be used and instead server-dialback will be preferred for vcerifying the identify of the remote server.- Specified by:
setUsingSelfSignedCertificatein interfaceConnection- Parameters:
isSelfSigned- true if the other peer presented a self-signed certificate.
-
isUsingSelfSignedCertificate
public boolean isUsingSelfSignedCertificate()
Deprecated.Description copied from interface:ConnectionReturns true if the other peer of this session presented a self-signed certificate. When using self-signed certificate for server-2-server sessions then SASL EXTERNAL will not be used and instead server-dialback will be preferred for vcerifying the identify of the remote server.- Specified by:
isUsingSelfSignedCertificatein interfaceConnection- Returns:
- true if the other peer of this session presented a self-signed certificate.
-
getPacketDeliverer
public PacketDeliverer getPacketDeliverer()
Deprecated.Description copied from interface:ConnectionReturns the packet deliverer to use when delivering a packet over the socket fails. The packet deliverer will retry to send the packet using some other connection, will store the packet offline for later retrieval or will just drop it.- Specified by:
getPacketDelivererin interfaceConnection- Returns:
- the packet deliverer to use when delivering a packet over the socket fails.
-
forceClose
public void forceClose()
Deprecated.Closes the connection without sending any data (not even a stream end-tag).
-
close
public void close()
Deprecated.Closes the connection after trying to send a stream end tag.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceConnection
-
systemShutdown
public void systemShutdown()
Deprecated.Description copied from interface:ConnectionNotification message indicating that the server is being shutdown. Implementors should send a stream error whose condition is system-shutdown before closing the connection.- Specified by:
systemShutdownin interfaceConnection
-
deliver
public void deliver(org.xmpp.packet.Packet packet) throws UnauthorizedException, PacketExceptionDeprecated.Description copied from interface:ConnectionDelivers the packet to this connection without checking the recipient. The method essentially callssocket.send(packet.getWriteBuffer()). Use with caution! This code is unlikely to be called directly. Instead, ensure that data sent to the entities is sent through the appropriate LocalSession object. For clients, this prevents, for example, synchronisation issues with stanza counts related to Stream Management (XEP-0198).- Specified by:
deliverin interfaceConnection- Parameters:
packet- the packet to deliver.- Throws:
UnauthorizedException- if a permission error was detected.PacketException
-
deliverRawText
public void deliverRawText(String text)
Deprecated.Description copied from interface:ConnectionDelivers raw text to this connection. This is a very low level way for sending XML stanzas to the client. This method should not be used unless you have very good reasons for not usingConnection.deliver(org.xmpp.packet.Packet).This method avoids having to get the writer of this connection and mess directly with the writer. Therefore, this method ensures a correct delivery of the stanza even if other threads were sending data concurrently.
- Specified by:
deliverRawTextin interfaceConnection- Parameters:
text- the XML stanzas represented kept in a String.
-
setSocketReader
public void setSocketReader(SocketReader socketReader)
Deprecated.
-
-