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 voidexecuteWithFallbackHeaderContainer(Supplier<RequestHeaderContainer> headers, Executable executable) Runs the givenexecutablewith the givenheadersas a fallback option that should be used in case there is no currentRequestHeaderContainer.static <T> TexecuteWithFallbackHeaderContainer(Supplier<RequestHeaderContainer> headers, Callable<T> callable) Runs the givencallablewith the givenheadersas a fallback option that should be used in case there is no currentRequestHeaderContainer.static voidexecuteWithHeaderContainer(RequestHeaderContainer headers, Executable executable) Runs the givenexecutablewith the givenheadersavailable.static <T> TexecuteWithHeaderContainer(RequestHeaderContainer headers, Callable<T> callable) Runs the givencallablewith the givenheadersavailable and returns the result.static voidexecuteWithHeaderContainer(Map<String, String> headers, Executable executable) Runs the givenexecutablewith the givenheadersavailable.static <T> TexecuteWithHeaderContainer(Map<String, String> headers, Callable<T> callable) Runs the givencallablewith the givenheadersavailable and returns the result.static Supplier<RequestHeaderContainer>static RequestHeaderContainerReturns the currentRequestHeaderContainer.static RequestHeaderFacadestatic voidsetFallbackHeaderContainer(Supplier<RequestHeaderContainer> fallbackHeaderContainer) static voidsetHeaderFacade(RequestHeaderFacade requestHeaderFacade) Sets theRequestHeaderFacadeto use.static io.vavr.control.Try<RequestHeaderContainer>Tries to get the currentRequestHeaderContainer.
-
Method Details
-
setHeaderFacade
Sets theRequestHeaderFacadeto use.- Parameters:
requestHeaderFacade- TheRequestHeaderFacadeto use, ornullif the defaultRequestHeaderFacadeshould be used.
-
getHeaderContainer
@Nonnull public static RequestHeaderContainer getHeaderContainer() throws RequestHeadersAccessExceptionReturns the currentRequestHeaderContainer.- Returns:
- The
RequestHeaderContainerfor the current context. - Throws:
RequestHeadersAccessException- If the currentRequestHeaderContainercannot be accessed.
-
tryGetHeaderContainer
Tries to get the currentRequestHeaderContainer.- Returns:
- A
Trythat might contain the currentRequestHeaderContainer.
-
executeWithHeaderContainer
public static void executeWithHeaderContainer(@Nonnull Map<String, String> headers, @Nonnull Executable executable) throws ThreadContextExecutionExceptionRuns the givenexecutablewith the givenheadersavailable.- Parameters:
headers- The HTTP headers (name-value pairs) that should be available within theexecutable.executable- TheExecutableto 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 givenexecutablewith the givenheadersavailable.- Parameters:
headers- TheRequestHeaderContainerthat should be available within theexecutable.executable- TheRunnableto 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 givencallablewith the givenheadersavailable 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- TheCallableto 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 givencallablewith the givenheadersavailable and returns the result.- Type Parameters:
T- The result type of the givencallable.- Parameters:
headers- TheRequestHeaderContainerthat should be available within thecallable.callable- TheCallableto 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 givenexecutablewith the givenheadersas a fallback option that should be used in case there is no currentRequestHeaderContainer.- Parameters:
headers- The fallbackRequestHeaderContainer.executable- TheExecutableto 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 givencallablewith the givenheadersas 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- TheCallableto 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)
-