Interface IUiSession
-
- All Known Implementing Classes:
UiSession
@Bean public interface IUiSession
-
-
Field Summary
Fields Modifier and Type Field Description static ThreadLocal<IUiSession>
CURRENT
TheIUiSession
which is currently associated with the current thread.static String
PREFERRED_LOCALE_COOKIE_NAME
Cookie name used to store the preferred language of a user (even after user has logged out).
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
addListener(UiSessionListener listener, Integer... eventTypes)
void
confirmResponseProcessed(Long sequenceNo)
Used to confirm that the UI has successfully processed the given response sequence number.<M,A extends IJsonAdapter<M>>
AcreateJsonAdapter(M model, IJsonAdapter<?> parent)
String
createUniqueId()
javax.servlet.http.HttpServletRequest
currentHttpRequest()
javax.servlet.http.HttpServletResponse
currentHttpResponse()
JsonResponse
currentJsonResponse()
void
dispose()
Marks the UI session is disposed (irreversible) and destroys the internal data structures and references (i.e.IClientSession
getClientSession()
String
getClientSessionId()
IHttpResourceCache
getHttpResourceCache()
String
getHttpSessionId()
IJsonAdapter<?>
getJsonAdapter(String id)
Returns an existing IJsonAdapter instance for the given adapter ID.<M,A extends IJsonAdapter<M>>
AgetJsonAdapter(M model, IJsonAdapter<?> parent)
Returns an existing IJsonAdapter instance for the given model object.<M,A extends IJsonAdapter<M>>
AgetJsonAdapter(M model, IJsonAdapter<?> parent, boolean checkRoot)
<M> List<IJsonAdapter<M>>
getJsonAdapters(M model)
Returns all JSON adapters which belong to the given model object.List<IJsonAdapter<?>>
getJsonChildAdapters(IJsonAdapter<?> parent)
long
getLastAccessedTime()
String
getLogoutRedirectUrl()
<M,A extends IJsonAdapter<M>>
AgetOrCreateJsonAdapter(M model, IJsonAdapter<?> parent)
Creates a new initialized IJsonAdapter instance for the given model or returns an existing instance.IJsonAdapter<?>
getRootJsonAdapter()
String
getUiSessionId()
void
init(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, JsonStartupRequest jsonStartupReq)
boolean
isDisposed()
boolean
isInitialized()
boolean
isPersistent()
Used to mark the session as persistent which means a persistent session cookie is used and the client session will be restored after a browser restart.UiSessionListeners
listeners()
void
logout()
Called from the model after the client session has been stopped.void
processCancelRequest()
JSONObject
processFileUpload(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, IUploadable uploadable, List<org.eclipse.scout.rt.platform.resource.BinaryResource> uploadResources, Map<String,String> uploadProperties)
JSONObject
processJsonRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, JsonRequest jsonReq)
JSONObject
processSyncResponseQueueRequest(JsonRequest jsonRequest)
void
registerJsonAdapter(IJsonAdapter<?> adapter)
default void
removeListener(UiSessionListener listener, Integer... eventTypes)
void
sendDisposeAdapterEvent(IJsonAdapter<?> adapter)
Sends an explicit "disposeAdapter" event to the UI.void
sendLocaleChangedEvent(Locale locale)
Sends a "localeChanged" event to the UI.void
sendReloadPageEvent()
Sends a reload page event to trigger a page reload.void
touch()
All requests except the polling requests are calling this method from theJsonMessageRequestHandler
ReentrantLock
uiSessionLock()
Returns a reentrant lock that can be used to synchronize on theIUiSession
.void
unregisterJsonAdapter(IJsonAdapter<?> adapter)
void
updateTheme(String theme)
Sets the new theme (session & cookie) and triggers a reload of the current page in the browser.void
verifySubject(javax.servlet.http.HttpServletRequest request)
Used to verify if theSubject
we're running in should be replaced on theIClientSession
.void
waitForBackgroundJobs(JsonRequest jsonRequest, int pollWaitSeconds)
Blocks the current thread/request until a model job started by a background job has terminated.
-
-
-
Field Detail
-
CURRENT
static final ThreadLocal<IUiSession> CURRENT
TheIUiSession
which is currently associated with the current thread.
-
PREFERRED_LOCALE_COOKIE_NAME
static final String PREFERRED_LOCALE_COOKIE_NAME
Cookie name used to store the preferred language of a user (even after user has logged out).- See Also:
- Constant Field Values
-
-
Method Detail
-
uiSessionLock
ReentrantLock uiSessionLock()
Returns a reentrant lock that can be used to synchronize on theIUiSession
.
-
init
void init(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, JsonStartupRequest jsonStartupReq)
-
isInitialized
boolean isInitialized()
- Returns:
true
ifinit(HttpServletRequest, HttpServletResponse, JsonStartupRequest)
was been called. Note: This will also betrue
after the session has been disposed.
-
isPersistent
boolean isPersistent()
Used to mark the session as persistent which means a persistent session cookie is used and the client session will be restored after a browser restart.This was mainly introduced for the iOS home screen mode. If the app is running in that mode the HTTP session will be lost whenever the user leaves the app (e.g. switches to another app or just downloads a file). If persistent is set to true the client session id will be put in the local storage instead of the session storage so that it can be reused the next time the app is activated.
-
getHttpSessionId
String getHttpSessionId()
-
getUiSessionId
String getUiSessionId()
-
getClientSessionId
String getClientSessionId()
-
getClientSession
IClientSession getClientSession()
-
touch
void touch()
All requests except the polling requests are calling this method from theJsonMessageRequestHandler
Note that
HttpSession.getLastAccessedTime()
is also updated on polling requests
-
getLastAccessedTime
long getLastAccessedTime()
- Returns:
- the last access time in millis since 01.01.1970 of a request, except polling requests
see
touch()
-
dispose
void dispose()
Marks the UI session is disposed (irreversible) and destroys the internal data structures and references (i.e. it disposes the JSON adapter registry).Important: This method must only be called in a context that holds the
uiSessionLock()
! (Either the current thread or a caller that waits for the current thread.)
-
isDisposed
boolean isDisposed()
- Returns:
true
ifdispose()
has been called.
-
currentJsonResponse
JsonResponse currentJsonResponse()
- Returns:
- the current UI response that is collecting changes for the next
processJsonRequest(HttpServletRequest, HttpServletResponse, JsonRequest)
cycle. This is nevernull
, except when the UI session is disposed (seeisDisposed()
).
-
currentHttpRequest
javax.servlet.http.HttpServletRequest currentHttpRequest()
-
currentHttpResponse
javax.servlet.http.HttpServletResponse currentHttpResponse()
-
confirmResponseProcessed
void confirmResponseProcessed(Long sequenceNo)
Used to confirm that the UI has successfully processed the given response sequence number. All responses that have a sequence number<= sequenceNo
are removed from the response history.
-
verifySubject
void verifySubject(javax.servlet.http.HttpServletRequest request)
Used to verify if theSubject
we're running in should be replaced on theIClientSession
.- Parameters:
request
- the request that is checked if the update of the Subject has been requested
-
processJsonRequest
JSONObject processJsonRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, JsonRequest jsonReq)
- Returns:
- a JSON object to send back to the client or
null
if an empty response shall be sent.
-
processFileUpload
JSONObject processFileUpload(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, IUploadable uploadable, List<org.eclipse.scout.rt.platform.resource.BinaryResource> uploadResources, Map<String,String> uploadProperties)
- Parameters:
req
- the HTTP requestuploadable
- the target adapter that receives the uploaded filesuploadResources
- list of uploaded filesuploadProperties
- a map of all other submitted string properties (usually not needed)- Returns:
- a JSON object to send back to the client or
null
if an empty response shall be sent.
-
processCancelRequest
void processCancelRequest()
-
processSyncResponseQueueRequest
JSONObject processSyncResponseQueueRequest(JsonRequest jsonRequest)
-
logout
void logout()
Called from the model after the client session has been stopped.Important: Because this method internally calls
dispose()
, it must only be called in a context that holds theuiSessionLock()
! (Either the current thread or a caller that waits for the current thread.)
-
getLogoutRedirectUrl
String getLogoutRedirectUrl()
- Returns:
- the URL where to redirect the UI on logout
-
getRootJsonAdapter
IJsonAdapter<?> getRootJsonAdapter()
-
createUniqueId
String createUniqueId()
-
getJsonAdapter
IJsonAdapter<?> getJsonAdapter(String id)
Returns an existing IJsonAdapter instance for the given adapter ID.
-
getJsonAdapters
<M> List<IJsonAdapter<M>> getJsonAdapters(M model)
Returns all JSON adapters which belong to the given model object.
-
getJsonChildAdapters
List<IJsonAdapter<?>> getJsonChildAdapters(IJsonAdapter<?> parent)
-
getJsonAdapter
<M,A extends IJsonAdapter<M>> A getJsonAdapter(M model, IJsonAdapter<?> parent)
Returns an existing IJsonAdapter instance for the given model object.
-
getJsonAdapter
<M,A extends IJsonAdapter<M>> A getJsonAdapter(M model, IJsonAdapter<?> parent, boolean checkRoot)
-
getOrCreateJsonAdapter
<M,A extends IJsonAdapter<M>> A getOrCreateJsonAdapter(M model, IJsonAdapter<?> parent)
Creates a new initialized IJsonAdapter instance for the given model or returns an existing instance. As a side-effect a newly created adapter is added to the current JSON response.
-
createJsonAdapter
<M,A extends IJsonAdapter<M>> A createJsonAdapter(M model, IJsonAdapter<?> parent)
-
registerJsonAdapter
void registerJsonAdapter(IJsonAdapter<?> adapter)
-
unregisterJsonAdapter
void unregisterJsonAdapter(IJsonAdapter<?> adapter)
-
waitForBackgroundJobs
void waitForBackgroundJobs(JsonRequest jsonRequest, int pollWaitSeconds) throws InterruptedException
Blocks the current thread/request until a model job started by a background job has terminated.- Throws:
InterruptedException
-
sendLocaleChangedEvent
void sendLocaleChangedEvent(Locale locale)
Sends a "localeChanged" event to the UI. All locale-relevant data (number formats, texts map etc.) is sent along.
-
sendDisposeAdapterEvent
void sendDisposeAdapterEvent(IJsonAdapter<?> adapter)
Sends an explicit "disposeAdapter" event to the UI. Usually, JSON adapters are disposed automatically when their parent adapter is disposed. However, for some adapters this has to be done manually, because their parent is not disposed (e.g. forms).
-
sendReloadPageEvent
void sendReloadPageEvent()
Sends a reload page event to trigger a page reload.
-
updateTheme
void updateTheme(String theme)
Sets the new theme (session & cookie) and triggers a reload of the current page in the browser.
-
getHttpResourceCache
IHttpResourceCache getHttpResourceCache()
- Returns:
- The
IHttpResourceCache
to use to cache resources for thisIUiSession
.
-
listeners
UiSessionListeners listeners()
-
addListener
default void addListener(UiSessionListener listener, Integer... eventTypes)
-
removeListener
default void removeListener(UiSessionListener listener, Integer... eventTypes)
-
-