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 StringBOSH_URIThe BOSH namespace from XEP-0124.protected StringsessionIDThe session ID for the BOSH session with the connection manager.static StringXMPP_BOSH_NSThe 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, inOrderListeners, lastFeaturesReceived, outgoingStreamXmlEnvironment, port, reader, saslFeatureReceived, SMACK_REACTOR, streamFeatures, streamId, tlsHandled, user, wasAuthenticated, writer
-
-
Constructor Summary
Constructors Constructor Description XMPPBOSHConnection(String username, String password, boolean https, String host, int port, 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 voidafterSaslAuthenticationSuccess()Hook for subclasses right after successful SASL authentication.protected voidconnectInternal()Abstract method that concrete subclasses of XMPPConnection need to implement to perform their way of XMPP connection establishment.protected voidinitDebugger()Initialize the SmackDebugger which allows to log and debug XML traffic.voidinstantShutdown()Performs an unclean disconnect and shutdown of the connection.booleanisSecureConnection()Returns true if the connection to the server has successfully negotiated encryption.booleanisUsingCompression()Returns true if network traffic is being compressed.protected voidloginInternal(String username, String password, Resourcepart resource)protected voidsend(org.igniterealtime.jbosh.ComposableBody body)Send a HTTP request to the connection manager with the provided body element.voidsendNonza(Nonza element)Send a Nonza.protected voidsendStanzaInternal(Stanza packet)protected voidshutdown()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, waitForConditionOrConnectionException, waitForConditionOrConnectionException, 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 String XMPP_BOSH_NS
The XMPP Over Bosh namespace.- See Also:
- Constant Field Values
-
BOSH_URI
public static final String BOSH_URI
The BOSH namespace from XEP-0124.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XMPPBOSHConnection
public XMPPBOSHConnection(String username, String password, boolean https, String host, int port, 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, InterruptedException
Description copied from class:AbstractXMPPConnectionAbstract 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:
connectInternalin classAbstractXMPPConnection- Throws:
SmackException- if Smack detected an exceptional situation.InterruptedException- if the calling thread was interrupted.
-
isSecureConnection
public boolean isSecureConnection()
Description copied from interface:XMPPConnectionReturns true if the connection to the server has successfully negotiated encryption.- Specified by:
isSecureConnectionin interfaceXMPPConnection- Specified by:
isSecureConnectionin classAbstractXMPPConnection- Returns:
- true if a secure connection to the server.
-
isUsingCompression
public boolean isUsingCompression()
Description copied from interface:XMPPConnectionReturns 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:
isUsingCompressionin interfaceXMPPConnection- Specified by:
isUsingCompressionin classAbstractXMPPConnection- Returns:
- true if network traffic is being compressed.
-
loginInternal
protected void loginInternal(String username, String password, Resourcepart resource) throws XMPPException, SmackException, IOException, InterruptedException
- Specified by:
loginInternalin classAbstractXMPPConnection- Throws:
XMPPExceptionSmackExceptionIOExceptionInterruptedException
-
sendNonza
public void sendNonza(Nonza element) throws SmackException.NotConnectedException
Description copied from interface:XMPPConnectionSend 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:
sendNonzain interfaceXMPPConnection- Specified by:
sendNonzain 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:
sendStanzaInternalin 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:
shutdownin classAbstractXMPPConnection
-
instantShutdown
public void instantShutdown()
Description copied from class:AbstractXMPPConnectionPerforms an unclean disconnect and shutdown of the connection. Does not send a closing stream stanza.- Specified by:
instantShutdownin 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:
initDebuggerin classAbstractXMPPConnection
-
afterSaslAuthenticationSuccess
protected void afterSaslAuthenticationSuccess() throws SmackException.NotConnectedException, InterruptedException, SmackException.SmackWrappedException
Description copied from class:AbstractXMPPConnectionHook 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:
afterSaslAuthenticationSuccessin classAbstractXMPPConnection- Throws:
SmackException.NotConnectedException- if the XMPP connection is not connected.InterruptedException- if the calling thread was interrupted.SmackException.SmackWrappedException- in case of an exception.
-
-