ExecutionInterceptor (AWS SDK for Java

Interceptor Hooks Methods for a given interceptor are executed in a predictable order, each receiving the information that is known about the message so far as well as a ExecutionAttributes object for storing data that is specific to a particular execution.

An interceptor that is invoked during the execution lifecycle of a request/response (execution). This can be used to publish metrics, modify a request in-flight, debug request processing, view exceptions, etc. This interface exposes different methods for hooking into different parts of the lifecycle of an execution.

Interceptor Hooks Methods for a given interceptor are executed in a predictable order, each receiving the information that is known about the message so far as well as a ExecutionAttributes object for storing data that is specific to a particular execution.

  • beforeExecution(software.amazon.awssdk.core.interceptor.Context.BeforeExecution, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Read the request before it is modified by other interceptors.
  • modifyRequest(software.amazon.awssdk.core.interceptor.Context.ModifyRequest, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Modify the request object before it is marshalled into an HTTP request.
  • beforeMarshalling(software.amazon.awssdk.core.interceptor.Context.BeforeMarshalling, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Read the request that has potentially been modified by other request interceptors before it is marshalled into an HTTP request.
  • afterMarshalling(software.amazon.awssdk.core.interceptor.Context.AfterMarshalling, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Read the HTTP request after it is created and before it can be modified by other interceptors.
  • modifyHttpRequest(software.amazon.awssdk.core.interceptor.Context.ModifyHttpRequest, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Modify the HTTP request object before it is transmitted.
  • beforeTransmission(software.amazon.awssdk.core.interceptor.Context.BeforeTransmission, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Read the HTTP request that has potentially been modified by other request interceptors before it is sent to the service.
  • afterTransmission(software.amazon.awssdk.core.interceptor.Context.AfterTransmission, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Read the HTTP response after it is received and before it can be modified by other interceptors.
  • modifyHttpResponse(software.amazon.awssdk.core.interceptor.Context.ModifyHttpResponse, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Modify the HTTP response object before it is unmarshalled.
  • beforeUnmarshalling(software.amazon.awssdk.core.interceptor.Context.BeforeUnmarshalling, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Read the HTTP response that has potentially been modified by other request interceptors before it is unmarshalled.
  • afterUnmarshalling(software.amazon.awssdk.core.interceptor.Context.AfterUnmarshalling, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Read the response after it is created and before it can be modified by other interceptors.
  • modifyResponse(software.amazon.awssdk.core.interceptor.Context.ModifyResponse, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Modify the response object before before it is returned to the client.
  • afterExecution(software.amazon.awssdk.core.interceptor.Context.AfterExecution, software.amazon.awssdk.core.interceptor.ExecutionAttributes) - Read the response that has potentially been modified by other request interceptors.
  • An additional onExecutionFailure(software.amazon.awssdk.core.interceptor.Context.FailedExecution, software.amazon.awssdk.core.interceptor.ExecutionAttributes) method is provided that is invoked if an execution fails at any point during the lifecycle of a request, including exceptions being thrown from this or other interceptors.

    Interceptor Registration Interceptors can be registered in one of many ways.

  • Override Configuration Interceptors are the most common method for SDK users to register an interceptor. These interceptors are explicitly added to the client builder's override configuration when a client is created using the ClientOverrideConfiguration.Builder.addExecutionInterceptor(ExecutionInterceptor) method.
  • Global Interceptors are interceptors loaded from the classpath for all clients. When any service client is created by a client builder, all jars on the classpath (from the perspective of the current thread's classloader) are checked for a file named '/software/amazon/awssdk/global/handlers/execution.interceptors'. Any interceptors listed in these files (new line separated) are instantiated using their default constructor and loaded into the client.
  • Service Interceptors are interceptors loaded from the classpath for a particular service's clients. When a service client is created by a client builder, all jars on the classpath (from the perspective of the current thread's classloader) are checked for a file named '/software/amazon/awssdk/services/{service}/execution.interceptors', where {service} is the package name of the service client. Any interceptors listed in these files (new line separated) are instantiated using their default constructor and loaded into the client.
  • Interceptor Order The order in which interceptors are executed is sometimes relevant to the accuracy of the interceptor itself. For example, an interceptor that adds a field to a message should be executed before an interceptor that reads and modifies that field. Interceptor's order is determined by their method of registration. The following order is used:

  • Global Interceptors. Interceptors earlier in the classpath will be placed earlier in the interceptor order than interceptors later in the classpath. Interceptors earlier within a specific file on the classpath will be placed earlier in the order than interceptors later in the file.
  • Service Interceptors. Interceptors earlier in the classpath will be placed earlier in the interceptor order than interceptors later in the classpath. Interceptors earlier within a specific file on the classpath will be placed earlier in the order than interceptors later in the file.
  • Override Configuration Interceptors. Any interceptors registered using ClientOverrideConfiguration.Builder.addExecutionInterceptor(ExecutionInterceptor) in the order they were added.
  • When a request is being processed (up to and including beforeTransmission(software.amazon.awssdk.core.interceptor.Context.BeforeTransmission, software.amazon.awssdk.core.interceptor.ExecutionAttributes), interceptors are applied in forward-order, according to the order described above. When a response is being processed (after and including afterTransmission(software.amazon.awssdk.core.interceptor.Context.AfterTransmission, software.amazon.awssdk.core.interceptor.ExecutionAttributes), interceptors are applied in reverse-order from the order described above. This means that the last interceptors to touch the request are the first interceptors to touch the response.

    Execution Attributes ExecutionAttributes are unique to an execution (the process of an SDK processing a SdkRequest). This mutable collection of attributes is created when a call to a service client is made and can be mutated throughout the course of the client call. These attributes are made available to every interceptor hook and is available for storing data between method calls. The SDK provides some attributes automatically, available via SdkExecutionAttribute.

    ncG1vNJzZmirlKB7ornAs6anmaeoe6S7zGihmq6RZK6xtY6lmK2do6l8tLvFra6aqpVkrq6t2ailaJmnqMClt46cpqudX567tbHRnJyprJ%2BnfIbExJysraGfo5avwMSrmp6opKS%2Fb7TTpqM%3D

     Share!