Class RequestHeaderAccessor
java.lang.Object
com.sap.cloud.sdk.cloudplatform.requestheader.RequestHeaderAccessor
Accessor for retrieving the
RequestHeaderContainer
of the current context.-
Method Summary
Modifier and TypeMethodDescriptionstatic void
executeWithFallbackHeaderContainer
(Supplier<RequestHeaderContainer> headers, Executable executable) Runs the givenexecutable
with the givenheaders
as a fallback option that should be used in case there is no currentRequestHeaderContainer
.static <T> T
executeWithFallbackHeaderContainer
(Supplier<RequestHeaderContainer> headers, Callable<T> callable) Runs the givencallable
with the givenheaders
as a fallback option that should be used in case there is no currentRequestHeaderContainer
.static void
executeWithHeaderContainer
(RequestHeaderContainer headers, Executable executable) Runs the givenexecutable
with the givenheaders
available.static <T> T
executeWithHeaderContainer
(RequestHeaderContainer headers, Callable<T> callable) Runs the givencallable
with the givenheaders
available and returns the result.static void
executeWithHeaderContainer
(Map<String, String> headers, Executable executable) Runs the givenexecutable
with the givenheaders
available.static <T> T
executeWithHeaderContainer
(Map<String, String> headers, Callable<T> callable) Runs the givencallable
with the givenheaders
available and returns the result.static Supplier<RequestHeaderContainer>
static RequestHeaderContainer
Returns the currentRequestHeaderContainer
.static RequestHeaderFacade
static void
setFallbackHeaderContainer
(Supplier<RequestHeaderContainer> fallbackHeaderContainer) static void
setHeaderFacade
(RequestHeaderFacade requestHeaderFacade) Sets theRequestHeaderFacade
to use.static io.vavr.control.Try<RequestHeaderContainer>
Tries to get the currentRequestHeaderContainer
.
-
Method Details
-
setHeaderFacade
Sets theRequestHeaderFacade
to use.- Parameters:
requestHeaderFacade
- TheRequestHeaderFacade
to use, ornull
if the defaultRequestHeaderFacade
should be used.
-
getHeaderContainer
@Nonnull public static RequestHeaderContainer getHeaderContainer() throws RequestHeadersAccessExceptionReturns the currentRequestHeaderContainer
.- Returns:
- The
RequestHeaderContainer
for the current context. - Throws:
RequestHeadersAccessException
- If the currentRequestHeaderContainer
cannot be accessed.
-
tryGetHeaderContainer
Tries to get the currentRequestHeaderContainer
.- Returns:
- A
Try
that might contain the currentRequestHeaderContainer
.
-
executeWithHeaderContainer
public static void executeWithHeaderContainer(@Nonnull Map<String, String> headers, @Nonnull Executable executable) throws ThreadContextExecutionExceptionRuns the givenexecutable
with the givenheaders
available.- Parameters:
headers
- The HTTP headers (name-value pairs) that should be available within theexecutable
.executable
- TheExecutable
to execute.- Throws:
ThreadContextExecutionException
- If there is an issue when running theexecutable
.
-
executeWithHeaderContainer
public static void executeWithHeaderContainer(@Nonnull RequestHeaderContainer headers, @Nonnull Executable executable) throws ThreadContextExecutionException Runs the givenexecutable
with the givenheaders
available.- Parameters:
headers
- TheRequestHeaderContainer
that should be available within theexecutable
.executable
- TheRunnable
to execute.- Throws:
ThreadContextExecutionException
- If there is an issue when running theexecutable
.
-
executeWithHeaderContainer
@Nullable public static <T> T executeWithHeaderContainer(@Nonnull Map<String, String> headers, @Nonnull Callable<T> callable) throws ThreadContextExecutionExceptionRuns the givencallable
with the givenheaders
available and returns the result.- Type Parameters:
T
- The result type of the givencallable
.- Parameters:
headers
- The HTTP headers (name-value pairs) that should be available within thecallable
.callable
- TheCallable
to run.- Returns:
- The result of the
callable
. - Throws:
ThreadContextExecutionException
- If there is an issue while running the givencallable
.
-
executeWithHeaderContainer
@Nullable public static <T> T executeWithHeaderContainer(@Nonnull RequestHeaderContainer headers, @Nonnull Callable<T> callable) throws ThreadContextExecutionException Runs the givencallable
with the givenheaders
available and returns the result.- Type Parameters:
T
- The result type of the givencallable
.- Parameters:
headers
- TheRequestHeaderContainer
that should be available within thecallable
.callable
- TheCallable
to run.- Returns:
- The result of the
callable
. - Throws:
ThreadContextExecutionException
- If there is an issue while running the givencallable
.
-
executeWithFallbackHeaderContainer
public static void executeWithFallbackHeaderContainer(@Nonnull Supplier<RequestHeaderContainer> headers, @Nonnull Executable executable) throws ThreadContextExecutionException Runs the givenexecutable
with the givenheaders
as a fallback option that should be used in case there is no currentRequestHeaderContainer
.- Parameters:
headers
- The fallbackRequestHeaderContainer
.executable
- TheExecutable
to run.- Throws:
ThreadContextExecutionException
- If there is an issue while running the givenexecutable
.
-
executeWithFallbackHeaderContainer
@Nullable public static <T> T executeWithFallbackHeaderContainer(@Nonnull Supplier<RequestHeaderContainer> headers, @Nonnull Callable<T> callable) throws ThreadContextExecutionException Runs the givencallable
with the givenheaders
as a fallback option that should be used in case there is no currentRequestHeaderContainer
.- Type Parameters:
T
- The return type of the givencallable
.- Parameters:
headers
- The fallbackRequestHeaderContainer
.callable
- TheCallable
to run.- Returns:
- The result of the given
callable
. - Throws:
ThreadContextExecutionException
- If there is an issue while running the givencallable
.
-
getHeaderFacade
-
getFallbackHeaderContainer
-
setFallbackHeaderContainer
public static void setFallbackHeaderContainer(@Nullable Supplier<RequestHeaderContainer> fallbackHeaderContainer)
-