public class XMPPConnection extends Connection
ConnectionConnection.InterceptorWrapper, Connection.ListenerWrappercollectors, compressionHandler, compressionHandlers, config, connectionCounterValue, connectionListeners, DEBUG_ENABLED, debugger, interceptors, reader, recvListeners, saslAuthentication, sendListeners, writer| Constructor and Description |
|---|
XMPPConnection(ConnectionConfiguration config)
Creates a new XMPP connection in the same way
XMPPConnection(ConnectionConfiguration,CallbackHandler) does,
but with no callback handler for password prompting of the keystore. |
XMPPConnection(ConnectionConfiguration config,
CallbackHandler callbackHandler)
Creates a new XMPP connection using the specified connection
configuration.
|
XMPPConnection(String serviceName)
Creates a new XMPP connection in the same way
XMPPConnection(String,CallbackHandler) does, but with no
callback handler for password prompting of the keystore. |
XMPPConnection(String serviceName,
CallbackHandler callbackHandler)
Creates a new connection to the specified XMPP server.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addPacketWriterInterceptor(PacketInterceptor packetInterceptor,
PacketFilter packetFilter)
Deprecated.
|
void |
addPacketWriterListener(PacketListener packetListener,
PacketFilter packetFilter)
Deprecated.
|
void |
connect()
Establishes a connection to the XMPP server and performs an automatic
login only if the previous connection state was logged (authenticated).
|
void |
disconnect(org.xmpp.packet.Presence unavailablePresence)
Closes the connection.
|
String |
getConnectionID()
Returns the connection ID for this connection, which is the value set by
the server when opening a XMPP stream.
|
ParsingExceptionCallback |
getParsingExceptionCallback()
Get the current active parsing exception callback.
|
Set<Plugin> |
getPlugins() |
UserRoster |
getRoster()
Returns the roster for the user.
|
String |
getUser()
Returns the full XMPP address of the user that is logged in to the
connection or null if not logged in yet.
|
boolean |
isAnonymous()
Returns true if currently authenticated anonymously.
|
boolean |
isAuthenticated()
Returns true if currently authenticated by successfully calling the login
method.
|
boolean |
isConnected()
Returns true if currently connected to the XMPP server.
|
boolean |
isSecureConnection()
Returns true if the connection to the server has successfully negotiated
encryption.
|
boolean |
isSocketClosed() |
boolean |
isUsingCompression()
Returns true if network traffic is being compressed.
|
boolean |
isUsingTLS()
Returns true if the connection to the server has successfully negotiated
TLS.
|
void |
login(String username,
String password,
String resource)
Logs in to the server using the strongest authentication mode supported
by the server, then sets presence to available.
|
void |
loginAnonymously()
Logs in to the server anonymously.
|
protected void |
notifyReconnection()
Sends a notification indicating that the connection was reconnected
successfully.
|
void |
registerPlugin(Plugin plugin) |
void |
removePacketWriterInterceptor(PacketInterceptor packetInterceptor)
Deprecated.
replaced by
Connection.removePacketInterceptor(PacketInterceptor)
. |
void |
removePacketWriterListener(PacketListener packetListener)
Deprecated.
|
void |
sendPacket(org.xmpp.packet.Packet packet)
Sends the specified packet to the server.
|
void |
setParsingExceptionCallback(ParsingExceptionCallback callback)
Install a parsing exception callback, which will be invoked once an
exception is encountered while parsing a stanza
|
protected void |
shutdown(org.xmpp.packet.Presence unavailablePresence)
Closes the connection by setting presence to unavailable then closing the
stream to the XMPP server.
|
addConnectionCreationListener, addConnectionListener, addPacketInterceptor, addPacketListener, addPacketSendingListener, createPacketCollector, disconnect, firePacketInterceptors, firePacketSendingListeners, getChatManager, getConfiguration, getConnectionCreationListeners, getConnectionListeners, getHost, getPacketCollectors, getPacketInterceptors, getPacketListeners, getPacketSendingListeners, getPort, getSASLAuthentication, getServiceCapsNode, getServiceName, initDebugger, isReconnectionAllowed, isRosterVersioningSupported, login, removeConnectionCreationListener, removeConnectionListener, removePacketCollector, removePacketInterceptor, removePacketListener, removePacketSendingListener, setRosterVersioningSupported, setServiceCapsNodepublic XMPPConnection(String serviceName, CallbackHandler callbackHandler)
This is the simplest constructor for connecting to an XMPP server. Alternatively, you can get fine-grained control over connection settings using the
XMPPConnection(ConnectionConfiguration) constructor.
Note that XMPPConnection constructors do not establish a connection to the server and you must call
connect().
The CallbackHandler will only be used if the connection requires the client provide an SSL certificate to the server. The CallbackHandler must handle the PasswordCallback to prompt for a password to unlock the keystore containing the SSL certificate.
serviceName - the name of the XMPP server to connect to; e.g.
example.com.callbackHandler - the CallbackHandler used to prompt for the password to the
keystore.public XMPPConnection(String serviceName)
XMPPConnection(String,CallbackHandler) does, but with no
callback handler for password prompting of the keystore. This will work
in most cases, provided the client is not required to provide a
certificate to the server.serviceName - the name of the XMPP server to connect to; e.g.
example.com.public XMPPConnection(ConnectionConfiguration config)
XMPPConnection(ConnectionConfiguration,CallbackHandler) does,
but with no callback handler for password prompting of the keystore. This
will work in most cases, provided the client is not required to provide a
certificate to the server.config - the connection configuration.public XMPPConnection(ConnectionConfiguration config, CallbackHandler callbackHandler)
Manually specifying connection configuration information is suitable for advanced users of the API. In many cases, using the
XMPPConnection(String) constructor is a better approach.
Note that XMPPConnection constructors do not establish a connection to the server and you must call
connect().
The CallbackHandler will only be used if the connection requires the client provide an SSL certificate to the server. The CallbackHandler must handle the PasswordCallback to prompt for a password to unlock the keystore containing the SSL certificate.
config - the connection configuration.callbackHandler - the CallbackHandler used to prompt for the password to the
keystore.public String getConnectionID()
ConnectiongetConnectionID in class Connectionpublic String getUser()
ConnectiongetUser in class Connectionpublic void setParsingExceptionCallback(ParsingExceptionCallback callback)
callback - the callback to installpublic ParsingExceptionCallback getParsingExceptionCallback()
public void login(String username, String password, String resource) throws XMPPException
Connection
Before logging in (i.e. authenticate) to the server the connection must
be connected.
It is possible to log in without sending an initial available presence by
using ConnectionConfiguration.setSendPresence(boolean). If this
connection is not interested in loading its roster upon login then use
ConnectionConfiguration.setRosterLoadedAtLogin(boolean). Finally,
if you want to not pass a password and instead use a more advanced
mechanism while using SASL then you may be interested in using
ConnectionConfiguration.setCallbackHandler(javax.security.auth.callback.CallbackHandler)
. For more advanced login settings see ConnectionConfiguration.
login in class Connectionusername - the username.password - the password or null if using a CallbackHandler.resource - the resource.XMPPException - if an error occurs.public void loginAnonymously()
throws XMPPException
ConnectionloginAnonymously in class ConnectionXMPPException - if an error occurs or anonymous logins are not supported by
the server.public UserRoster getRoster()
Connection
This method will never return null, instead if the user has
not yet logged into the server or is logged in anonymously all modifying
methods of the returned roster object like
UserRoster.createEntry(String, String, String[]),
UserRoster.removeEntry(RosterEntry) , etc. except adding or
removing RosterListeners will throw an IllegalStateException.
getRoster in class Connectionpublic boolean isConnected()
ConnectionisConnected in class Connectionpublic boolean isSecureConnection()
ConnectionisSecureConnection in class Connectionpublic boolean isSocketClosed()
public boolean isAuthenticated()
ConnectionisAuthenticated in class Connectionpublic boolean isAnonymous()
ConnectionisAnonymous in class Connectionprotected void shutdown(org.xmpp.packet.Presence unavailablePresence)
Connection.disconnect() the connection's packet reader, packet
writer, and UserRoster will not be removed; thus connection's
state is kept.unavailablePresence - the presence packet to send during shutdown.public void disconnect(org.xmpp.packet.Presence unavailablePresence)
ConnectionThis method cleans up all resources used by the connection. Therefore, the roster, listeners and other stateful objects cannot be re-used by simply calling connect() on this connection again. This is unlike the behavior during unexpected disconnects (and subsequent connections). In that case, all state is preserved to allow for more seamless error recovery.
disconnect in class ConnectionunavailablePresence - the presence packet to send during shutdown.public void sendPacket(org.xmpp.packet.Packet packet)
ConnectionsendPacket in class Connectionpacket - the packet to send.public void addPacketWriterInterceptor(PacketInterceptor packetInterceptor, PacketFilter packetFilter)
Connection.addPacketInterceptor(PacketInterceptor, PacketFilter)
.packetInterceptor - the packet interceptor to notify of packets about to be sent.packetFilter - the packet filter to use.public void removePacketWriterInterceptor(PacketInterceptor packetInterceptor)
Connection.removePacketInterceptor(PacketInterceptor)
.packetInterceptor - the packet interceptor to remove.public void addPacketWriterListener(PacketListener packetListener, PacketFilter packetFilter)
Connection.addPacketSendingListener(PacketListener, PacketFilter)
.packetListener - the packet listener to notify of sent packets.packetFilter - the packet filter to use.public void removePacketWriterListener(PacketListener packetListener)
Connection.removePacketSendingListener(PacketListener).packetListener - the packet listener to remove.public boolean isUsingTLS()
public boolean isUsingCompression()
ConnectionisUsingCompression in class Connectionpublic void connect()
throws XMPPException
Listeners will be preserved from a previous connection if the reconnection occurs after an abrupt termination.
connect in class ConnectionXMPPException - if an error occurs while trying to establish the connection.
Two possible errors can occur which will be wrapped by an
XMPPException -- UnknownHostException (XMPP error code 504),
and IOException (XMPP error code 502). The error codes and
wrapped exceptions can be used to present more appropriate
error messages to end-users.protected void notifyReconnection()
public void registerPlugin(Plugin plugin)
Copyright © 2014. All Rights Reserved.