Package io.vertx.ext.web.handler.sockjs
Class SockJSHandlerOptions
- java.lang.Object
-
- io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions
-
public class SockJSHandlerOptions extends Object
Options for configuring a SockJS handler- Author:
- Tim Fox, Paulo Lopes
-
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_HEARTBEAT_INTERVALThe default interval between heartbeat packets.static booleanDEFAULT_INSERT_JSESSIONIDWhether aJSESSIONIDcookie should be inserted by default = true.static StringDEFAULT_LIBRARY_URLThe default SockJS library URL to load in iframe when a transport does not support cross-domain communication natively.static booleanDEFAULT_LOCAL_WRITE_HANDLERWhether thewriteHandlershould be registered as local by default = true.static intDEFAULT_MAX_BYTES_STREAMINGThe default maximum number of bytes an HTTP streaming request can send.static booleanDEFAULT_REGISTER_WRITE_HANDLERWhether awriteHandlershould be registered by default = false.static longDEFAULT_SESSION_TIMEOUTThe default delay before sending acloseevent to a silent client.
-
Constructor Summary
Constructors Constructor Description SockJSHandlerOptions()Default constructor.SockJSHandlerOptions(JsonObject json)Constructor to create options from JSON.SockJSHandlerOptions(SockJSHandlerOptions other)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SockJSHandlerOptionsaddDisabledTransport(String subProtocol)Add a transport (by name) to the set of disabled transports.Set<String>getDisabledTransports()longgetHeartbeatInterval()StringgetLibraryURL()intgetMaxBytesStreaming()StringgetOrigin()longgetSessionTimeout()booleanisInsertJSESSIONID()booleanisLocalWriteHandler()booleanisRegisterWriteHandler()SockJSHandlerOptionssetHeartbeatInterval(long heartbeatInterval)In order to keep proxies and load balancers from closing long running HTTP requests we need to pretend that the connection is active and send a heartbeat packet once in a while.SockJSHandlerOptionssetInsertJSESSIONID(boolean insertJSESSIONID)Whether to insert aJSESSIONIDcookie so load-balancers ensure requests for a specific SockJS session are always routed to the correct server.SockJSHandlerOptionssetLibraryURL(String libraryURL)Transports which don't support cross-domain communication natively use an iframe trick.SockJSHandlerOptionssetLocalWriteHandler(boolean localWriteHandler)Whether thewriteHandlershould be local only or cluster-wide.SockJSHandlerOptionssetMaxBytesStreaming(int maxBytesStreaming)Most streaming transports save responses on the client side and don't free memory used by delivered messages.SockJSHandlerOptionssetOrigin(String origin)Set the origin to be verified before a websocket upgrade happens.SockJSHandlerOptionssetRegisterWriteHandler(boolean registerWriteHandler)Whether awriteHandlershould be registered on theEventBus.SockJSHandlerOptionssetSessionTimeout(long sessionTimeout)Set the delay before the server sends acloseevent when a client receiving connection has not been seen for a while.
-
-
-
Field Detail
-
DEFAULT_SESSION_TIMEOUT
public static final long DEFAULT_SESSION_TIMEOUT
The default delay before sending acloseevent to a silent client.- See Also:
- Constant Field Values
-
DEFAULT_INSERT_JSESSIONID
public static final boolean DEFAULT_INSERT_JSESSIONID
Whether aJSESSIONIDcookie should be inserted by default = true.- See Also:
- Constant Field Values
-
DEFAULT_HEARTBEAT_INTERVAL
public static final long DEFAULT_HEARTBEAT_INTERVAL
The default interval between heartbeat packets.- See Also:
- Constant Field Values
-
DEFAULT_MAX_BYTES_STREAMING
public static final int DEFAULT_MAX_BYTES_STREAMING
The default maximum number of bytes an HTTP streaming request can send.- See Also:
- Constant Field Values
-
DEFAULT_LIBRARY_URL
public static final String DEFAULT_LIBRARY_URL
The default SockJS library URL to load in iframe when a transport does not support cross-domain communication natively.- See Also:
- Constant Field Values
-
DEFAULT_REGISTER_WRITE_HANDLER
public static final boolean DEFAULT_REGISTER_WRITE_HANDLER
Whether awriteHandlershould be registered by default = false.- See Also:
- Constant Field Values
-
DEFAULT_LOCAL_WRITE_HANDLER
public static final boolean DEFAULT_LOCAL_WRITE_HANDLER
Whether thewriteHandlershould be registered as local by default = true.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SockJSHandlerOptions
public SockJSHandlerOptions(SockJSHandlerOptions other)
Copy constructor.- Parameters:
other- the options to copy
-
SockJSHandlerOptions
public SockJSHandlerOptions()
Default constructor.
-
SockJSHandlerOptions
public SockJSHandlerOptions(JsonObject json)
Constructor to create options from JSON.- Parameters:
json- the JSON
-
-
Method Detail
-
getSessionTimeout
public long getSessionTimeout()
- Returns:
- the session timeout in milliseconds
-
setSessionTimeout
public SockJSHandlerOptions setSessionTimeout(long sessionTimeout)
Set the delay before the server sends acloseevent when a client receiving connection has not been seen for a while.Defaults to 5 seconds.
- Parameters:
sessionTimeout- timeout in milliseconds- Returns:
- a reference to this, so the API can be used fluently
-
isInsertJSESSIONID
public boolean isInsertJSESSIONID()
- Returns:
- true if a
JSESSIONIDcookie should be inserted, false otherwise
-
setInsertJSESSIONID
public SockJSHandlerOptions setInsertJSESSIONID(boolean insertJSESSIONID)
Whether to insert aJSESSIONIDcookie so load-balancers ensure requests for a specific SockJS session are always routed to the correct server.Defaults to
true.- Parameters:
insertJSESSIONID- true if aJSESSIONIDcookie should be inserted, false otherwise- Returns:
- a reference to this, so the API can be used fluently
-
getHeartbeatInterval
public long getHeartbeatInterval()
- Returns:
- the hearbeat packet interval in milliseconds
-
setHeartbeatInterval
public SockJSHandlerOptions setHeartbeatInterval(long heartbeatInterval)
In order to keep proxies and load balancers from closing long running HTTP requests we need to pretend that the connection is active and send a heartbeat packet once in a while. This setting controls how often this is done.Defaults to 25 seconds.
- Parameters:
heartbeatInterval- interval in milliseconds- Returns:
- a reference to this, so the API can be used fluently
-
getMaxBytesStreaming
public int getMaxBytesStreaming()
- Returns:
- maximum number of bytes an HTTP streaming request can send
-
setMaxBytesStreaming
public SockJSHandlerOptions setMaxBytesStreaming(int maxBytesStreaming)
Most streaming transports save responses on the client side and don't free memory used by delivered messages. Such transports need to be garbage-collected once in a while.This setting controls the maximum number of bytes that can be sent over a single HTTP streaming request before it will be closed. After that the client needs to open new request. Setting this value to one effectively disables streaming and will make streaming transports to behave like polling transports.
Defaults to 128K.
- Parameters:
maxBytesStreaming- maximum number of bytes an HTTP streaming request can send- Returns:
- a reference to this, so the API can be used fluently
-
getLibraryURL
public String getLibraryURL()
- Returns:
- the SockJS library URL to load in iframe when a transport does not support cross-domain communication natively
-
setLibraryURL
public SockJSHandlerOptions setLibraryURL(String libraryURL)
Transports which don't support cross-domain communication natively use an iframe trick. A simple page is served from the SockJS server (using its foreign domain) and is placed in an invisible iframe.Code run from this iframe doesn't need to worry about cross-domain issues, as it's being run from domain local to the SockJS server. This iframe also does need to load SockJS javascript client library, and this option lets you specify its URL.
- Parameters:
libraryURL- the SockJS library URL- Returns:
- a reference to this, so the API can be used fluently
-
addDisabledTransport
public SockJSHandlerOptions addDisabledTransport(String subProtocol)
Add a transport (by name) to the set of disabled transports.- Parameters:
subProtocol- the transport to disable- Returns:
- a reference to this, so the API can be used fluently
- See Also:
Transport
-
getDisabledTransports
public Set<String> getDisabledTransports()
- Returns:
- the set of transports to disable
-
isRegisterWriteHandler
public boolean isRegisterWriteHandler()
- Returns:
- true if a
writeHandlershould be registered on theEventBus, false otherwise - See Also:
SockJSSocket.writeHandlerID()
-
setRegisterWriteHandler
public SockJSHandlerOptions setRegisterWriteHandler(boolean registerWriteHandler)
- Parameters:
registerWriteHandler- true to register awriteHandler- Returns:
- a reference to this, so the API can be used fluently
- See Also:
SockJSSocket.writeHandlerID()
-
isLocalWriteHandler
public boolean isLocalWriteHandler()
- Returns:
- true if the
writeHandleris local only, false otherwise - See Also:
SockJSSocket.writeHandlerID()
-
setLocalWriteHandler
public SockJSHandlerOptions setLocalWriteHandler(boolean localWriteHandler)
Whether thewriteHandlershould be local only or cluster-wide.Defaults to
true.- Parameters:
localWriteHandler- true to register locally, false otherwise- Returns:
- a reference to this, so the API can be used fluently
- See Also:
SockJSSocket.writeHandlerID()
-
getOrigin
public String getOrigin()
- Returns:
- the origin associated with this bridge
-
setOrigin
public SockJSHandlerOptions setOrigin(String origin)
Set the origin to be verified before a websocket upgrade happens.Defaults to
null.- Parameters:
origin- web origin- Returns:
- a reference to this, so the API can be used fluently
-
-