Interface Policy
-
- All Known Subinterfaces:
SecurityPolicy
public interface PolicyAPolicyallows to define the actions to apply during the different request execution phases. A policy can override the default behavior (which is, doing nothing at all) to execute during request or response phase or on each message when the policy is able to work at message level. The implemented methods will be called depending on the execution phase:ExecutionPhase.REQUEST:onRequest(RequestExecutionContext)ExecutionPhase.RESPONSE:onResponse(RequestExecutionContext)ExecutionPhase.ASYNC_REQUEST:onRequest(RequestExecutionContext)andonMessageFlow(ExecutionContext, Flowable)ExecutionPhase.ASYNC_RESPONSE:onResponse(RequestExecutionContext)andonMessageFlow(ExecutionContext, Flowable)
ExecutionPhase.ASYNC_REQUESTandExecutionPhase.ASYNC_RESPONSE, theonMessage(ExecutionContext, Message)method will be called for each incoming message.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Stringid()The id of the policy (usually the same id as defined in the policy manifest)default io.reactivex.Maybe<Message>onMessage(ExecutionContext ctx, Message message)Defines the actions to perform during on each incomingMessage.default io.reactivex.Flowable<Message>onMessageFlow(ExecutionContext ctx, io.reactivex.Flowable<Message> messageFlow)Defines the actions to perform on the message flow itself.default io.reactivex.CompletableonRequest(RequestExecutionContext ctx)Define the actions to perform during theExecutionPhase.REQUESTphase.default io.reactivex.CompletableonResponse(RequestExecutionContext ctx)Define the actions to perform during theExecutionPhase.RESPONSEphase.
-
-
-
Method Detail
-
id
String id()
The id of the policy (usually the same id as defined in the policy manifest)- Returns:
- the id of the policy.
-
onRequest
default io.reactivex.Completable onRequest(RequestExecutionContext ctx)
Define the actions to perform during theExecutionPhase.REQUESTphase. TheonRequest(RequestExecutionContext)method will be called during the policy chain construction. Once built, the subscription occurs and the execution is triggered. It is important that nothing must be executed before the subscription occurs as it could lead to important side effects. GOOD, the header is added during the execution, at subscription time.Completable onRequest(final RequestExecutionContext ctx) { return Completable.fromRunnable(() -> request.headers().set("X-DummyHeader", "dummy")); }BAD, the header is added during the build of the policy chain.Completable onRequest(final RequestExecutionContext ctx) { request.headers().set("X-DummyHeader", "dummy"); return Completable.complete(); }- Parameters:
ctx- the current request execution context allowing to access the request, response and attributes.- Returns:
- a
Completablethat must complete when all the actions have been performed.
-
onResponse
default io.reactivex.Completable onResponse(RequestExecutionContext ctx)
Define the actions to perform during theExecutionPhase.RESPONSEphase. TheonResponse(RequestExecutionContext)method will be called during the policy chain construction. Once built, the subscription occurs and the execution is triggered. It is important that nothing must be executed before the subscription occurs as it could lead to important side effects. GOOD, the header is added during the execution, at subscription time.Completable onResponse(final RequestExecutionContext ctx) { return Completable.fromRunnable(() -> response.headers().set("X-DummyHeader", "dummy")); }BAD, the header is added during the build of the policy chain.Completable onResponse(final RequestExecutionContext ctx) { response.headers().set("X-DummyHeader", "dummy"); return Completable.complete(); }- Parameters:
ctx- the current request execution context allowing to access the request, response and attributes.- Returns:
- a
Completablethat must complete when all the actions have been performed.
-
onMessage
default io.reactivex.Maybe<Message> onMessage(ExecutionContext ctx, Message message)
Defines the actions to perform during on each incomingMessage.- Parameters:
ctx- the current execution context allowing to access context attributes.- Returns:
- a
Maybethat must complete when all the actions have been performed on the message. The message can be simply dropped by returningMaybe.empty().
-
onMessageFlow
default io.reactivex.Flowable<Message> onMessageFlow(ExecutionContext ctx, io.reactivex.Flowable<Message> messageFlow)
Defines the actions to perform on the message flow itself.- Parameters:
ctx- the current execution context allowing to access context attributes.- Returns:
- a
FlowableofMessage.
-
-