public class RequestContextExecutor extends BaseRequestContextExecutor<RequestContextExecutor>
Callable
or Executable
within a RequestContext
.
Usually, a RequestContext
is initialized by a RequestContextServletFilter
. However, for tasks that
are not triggered by a request (such as background jobs), the servlet filter is not executed. Therefore, in such
cases, this class provides a wrapper that initializes the required RequestContext
.
For example:
new RequestContextExecutor().execute(() -> {
// code that is executed within the RequestContext created by RequestContextExecutor
new MyODataService().getAllEntities().top(10).execute();
});
Note: Please be aware that if you pass a RequestContext
to the executor, you have to make
sure that this context is not destroyed during execution, for example, within asynchronous tasks. You should
therefore only pass a RequestContext
for which you manage the lifecycle yourself. In addition, you have to
consider that an already existing RequestContext
would result in an exception since nesting of
RequestContext
s is not allowed by default. You would have to allow this behavior using
BaseRequestContextExecutor.withParentRequestContext()
.
Constructor and Description |
---|
RequestContextExecutor() |
Modifier and Type | Method and Description |
---|---|
protected RequestContextExecutor |
getThis()
Getter needed to allow for a type safe return in the builder methods.
|
execute, execute, withListeners, withoutDefaultListeners, withoutListener, withoutListeners, withParentRequestContext, withRequestContext
@Nonnull protected RequestContextExecutor getThis()
BaseRequestContextExecutor
protected ImplementingType getThis() { return this; }in the subclasses.
getThis
in class BaseRequestContextExecutor<RequestContextExecutor>
Copyright © 2019 SAP SE. All rights reserved.