Interface WebContext
public interface WebContext
Allows a Rest or WebSocket Service to communicate with NetSwitch.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName used withServletContext#getAttribute(String)to retrieve an instance ofWebContext. -
Method Summary
Modifier and TypeMethodDescription<T> TexecuteSQL(String poolName, SQLExecutor<T> executor) Allocates a connection from the specified pool and then executes the supplied SQL executor.Returns an unmodifiable map with all the properties of this WebContext.getProperty(String name, String defval) Returns the value of the property indexed by specified name.voidSends a mail message using the specified SMTP mail session.voidsendMulticast(String name, Serializable data) Sends an multicast message built using the suppliednameanddata.sendRequest(String destination, Serializable data, int timeout) Sends a request message to adestinationand then blocks waiting for the reply message for at mosttimeoutmilliseconds.
-
Field Details
-
ATTRIBUTE_NAME
Name used withServletContext#getAttribute(String)to retrieve an instance ofWebContext.- See Also:
-
-
Method Details
-
getProperties
-
getProperty
Returns the value of the property indexed by specified name. If the property is not defined, it returns the supplied default value.- Parameters:
name- the name of the required property.defval- value returned if property is not defined (can be null).- Returns:
- the value of the property or default value
defval. - Throws:
NullPointerException- ifnameisnull.
-
sendMail
Sends a mail message using the specified SMTP mail session.- Parameters:
sessionName- the name of the mail session.subject- the subject of the mail message.text- the text of the mail message.- Throws:
NullPointerException- if an argument isnull.Exception- if another error occurs.
-
sendMulticast
Sends an multicast message built using the suppliednameanddata. The message will be dispatched to all client and/or server applications that have enabled the reception of multicast messages with the specifiedname.- Parameters:
name- the name of the multicast message.data- data to include in the multicast message (can be null).- Throws:
NullPointerException- ifnameisnull.Exception- if another error occurs.
-
sendRequest
Sends a request message to adestinationand then blocks waiting for the reply message for at mosttimeoutmilliseconds. The value ofdestinationmust have the following format:[SwitchName:]ServerName[.ServiceName]
where optional items are shown within"["and"]"brackets, and the characters":"and"."stand for themselves. If the optionalSwitchNameis not specified, the message is sent to the connected switch.ServerNameis the name of a server, a listener or a connector. The optionalServiceNameis the name of a service provided by the server, or the name of a channel of a listener. The following are examples of valid destinations:POS_DEVICE NETSWITCH.LOG_ERROR HUB:IMSER.ADD_CONTACT
Argumenttimeoutspecifies the amount of time to wait for the synchronous reply message. Iftimeoutis zero (0), the call waits forever for the reply message.- Parameters:
destination- the request destinationswitch:server.service.data- the data to include in the request message (can be null).timeout- the maximum time to wait for a reply (in milliseconds).- Returns:
- the reply message returned from the switch server.
- Throws:
NullPointerException- ifdestinationisnull.IllegalArgumentException- iftimeoutis negative.IllegalStateException- if already waiting for a reply message.SocketTimeoutException- iftimeoutexpired while waiting for reply.Exception- if another error occurs.
-
executeSQL
Allocates a connection from the specified pool and then executes the supplied SQL executor. If the SQL executor returns normally, the connection is committed. If the SQL executor throws an exception, the connection is rollback. In any event, the connection is returned to the pool.- Type Parameters:
T- the type of the value returned by theexecutor.- Parameters:
poolName- the name of the connection pool.executor- an SQL statement executor.- Returns:
- the value returned by the
executor. - Throws:
NullPointerException- if an argument isnull.SQLException- if an SQL error occurs.Exception- if another error occurs.
-