Class ThreadLocalContext
java.lang.Object
com.thingworx.webservices.context.ThreadLocalContext
@ThingworxExtensionApiClass(since={6,6},
canInstantiate=true)
public final class ThreadLocalContext
extends Object
A container for all session-managed objects.
The ThreadLocalContext class contains all objects that are tied to a request. This includes but is not limited to the session
data, the authorized account that made the request, the transaction success state, events that have been queued for processing, and the
entity (if any) the current request is being made against.
Security contexts are managed in a stack-like manner. That is, the most recently set security context is returned by
ThreadLocalContext#getSecurityContext() and clearing a
security context will move the previously set security context to the top.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic voidRemoves all queued events (if any) for the current thread.static voidstatic SecurityContextstatic voidDispatches the events queued for the current thread.static Stringstatic Objectstatic SecurityContextstatic jakarta.servlet.http.HttpSessionstatic Booleanstatic Booleanstatic Booleanstatic voidqueueEvent(ThingworxEvent event) Queues an event into the event queue for the current thread.static voidstatic voidstatic voidsetSession(jakarta.servlet.http.HttpSession value) static voidsetTransactionSuccess(boolean status)
-
Constructor Details
-
ThreadLocalContext
public ThreadLocalContext()Initializes this instace with default values.
-
-
Method Details
-
getSecurityContext
- Returns:
- The security context.
-
setSecurityContext
@ThingworxExtensionApiMethod(since={6,6}) public static void setSecurityContext(SecurityContext value) -
clearSecurityContext
-
isTraceActive
-
getMeContext
- Returns:
-
isImportActive
-
setSession
@ThingworxExtensionApiMethod(since={6,6}) public static void setSession(jakarta.servlet.http.HttpSession value) -
getSession
@ThingworxExtensionApiMethod(since={6,6}) public static jakarta.servlet.http.HttpSession getSession() -
getSessionId
-
getClientIP
-
queueEvent
Queues an event into the event queue for the current thread. This can be used to support transactional event dispatch along with thedispatchQueuedEvents()andclearQueuedEvents()methods.- Parameters:
event- the event to add to the dispatch queue
-
queuePostCommitEvent
@ThingworxExtensionApiMethod(since={9,0}) public static void queuePostCommitEvent(ThingworxEvent event) -
dispatchQueuedEvents
@ThingworxExtensionApiMethod(since={6,6}) public static void dispatchQueuedEvents() throws ExceptionDispatches the events queued for the current thread. The event queue will be empty after this method completes.- Throws:
Exception- if an exception occurred during event dispatch
-
clearQueuedEvents
Removes all queued events (if any) for the current thread. The events are not dispatched. -
clearQueuedPostCommitEvents
-
setTransactionSuccess
-
getTransactionSuccessStatus
-
cleanupContext
-