Class WebSocketConnection
- java.lang.Object
-
- org.jivesoftware.openfire.net.VirtualConnection
-
- org.jivesoftware.openfire.websocket.WebSocketConnection
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Connection
public class WebSocketConnection extends VirtualConnection
Following the conventions of the BOSH implementation, this class extendsVirtualConnectionand delegates the expected XMPP connection behaviors to the correspondingXmppWebSocket.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.Connection
Connection.ClientAuth, Connection.CompressionPolicy, Connection.State, Connection.TLSPolicy
-
-
Field Summary
-
Fields inherited from class org.jivesoftware.openfire.net.VirtualConnection
session
-
-
Constructor Summary
Constructors Constructor Description WebSocketConnection(XmppWebSocket socket, InetSocketAddress remotePeer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseVirtualConnection()Closes the virtual connection.voiddeliver(org.xmpp.packet.Packet packet)Delivers the packet to this connection without checking the recipient.voiddeliverRawText(String text)Delivers raw text to this connection.byte[]getAddress()Returns the raw IP address of thisInetAddressobject.ConnectionConfigurationgetConfiguration()Returns a representation of the desired state for this connection.StringgetHostAddress()Returns the IP address string in textual presentation.StringgetHostName()Gets the host name for this IP address.PacketDeliverergetPacketDeliverer()Returns the packet deliverer to use when delivering a packet over the socket fails.booleanisCompressed()Returns true if the connection is using compression.booleanisSecure()Returns true if this connection is secure.voidreinit(LocalSession session)Reinitializes the connection to switch to a different session.voidsystemShutdown()Notification message indicating that the server is being shutdown.booleanvalidate()Verifies that the connection is still live.-
Methods inherited from class org.jivesoftware.openfire.net.VirtualConnection
addCompression, close, getCompressionPolicy, getLocalCertificates, getMajorXMPPVersion, getMinorXMPPVersion, getPeerCertificates, getTlsPolicy, init, isClosed, isFlashClient, isUsingSelfSignedCertificate, registerCloseListener, removeCloseListener, setCompressionPolicy, setFlashClient, setTlsPolicy, setUsingSelfSignedCertificate, setXMPPVersion, startCompression, startTLS
-
-
-
-
Constructor Detail
-
WebSocketConnection
public WebSocketConnection(XmppWebSocket socket, InetSocketAddress remotePeer)
-
-
Method Detail
-
closeVirtualConnection
public void closeVirtualConnection()
Description copied from class:VirtualConnectionCloses the virtual connection. Subsclasses should indicate what closing a virtual connection means. At this point the session has a CLOSED state.- Specified by:
closeVirtualConnectionin classVirtualConnection
-
getAddress
public byte[] getAddress()
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].- Returns:
- the raw IP address of this object.
-
getHostAddress
public String getHostAddress()
Description copied from interface:ConnectionReturns the IP address string in textual presentation.- Returns:
- the raw IP address in a string format.
-
getHostName
public String getHostName()
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.- 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.
- See Also:
InetAddress.getCanonicalHostName(),SecurityManager.checkConnect(java.lang.String, int)
-
systemShutdown
public void systemShutdown()
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.
-
deliver
public void deliver(org.xmpp.packet.Packet packet) throws UnauthorizedExceptionDescription 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).- Parameters:
packet- the packet to deliver.- Throws:
UnauthorizedException- if a permission error was detected.
-
deliverRawText
public void deliverRawText(String text)
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.
- Parameters:
text- the XML stanzas represented kept in a String.
-
validate
public boolean validate()
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- Overrides:
validatein classVirtualConnection- Returns:
- true if the socket remains valid, false otherwise.
-
isSecure
public boolean isSecure()
Description copied from interface:ConnectionReturns true if this connection is secure.- Specified by:
isSecurein interfaceConnection- Overrides:
isSecurein classVirtualConnection- Returns:
- true if the connection is secure (e.g. SSL/TLS)
-
getPacketDeliverer
public PacketDeliverer getPacketDeliverer()
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- Overrides:
getPacketDelivererin classVirtualConnection- Returns:
- the packet deliverer to use when delivering a packet over the socket fails.
-
getConfiguration
public ConnectionConfiguration getConfiguration()
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.- Returns:
- The desired configuration for the connection (never null).
-
isCompressed
public boolean isCompressed()
Description copied from interface:ConnectionReturns true if the connection is using compression.- Specified by:
isCompressedin interfaceConnection- Overrides:
isCompressedin classVirtualConnection- Returns:
- true if the connection is using compression.
-
reinit
public void reinit(LocalSession session)
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- Overrides:
reinitin classVirtualConnection- Parameters:
session- The new session now owning the connection.
-
-