Package org.jivesoftware.openfire.http
Class HttpSession
- java.lang.Object
-
- org.jivesoftware.openfire.session.LocalSession
-
- org.jivesoftware.openfire.session.LocalClientSession
-
- org.jivesoftware.openfire.http.HttpSession
-
- All Implemented Interfaces:
ChannelHandler<org.xmpp.packet.Packet>
,RoutableChannelHandler
,ClientSession
,Session
public class HttpSession extends LocalClientSession
A session represents a series of interactions with an XMPP client sending packets using the HTTP Binding protocol specified in XEP-0124. A session can have several client connections open simultaneously while awaiting packets bound for the client from the server.- Author:
- Alexander Wenckus
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpSession.HttpVirtualConnection
A virtual server connection relates to a http session which its self can relate to many http connections.-
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.session.Session
Session.Status
-
-
Field Summary
Fields Modifier and Type Field Description static SystemProperty<Boolean>
IGNORE_INVALID_PAUSE
` Controls if client-provided 'pause' values that are invalid (higher than 'maxpause') are ignored or will cause the client to be disconnected.-
Fields inherited from class org.jivesoftware.openfire.session.LocalClientSession
authToken, csiManager
-
Fields inherited from class org.jivesoftware.openfire.session.LocalSession
address, conn, serverName, sessionManager, startDate, status, streamID, streamManager
-
Fields inherited from interface org.jivesoftware.openfire.session.Session
MAJOR_VERSION, MINOR_VERSION, STATUS_AUTHENTICATED, STATUS_CLOSED, STATUS_CONNECTED
-
-
Constructor Summary
Constructors Constructor Description HttpSession(HttpSession.HttpVirtualConnection vConnection, String serverName, StreamID streamID, long requestId, X509Certificate[] sslCertificates, Locale language, Duration wait, int hold, boolean isEncrypted, Duration maxPollingInterval, int maxRequests, Duration maxPause, Duration defaultInactivityTimeout, int majorVersion, int minorVersion)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
createEmptyBody(boolean terminate)
Creates an empty BOSH 'body' element, optionally including a 'terminate' type attribute (that, in BOSH, signifies the end of a session).protected String
createRemoteStreamErrorBody(org.xmpp.packet.StreamError error)
Creates an empty BOSH 'body' element that including a 'terminate' type attribute (that, in BOSH, signifies the end of a session), sets the 'condition' attribute to 'remote-stream-error' (to signal that an XMPP error is transported), and includes the error in the body.protected String
createTerminalBindingBody(String condition)
Creates an empty BOSH 'body' element that including a 'terminate' type attribute (that, in BOSH, signifies the end of a session), and sets the 'condition' attribute to a specified value.void
deliver(org.xmpp.packet.Packet stanza)
void
forwardRequest(HttpBindBody body, javax.servlet.AsyncContext context)
Forwards a client request, which is related to a session, to the server.List<org.dom4j.Element>
getAvailableStreamFeatures()
Returns the stream features which are available for this session.int
getHold()
Specifies the maximum number of requests the connection manager is allowed to keep waiting at any one time during the session.Duration
getInactivityTimeout()
Returns the time, in seconds, after which this session will be considered inactive and terminated.long
getLastAcknowledged()
Returns the highest 'rid' attribute the server has received where it has also received all requests with lower 'rid' values.Instant
getLastActivity()
Returns the time in milliseconds since the epoch that this session was last active.int
getMajorVersion()
Returns the major version of BOSH which this session utilizes.Duration
getMaxPause()
Returns the maximum length of a temporary session pause that the client MAY request.Duration
getMaxPollingInterval()
Returns the max interval within which a client can send polling requests.int
getMaxRequests()
Returns the max number of requests it is permissible for this session to have open at any one time.int
getMinorVersion()
Returns the major version of BOSH which this session utilizes.X509Certificate[]
getPeerCertificates()
Return the X509Certificates associated with this session.Duration
getWait()
Specifies the longest time (in seconds) that the connection manager is allowed to wait before responding to any request during the session.boolean
isEncrypted()
Returns true if all connections on this session should be encrypted, and false if they should not.boolean
isPollingSession()
Returns true if this session is a polling session.void
pause(Duration duration)
Pauses the session for the given amount of time.void
resetInactivityTimeout()
Resets the inactivity timeout of this session to default.protected void
sendPendingPackets(List<org.dom4j.Element> packetsToSend)
This method sends any pending packets in the session.void
setInactivityTimeout(Duration inactivityTimeout)
Sets the time, in seconds, after which this session will be considered inactive and be terminated.void
setLastResponseEmpty(boolean lastResponseEmpty)
lastResponseEmpty true if last response of this session is an empty body element.String
toString()
-
Methods inherited from class org.jivesoftware.openfire.session.LocalClientSession
canFloodOfflineMessages, canProcess, createSession, getActiveList, getAuthToken, getBlacklistedIPs, getCsiManager, getDefaultList, getPresence, getUsername, getWhitelistedAnonymousIPs, getWhitelistedIPs, hasRequestedBlocklist, incrementConflictCount, isAddressInRange, isAllowed, isAllowedAnonymous, isAnonymousUser, isInitialized, isMessageCarbonsEnabled, isOfflineFloodStopped, reattach, setActiveList, setAnonymousAuth, setAuthToken, setAuthToken, setBlacklistedIPs, setDefaultList, setHasRequestedBlocklist, setInitialized, setMessageCarbonsEnabled, setOfflineFloodStopped, setPresence, setWhitelistedAnonymousIPs, setWhitelistedIPs, wasAvailable
-
Methods inherited from class org.jivesoftware.openfire.session.LocalSession
close, decodeVersion, deliverRawText, getAddress, getCipherSuiteName, getConnection, getCreationDate, getHostAddress, getHostName, getLanguage, getLastActiveDate, getNumClientPackets, getNumServerPackets, getServerName, getSessionData, getSoftwareVersion, getStatus, getStreamID, getStreamManager, getTLSProtocolName, incrementClientPacketCount, incrementServerPacketCount, isClosed, isDetached, isSecure, isUsingSelfSignedCertificate, process, removeSessionData, setAddress, setDetached, setSessionData, setSoftwareVersionData, setStatus, validate
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.openfire.session.Session
close, deliverRawText, getAddress, getCipherSuiteName, getCreationDate, getHostAddress, getHostName, getLanguage, getLastActiveDate, getNumClientPackets, getNumServerPackets, getServerName, getSoftwareVersion, getStatus, getStreamID, getTLSProtocolName, isAuthenticated, isClosed, isSecure, process, validate
-
-
-
-
Field Detail
-
IGNORE_INVALID_PAUSE
public static SystemProperty<Boolean> IGNORE_INVALID_PAUSE
` Controls if client-provided 'pause' values that are invalid (higher than 'maxpause') are ignored or will cause the client to be disconnected.
-
-
Constructor Detail
-
HttpSession
public HttpSession(HttpSession.HttpVirtualConnection vConnection, String serverName, StreamID streamID, long requestId, X509Certificate[] sslCertificates, Locale language, Duration wait, int hold, boolean isEncrypted, Duration maxPollingInterval, int maxRequests, Duration maxPause, Duration defaultInactivityTimeout, int majorVersion, int minorVersion) throws UnknownHostException
- Throws:
UnknownHostException
-
-
Method Detail
-
getAvailableStreamFeatures
public List<org.dom4j.Element> getAvailableStreamFeatures()
Returns the stream features which are available for this session.- Overrides:
getAvailableStreamFeatures
in classLocalClientSession
- Returns:
- the stream features which are available for this session.
-
getWait
public Duration getWait()
Specifies the longest time (in seconds) that the connection manager is allowed to wait before responding to any request during the session. This enables the client to prevent its TCP connection from expiring due to inactivity, as well as to limit the delay before it discovers any network failure.- Returns:
- the longest time it is permissible to wait for a response.
-
getHold
public int getHold()
Specifies the maximum number of requests the connection manager is allowed to keep waiting at any one time during the session. (For example, if a constrained client is unable to keep open more than two HTTP connections to the same HTTP server simultaneously, then it SHOULD specify a value of "1".)- Returns:
- the maximum number of simultaneous waiting requests
-
getMaxPollingInterval
public Duration getMaxPollingInterval()
Returns the max interval within which a client can send polling requests. If more than one request occurs in the interval the session will be terminated.- Returns:
- the max interval within which a client can send polling requests. If more than one request occurs in the interval the session will be terminated.
-
getMaxRequests
public int getMaxRequests()
Returns the max number of requests it is permissible for this session to have open at any one time.- Returns:
- the max number of requests it is permissible for this session to have open at any one time.
-
getMaxPause
public Duration getMaxPause()
Returns the maximum length of a temporary session pause that the client MAY request.- Returns:
- the maximum length of a temporary session pause that the client MAY request.
-
isEncrypted
public boolean isEncrypted()
Returns true if all connections on this session should be encrypted, and false if they should not.- Specified by:
isEncrypted
in interfaceSession
- Overrides:
isEncrypted
in classLocalSession
- Returns:
- true if all connections on this session should be encrypted, and false if they should not.
-
isPollingSession
public boolean isPollingSession()
Returns true if this session is a polling session. Some clients may be restricted to open only one connection to the server. In this case the client SHOULD inform the server by setting the values of the 'wait' and/or 'hold' attributes in its session creation request to "0", and then "poll" the server at regular intervals throughout the session for stanzas it may have received from the server.- Returns:
- true if this session is a polling session.
-
setInactivityTimeout
public void setInactivityTimeout(Duration inactivityTimeout)
Sets the time, in seconds, after which this session will be considered inactive and be terminated.- Parameters:
inactivityTimeout
- the time, in seconds, after which this session will be considered inactive and be terminated.
-
resetInactivityTimeout
public void resetInactivityTimeout()
Resets the inactivity timeout of this session to default. A session's inactivity timeout can be temporarily changed using session pause requests.- See Also:
pause(Duration)
-
getInactivityTimeout
public Duration getInactivityTimeout()
Returns the time, in seconds, after which this session will be considered inactive and terminated.- Returns:
- the time, in seconds, after which this session will be considered inactive and terminated.
-
pause
public void pause(Duration duration)
Pauses the session for the given amount of time. If a client encounters an exceptional temporary situation during which it will be unable to send requests to the connection manager for a period of time greater than the maximum inactivity period, then the client MAY request a temporary increase to the maximum inactivity period by including a 'pause' attribute in a request.- Parameters:
duration
- the time, in seconds, after which this session will be considered inactive and terminated.
-
getLastActivity
public Instant getLastActivity()
Returns the time in milliseconds since the epoch that this session was last active. Activity is a request was either made or responded to. If the session is currently active, meaning there are connections awaiting a response, the current time is returned.- Returns:
- the time in milliseconds since the epoch that this session was last active.
-
getLastAcknowledged
public long getLastAcknowledged()
Returns the highest 'rid' attribute the server has received where it has also received all requests with lower 'rid' values. When responding to a request that it has been holding, if the server finds it has already received another request with a higher 'rid' attribute (typically while it was holding the first request), then it MAY acknowledge the reception to the client.- Returns:
- the highest 'rid' attribute the server has received where it has also received all requests with lower 'rid' values.
-
getMajorVersion
public int getMajorVersion()
Returns the major version of BOSH which this session utilizes. The version refers to the version of the XEP which the connecting client implements. If the client did not specify a version 1 is returned as 1.5 is the last version of the XEP that the client was not required to pass along its version information when creating a session.- Returns:
- the major version of the BOSH XEP which the client is utilizing.
-
getMinorVersion
public int getMinorVersion()
Returns the major version of BOSH which this session utilizes. The version refers to the version of the XEP which the connecting client implements. If the client did not specify a version 5 is returned as 1.5 is the last version of the XEP that the client was not required to pass along its version information when creating a session.- Returns:
- the minor version of the BOSH XEP which the client is utilizing.
-
setLastResponseEmpty
public void setLastResponseEmpty(boolean lastResponseEmpty)
lastResponseEmpty true if last response of this session is an empty body element. This is used in overactivity checking.- Parameters:
lastResponseEmpty
- true if last response of this session is an empty body element.
-
forwardRequest
public void forwardRequest(HttpBindBody body, javax.servlet.AsyncContext context) throws HttpBindException, HttpConnectionClosedException, IOException
Forwards a client request, which is related to a session, to the server. A connection is created and queued up in the provided session. When a connection reaches the top of a queue any pending packets bound for the client will be forwarded to the client through the connection.- Parameters:
body
- the body element that was sent containing the request for a new session.context
- the context of the asynchronous servlet call leading up to this method call.- Throws:
HttpBindException
- for several reasons: if the encoding inside an auth packet is not recognized by the server, or if the packet type is not recognized.HttpConnectionClosedException
- if the session is no longer available.IOException
- if an input or output exception occurred
-
sendPendingPackets
protected void sendPendingPackets(List<org.dom4j.Element> packetsToSend)
This method sends any pending packets in the session. If no packets are pending, this method simply returns. The method is internally synchronized to avoid simultaneous sending operations on this Session. If two threads try to run this method simultaneously, the first one will trigger the pending packets to be sent, while the second one will simply return (as there are no packets left to send).
-
getPeerCertificates
public X509Certificate[] getPeerCertificates()
Return the X509Certificates associated with this session.- Specified by:
getPeerCertificates
in interfaceSession
- Overrides:
getPeerCertificates
in classLocalSession
- Returns:
- the X509Certificate associated with this session.
-
deliver
public void deliver(@Nonnull org.xmpp.packet.Packet stanza)
- Overrides:
deliver
in classLocalClientSession
-
createEmptyBody
@Nonnull protected String createEmptyBody(boolean terminate)
Creates an empty BOSH 'body' element, optionally including a 'terminate' type attribute (that, in BOSH, signifies the end of a session). The element will include an 'ack' attribute, of which the value is the highest request ID (rid) the server has received where it has also received all requests with lower request ID values.- Parameters:
terminate
- Whether to include a type attribute with value 'terminate'.- Returns:
- The string representation of an empty BOSH 'body' element.
-
createTerminalBindingBody
@Nonnull protected String createTerminalBindingBody(@Nonnull String condition)
Creates an empty BOSH 'body' element that including a 'terminate' type attribute (that, in BOSH, signifies the end of a session), and sets the 'condition' attribute to a specified value.- Parameters:
condition
- The terminate condition to set.- Returns:
- The string representation of a BOSH 'body' element.
-
createRemoteStreamErrorBody
@Nonnull protected String createRemoteStreamErrorBody(@Nonnull org.xmpp.packet.StreamError error)
Creates an empty BOSH 'body' element that including a 'terminate' type attribute (that, in BOSH, signifies the end of a session), sets the 'condition' attribute to 'remote-stream-error' (to signal that an XMPP error is transported), and includes the error in the body.- Parameters:
error
- The error to be included in the body.- Returns:
- The string representation of a BOSH 'body' element.
-
toString
public String toString()
- Overrides:
toString
in classLocalClientSession
-
-