public class XMPPBOSHConnection extends XMPPConnection
XMPPConnection
XMPPConnection.FromMode, XMPPConnection.InterceptorWrapper, XMPPConnection.ListenerWrapper
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
authID
The BOSH equivalent of the stream ID which is used for DIGEST authentication.
|
static java.lang.String |
BOSH_URI
The BOSH namespace from XEP-0124.
|
protected java.lang.String |
sessionID
The session ID for the BOSH session with the connection manager.
|
static java.lang.String |
XMPP_BOSH_NS
The XMPP Over Bosh namespace.
|
collectors, compressionHandler, connectionCounterValue, connectionListeners, debugger, interceptors, reader, recvListeners, saslAuthentication, sendListeners, writer
Constructor and Description |
---|
XMPPBOSHConnection(boolean https,
java.lang.String host,
int port,
java.lang.String filePath,
java.lang.String xmppDomain)
Create a HTTP Binding connection to a XMPP server.
|
XMPPBOSHConnection(BOSHConfiguration config)
Create a HTTP Binding connection to a XMPP server.
|
Modifier and Type | Method and Description |
---|---|
protected void |
connectInternal()
Abstract method that concrete subclasses of XMPPConnection need to implement to perform their
way of XMPP connection establishment.
|
java.lang.String |
getConnectionID()
Returns the connection ID for this connection, which is the value set by the server
when opening a XMPP stream.
|
protected SASLAuthentication |
getSASLAuthentication()
Returns the SASLAuthentication manager that is responsible for authenticating with
the server.
|
java.lang.String |
getUser()
Returns the full XMPP address of the user that is logged in to the connection or
null if not logged in yet.
|
protected void |
initDebugger()
Initialize the SmackDebugger which allows to log and debug XML traffic.
|
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 |
isUsingCompression()
Returns true if network traffic is being compressed.
|
void |
login(java.lang.String username,
java.lang.String password,
java.lang.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 |
notifyConnectionError(java.lang.Exception e)
Sends out a notification that there was an error with the connection
and closes the connection.
|
protected void |
processPacket(Packet packet)
Processes a packet after it's been fully parsed by looping through the installed
packet collectors and listeners and letting them examine the packet to see if
they are a match with the filter.
|
protected void |
send(org.igniterealtime.jbosh.ComposableBody body)
Send a HTTP request to the connection manager with the provided body element.
|
protected void |
sendPacketInternal(Packet packet) |
protected void |
serverRequiresBinding()
Notification message saying that the server requires the client to bind a
resource to the stream.
|
protected void |
serverSupportsAccountCreation() |
protected void |
serverSupportsSession()
Notification message saying that the server supports sessions.
|
protected void |
shutdown()
Closes the connection by setting presence to unavailable and closing the
HTTP client.
|
addConnectionCreationListener, addConnectionListener, addPacketInterceptor, addPacketListener, addPacketSendingListener, bindResourceAndEstablishSession, callConnectionAuthenticatedListener, callConnectionClosedOnErrorListener, callConnectionConnectedListener, connect, createPacketCollector, createPacketCollectorAndSend, disconnect, disconnect, finalize, getConfiguration, getConnectionCounter, getConnectionCreationListeners, getConnectionListeners, getFromMode, getHost, getPacketCollectors, getPacketInterceptors, getPacketListeners, getPacketReplyTimeout, getPacketSendingListeners, getPort, getReader, getRoster, getServiceCapsNode, getServiceName, getWriter, isRosterVersioningSupported, login, maybeResolveDns, removeConnectionCreationListener, removeConnectionListener, removePacketCollector, removePacketInterceptor, removePacketListener, removePacketSendingListener, schedule, sendPacket, setConnectionException, setFromMode, setLoginInfo, setPacketReplyTimeout, setRosterVersioningSupported, setServiceCapsNode, setServiceName, setWasAuthenticated, throwConnectionExceptionOrNoResponse
public static final java.lang.String XMPP_BOSH_NS
public static final java.lang.String BOSH_URI
protected java.lang.String authID
protected java.lang.String sessionID
public XMPPBOSHConnection(boolean https, java.lang.String host, int port, java.lang.String filePath, java.lang.String xmppDomain)
https
- true if you want to use SSL
(e.g. false for http://domain.lt:7070/http-bind).host
- the hostname or IP address of the connection manager
(e.g. domain.lt for http://domain.lt:7070/http-bind).port
- the port of the connection manager
(e.g. 7070 for http://domain.lt:7070/http-bind).filePath
- the file which is described by the URL
(e.g. /http-bind for http://domain.lt:7070/http-bind).xmppDomain
- the XMPP service name
(e.g. domain.lt for the user alice@domain.lt)public XMPPBOSHConnection(BOSHConfiguration config)
config
- The configuration which is used for this connection.protected void connectInternal() throws SmackException
XMPPConnection
XMPPConnection.serverRequiresBinding()
and such).
Also implementations are required to perform an automatic login if the previous connection state was logged (authenticated).
connectInternal
in class XMPPConnection
SmackException
public java.lang.String getConnectionID()
XMPPConnection
getConnectionID
in class XMPPConnection
public java.lang.String getUser()
XMPPConnection
getUser
in class XMPPConnection
public boolean isAnonymous()
XMPPConnection
isAnonymous
in class XMPPConnection
public boolean isAuthenticated()
XMPPConnection
isAuthenticated
in class XMPPConnection
public boolean isConnected()
XMPPConnection
isConnected
in class XMPPConnection
public boolean isSecureConnection()
XMPPConnection
isSecureConnection
in class XMPPConnection
public boolean isUsingCompression()
XMPPConnection
isUsingCompression
in class XMPPConnection
public void login(java.lang.String username, java.lang.String password, java.lang.String resource) throws XMPPException, SmackException, java.io.IOException
XMPPConnection
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 XMPPConnection
username
- the username.password
- the password or null if using a CallbackHandler.resource
- the resource.XMPPException
- if an error occurs on the XMPP protocol level.SmackException
- if an error occurs somehwere else besides XMPP protocol level.java.io.IOException
javax.security.sasl.SaslException
public void loginAnonymously() throws XMPPException, SmackException, java.io.IOException
XMPPConnection
loginAnonymously
in class XMPPConnection
XMPPException
- if an error occurs on the XMPP protocol level.SmackException
- if an error occurs somehwere else besides XMPP protocol level.java.io.IOException
javax.security.sasl.SaslException
protected void sendPacketInternal(Packet packet) throws SmackException.NotConnectedException
sendPacketInternal
in class XMPPConnection
SmackException.NotConnectedException
protected void shutdown()
XMPPConnection.disconnect()
the connection's
BOSH packet reader and Roster
will not be removed; thus
connection's state is kept.shutdown
in class XMPPConnection
protected void send(org.igniterealtime.jbosh.ComposableBody body) throws org.igniterealtime.jbosh.BOSHException
body
- the body which will be sent.org.igniterealtime.jbosh.BOSHException
protected void initDebugger()
initDebugger
in class XMPPConnection
protected void notifyConnectionError(java.lang.Exception e)
e
- the exception that causes the connection close event.protected void processPacket(Packet packet)
XMPPConnection
processPacket
in class XMPPConnection
packet
- the packet to process.protected SASLAuthentication getSASLAuthentication()
XMPPConnection
getSASLAuthentication
in class XMPPConnection
protected void serverRequiresBinding()
XMPPConnection
serverRequiresBinding
in class XMPPConnection
protected void serverSupportsSession()
XMPPConnection
serverSupportsSession
in class XMPPConnection
protected void serverSupportsAccountCreation()
serverSupportsAccountCreation
in class XMPPConnection