Package org.jivesoftware.smack.bosh
Class XMPPBOSHConnection
- java.lang.Object
-
- org.jivesoftware.smack.AbstractXMPPConnection
-
- org.jivesoftware.smack.bosh.XMPPBOSHConnection
-
- All Implemented Interfaces:
XMPPConnection
public class XMPPBOSHConnection extends AbstractXMPPConnection
Creates a connection to an XMPP server via HTTP binding. This is specified in the XEP-0206: XMPP Over BOSH.- See Also:
XMPPConnection
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jivesoftware.smack.AbstractXMPPConnection
AbstractXMPPConnection.InterceptorWrapper, AbstractXMPPConnection.ListenerWrapper, AbstractXMPPConnection.SyncPointState
-
Nested classes/interfaces inherited from interface org.jivesoftware.smack.XMPPConnection
XMPPConnection.FromMode
-
-
Field Summary
Fields Modifier and Type Field Description 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.-
Fields inherited from class org.jivesoftware.smack.AbstractXMPPConnection
ASYNC_BUT_ORDERED, authenticated, authenticatedConnectionInitiallyEstablishedTimestamp, closingStreamReceived, compressionHandler, connected, connectionCounterValue, connectionListeners, connectionLock, currentSmackException, currentXmppException, debugger, host, lastFeaturesReceived, outgoingStreamXmlEnvironment, port, reader, saslFeatureReceived, SMACK_REACTOR, streamFeatures, streamId, tlsHandled, user, wasAuthenticated, writer
-
-
Constructor Summary
Constructors Constructor Description XMPPBOSHConnection(java.lang.String username, java.lang.String password, boolean https, java.lang.String host, int port, java.lang.String filePath, DomainBareJid xmppServiceDomain)
Create a HTTP Binding connection to an XMPP server.XMPPBOSHConnection(BOSHConfiguration config)
Create a HTTP Binding connection to an XMPP server.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterSaslAuthenticationSuccess()
Hook for subclasses right after successful SASL authentication.protected void
connectInternal()
Abstract method that concrete subclasses of XMPPConnection need to implement to perform their way of XMPP connection establishment.protected void
initDebugger()
Initialize the SmackDebugger which allows to log and debug XML traffic.void
instantShutdown()
Performs an unclean disconnect and shutdown of the connection.boolean
isSecureConnection()
Returns true if the connection to the server has successfully negotiated encryption.boolean
isUsingCompression()
Returns true if network traffic is being compressed.protected void
loginInternal(java.lang.String username, java.lang.String password, Resourcepart resource)
protected void
send(org.igniterealtime.jbosh.ComposableBody body)
Send a HTTP request to the connection manager with the provided body element.void
sendNonza(Nonza element)
Send a Nonza.protected void
sendStanzaInternal(Stanza packet)
protected void
shutdown()
Closes the connection by setting presence to unavailable and closing the HTTP client.-
Methods inherited from class org.jivesoftware.smack.AbstractXMPPConnection
addAsyncStanzaListener, addConnectionListener, addMessageInterceptor, addOneTimeSyncCallback, addPresenceInterceptor, addStanzaInterceptor, addStanzaListener, addStanzaSendingListener, addStreamFeature, addSyncStanzaListener, afterFeaturesReceived, afterSuccessfulLogin, asyncGo, asyncGoLimited, authenticate, bindResourceAndEstablishSession, buildNonzaCallback, callConnectionAuthenticatedListener, callConnectionConnectedListener, callConnectionConnectingListener, connect, createStanzaCollector, createStanzaCollector, createStanzaCollectorAndSend, createStanzaCollectorAndSend, disconnect, disconnect, firePacketSendingListeners, getAuthenticatedConnectionInitiallyEstablishedTimestamp, getConfiguration, getConnectionCounter, getConnectionLock, getFeature, getFromMode, getHost, getLastStanzaReceived, getParsingExceptionCallback, getPort, getReactor, getReplyTimeout, getSmackTlsContext, getStanzaFactory, getStreamId, getUsedSaslMechansism, getUser, getXMPPServiceDomain, hasCurrentConnectionException, hasFeature, initState, invokeStanzaCollectorsAndNotifyRecvListeners, isAnonymous, isAuthenticated, isConnected, isSaslAuthenticated, login, login, login, notifyConnectionError, notifyWaitingThreads, onStreamOpen, parseAndProcessNonza, parseAndProcessStanza, parseFeatures, parseFeaturesAndNotify, processStanza, registerIQRequestHandler, removeAsyncStanzaListener, removeConnectionListener, removeMessageInterceptor, removePresenceInterceptor, removeStanzaCollector, removeStanzaInterceptor, removeStanzaListener, removeStanzaSendingListener, removeSyncStanzaListener, schedule, sendAndWaitForResponse, sendAsync, sendAsync, sendIqRequestAndWaitForResponse, sendIqRequestAsync, sendIqRequestAsync, sendStanza, sendStreamOpen, setCurrentConnectionExceptionAndNotify, setFromMode, setMaxAsyncOperations, setParsingExceptionCallback, setReplyTimeout, setUnknownIqRequestReplyMode, setWasAuthenticated, throwAlreadyConnectedExceptionIfAppropriate, throwAlreadyLoggedInExceptionIfAppropriate, throwCurrentConnectionException, throwNotConnectedExceptionIfAppropriate, throwNotConnectedExceptionIfAppropriate, toString, trySendStanza, trySendStanza, unregisterIQRequestHandler, unregisterIQRequestHandler, waitFor, waitForClosingStreamTagFromServer, waitForConditionOrThrowConnectionException
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.XMPPConnection
getFeature, getFeature, hasFeature
-
-
-
-
Field Detail
-
XMPP_BOSH_NS
public static final java.lang.String XMPP_BOSH_NS
The XMPP Over Bosh namespace.- See Also:
- Constant Field Values
-
BOSH_URI
public static final java.lang.String BOSH_URI
The BOSH namespace from XEP-0124.- See Also:
- Constant Field Values
-
sessionID
protected java.lang.String sessionID
The session ID for the BOSH session with the connection manager.
-
-
Constructor Detail
-
XMPPBOSHConnection
public XMPPBOSHConnection(java.lang.String username, java.lang.String password, boolean https, java.lang.String host, int port, java.lang.String filePath, DomainBareJid xmppServiceDomain)
Create a HTTP Binding connection to an XMPP server.- Parameters:
username
- the username to use.password
- the password to use.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).xmppServiceDomain
- the XMPP service name (e.g. domain.lt for the user alice@domain.lt)
-
XMPPBOSHConnection
public XMPPBOSHConnection(BOSHConfiguration config)
Create a HTTP Binding connection to an XMPP server.- Parameters:
config
- The configuration which is used for this connection.
-
-
Method Detail
-
connectInternal
protected void connectInternal() throws SmackException, java.lang.InterruptedException
Description copied from class:AbstractXMPPConnection
Abstract method that concrete subclasses of XMPPConnection need to implement to perform their way of XMPP connection establishment. Implementations are required to perform an automatic login if the previous connection state was logged (authenticated).- Specified by:
connectInternal
in classAbstractXMPPConnection
- Throws:
SmackException
- if Smack detected an exceptional situation.java.lang.InterruptedException
- if the calling thread was interrupted.
-
isSecureConnection
public boolean isSecureConnection()
Description copied from interface:XMPPConnection
Returns true if the connection to the server has successfully negotiated encryption.- Specified by:
isSecureConnection
in interfaceXMPPConnection
- Specified by:
isSecureConnection
in classAbstractXMPPConnection
- Returns:
- true if a secure connection to the server.
-
isUsingCompression
public boolean isUsingCompression()
Description copied from interface:XMPPConnection
Returns true if network traffic is being compressed. When using stream compression network traffic can be reduced up to 90%. Therefore, stream compression is ideal when using a slow speed network connection. However, the server will need to use more CPU time in order to un/compress network data so under high load the server performance might be affected.- Specified by:
isUsingCompression
in interfaceXMPPConnection
- Specified by:
isUsingCompression
in classAbstractXMPPConnection
- Returns:
- true if network traffic is being compressed.
-
loginInternal
protected void loginInternal(java.lang.String username, java.lang.String password, Resourcepart resource) throws XMPPException, SmackException, java.io.IOException, java.lang.InterruptedException
- Specified by:
loginInternal
in classAbstractXMPPConnection
- Throws:
XMPPException
SmackException
java.io.IOException
java.lang.InterruptedException
-
sendNonza
public void sendNonza(Nonza element) throws SmackException.NotConnectedException
Description copied from interface:XMPPConnection
Send a Nonza.This method is not meant for end-user usage! It allows sending plain stream elements, which should not be done by a user manually. Doing so may result in a unstable or unusable connection. Certain Smack APIs use this method to send plain stream elements.
- Specified by:
sendNonza
in interfaceXMPPConnection
- Specified by:
sendNonza
in classAbstractXMPPConnection
- Parameters:
element
- the Nonza to send.- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.
-
sendStanzaInternal
protected void sendStanzaInternal(Stanza packet) throws SmackException.NotConnectedException
- Specified by:
sendStanzaInternal
in classAbstractXMPPConnection
- Throws:
SmackException.NotConnectedException
-
shutdown
protected void shutdown()
Closes the connection by setting presence to unavailable and closing the HTTP client. The shutdown logic will be used during a planned disconnection or when dealing with an unexpected disconnection. UnlikeAbstractXMPPConnection.disconnect()
the connection's BOSH stanza reader will not be removed; thus connection's state is kept.- Specified by:
shutdown
in classAbstractXMPPConnection
-
instantShutdown
public void instantShutdown()
Description copied from class:AbstractXMPPConnection
Performs an unclean disconnect and shutdown of the connection. Does not send a closing stream stanza.- Specified by:
instantShutdown
in classAbstractXMPPConnection
-
send
protected void send(org.igniterealtime.jbosh.ComposableBody body) throws org.igniterealtime.jbosh.BOSHException
Send a HTTP request to the connection manager with the provided body element.- Parameters:
body
- the body which will be sent.- Throws:
org.igniterealtime.jbosh.BOSHException
- if an BOSH (Bidirectional-streams Over Synchronous HTTP, XEP-0124) related error occurs
-
initDebugger
protected void initDebugger()
Initialize the SmackDebugger which allows to log and debug XML traffic.- Overrides:
initDebugger
in classAbstractXMPPConnection
-
afterSaslAuthenticationSuccess
protected void afterSaslAuthenticationSuccess() throws SmackException.NotConnectedException, java.lang.InterruptedException, SmackException.SmackWrappedException
Description copied from class:AbstractXMPPConnection
Hook for subclasses right after successful SASL authentication. RFC 6120 ยง 6.4.6. specifies a that the initiating entity, needs to initiate a new stream in this case. But some transports, like BOSH, requires a special handling.Note that we can not reset XMPPTCPConnection's parser here, because this method is invoked by the thread calling
AbstractXMPPConnection.login()
, but the parser reset has to be done within the reader thread.- Overrides:
afterSaslAuthenticationSuccess
in classAbstractXMPPConnection
- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.SmackException.SmackWrappedException
- in case of an exception.
-
-