ResponseTransformer (AWS SDK for Java

May 2024 ยท 5 minute read
ResponseTransformer (AWS SDK for Java - 2.25.21) Type Parameters: ResponseT - Type of unmarshalled POJO response. ReturnT - Return type of the transform(Object, AbortableInputStream) method. Implementations are free to perform whatever transformations are appropriate. Functional Interface: This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference. Interface for processing a streaming response from a service in a synchronous fashion. This interfaces gives access to the unmarshalled response POJO which may contain metadata about the streamed contents. It also provides access to the content via an AbortableInputStream. Callers do not need to worry about calling InputStream.close() on the content, but if they wish to stop reading data from the stream AbortableInputStream.abort() may be called to kill the underlying HTTP connection. This is generally not recommended and should only be done when the cost of reading the rest of the data exceeds the cost of establishing a new connection. If callers do not call abort and do not read all of the data in the stream, then the content will be drained by the SDK and the underlying HTTP connection will be returned to the connection pool (if applicable).

Retries

Exceptions thrown from the transformer's transform(Object, AbortableInputStream) method are not automatically retried by the RetryPolicy of the client. Since we can't know if a transformer implementation is idempotent or safe to retry, if you wish to retry on the event of a failure you must throw a SdkException with retryable set to true from the transformer. This exception can wrap the original exception that was thrown. Note that throwing a SdkException that is marked retryable from the transformer does not guarantee the request will be retried, retries are still limited by the max retry attempts and retry throttling feature of the RetryPolicy.

Thread Interrupts

Implementations should have proper handling of Thread interrupts. For long running, non-interruptible tasks, it is recommended to check the thread interrupt status periodically and throw an InterruptedException if set. When an InterruptedException is thrown from a interruptible task, you should either re-interrupt the current thread and return or throw that InterruptedException from the transform(Object, AbortableInputStream) method. Failure to do these things may prevent the SDK from stopping the request in a timely manner in the event the thread is interrupted externally.

ncG1vNJzZmirlKB7ornAs6anmaeoe6S7zGihmq6RZK6xtY6lmK2do6l8tLvFra6aqpVkrq6t2ailaJmnqMClt46cpqudX6jGr6%2BOi5ysqJ%2BjwKag0ZqlrJ6fp7qmvo2hq6ak