1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"). 5 * You may not use this file except in compliance with the License. 6 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package software.amazon.awssdk.core.client.handler; 17 18 import java.net.URI; 19 import software.amazon.awssdk.annotations.NotThreadSafe; 20 import software.amazon.awssdk.annotations.SdkProtectedApi; 21 import software.amazon.awssdk.core.CredentialType; 22 import software.amazon.awssdk.core.Response; 23 import software.amazon.awssdk.core.SdkProtocolMetadata; 24 import software.amazon.awssdk.core.SdkRequest; 25 import software.amazon.awssdk.core.async.AsyncRequestBody; 26 import software.amazon.awssdk.core.client.config.SdkClientConfiguration; 27 import software.amazon.awssdk.core.exception.SdkException; 28 import software.amazon.awssdk.core.http.HttpResponseHandler; 29 import software.amazon.awssdk.core.interceptor.ExecutionAttribute; 30 import software.amazon.awssdk.core.interceptor.ExecutionAttributes; 31 import software.amazon.awssdk.core.runtime.transform.Marshaller; 32 import software.amazon.awssdk.core.sync.RequestBody; 33 import software.amazon.awssdk.metrics.MetricCollector; 34 35 /** 36 * Encapsulates parameters needed for a particular API call. Captures input and output pojo types. 37 * 38 * @param <InputT> Input POJO type. 39 * @param <OutputT> Output POJO type. 40 */ 41 @SdkProtectedApi 42 @NotThreadSafe 43 public final class ClientExecutionParams<InputT extends SdkRequest, OutputT> { 44 45 private InputT input; 46 private RequestBody requestBody; 47 private AsyncRequestBody asyncRequestBody; 48 private Marshaller<InputT> marshaller; 49 private HttpResponseHandler<OutputT> responseHandler; 50 private HttpResponseHandler<? extends SdkException> errorResponseHandler; 51 private HttpResponseHandler<Response<OutputT>> combinedResponseHandler; 52 private boolean fullDuplex; 53 private boolean hasInitialRequestEvent; 54 private String hostPrefixExpression; 55 private String operationName; 56 private SdkProtocolMetadata protocolMetadata; 57 private URI discoveredEndpoint; 58 private CredentialType credentialType; 59 private MetricCollector metricCollector; 60 private final ExecutionAttributes attributes = new ExecutionAttributes(); 61 private SdkClientConfiguration requestConfiguration; 62 getMarshaller()63 public Marshaller<InputT> getMarshaller() { 64 return marshaller; 65 } 66 withMarshaller(Marshaller<InputT> marshaller)67 public ClientExecutionParams<InputT, OutputT> withMarshaller(Marshaller<InputT> marshaller) { 68 this.marshaller = marshaller; 69 return this; 70 } 71 getInput()72 public InputT getInput() { 73 return input; 74 } 75 withInput(InputT input)76 public ClientExecutionParams<InputT, OutputT> withInput(InputT input) { 77 this.input = input; 78 return this; 79 } 80 getResponseHandler()81 public HttpResponseHandler<OutputT> getResponseHandler() { 82 return responseHandler; 83 } 84 withResponseHandler( HttpResponseHandler<OutputT> responseHandler)85 public ClientExecutionParams<InputT, OutputT> withResponseHandler( 86 HttpResponseHandler<OutputT> responseHandler) { 87 this.responseHandler = responseHandler; 88 return this; 89 } 90 getErrorResponseHandler()91 public HttpResponseHandler<? extends SdkException> getErrorResponseHandler() { 92 return errorResponseHandler; 93 } 94 withErrorResponseHandler( HttpResponseHandler<? extends SdkException> errorResponseHandler)95 public ClientExecutionParams<InputT, OutputT> withErrorResponseHandler( 96 HttpResponseHandler<? extends SdkException> errorResponseHandler) { 97 this.errorResponseHandler = errorResponseHandler; 98 return this; 99 } 100 101 /** 102 * Non-streaming requests can use handlers that handle both error and success as a single handler instead of 103 * submitting individual success and error handlers. This allows the protocol to have more control over how to 104 * determine success and failure from a given HTTP response. This handler is mutually exclusive to 105 * {@link #getResponseHandler()} and {@link #getErrorResponseHandler()} and an exception will be thrown if this 106 * constraint is violated. 107 */ getCombinedResponseHandler()108 public HttpResponseHandler<Response<OutputT>> getCombinedResponseHandler() { 109 return combinedResponseHandler; 110 } 111 withCombinedResponseHandler( HttpResponseHandler<Response<OutputT>> combinedResponseHandler)112 public ClientExecutionParams<InputT, OutputT> withCombinedResponseHandler( 113 HttpResponseHandler<Response<OutputT>> combinedResponseHandler) { 114 this.combinedResponseHandler = combinedResponseHandler; 115 return this; 116 } 117 getRequestBody()118 public RequestBody getRequestBody() { 119 return requestBody; 120 } 121 withRequestBody(RequestBody requestBody)122 public ClientExecutionParams<InputT, OutputT> withRequestBody(RequestBody requestBody) { 123 this.requestBody = requestBody; 124 return this; 125 } 126 getAsyncRequestBody()127 public AsyncRequestBody getAsyncRequestBody() { 128 return asyncRequestBody; 129 } 130 withAsyncRequestBody(AsyncRequestBody asyncRequestBody)131 public ClientExecutionParams<InputT, OutputT> withAsyncRequestBody(AsyncRequestBody asyncRequestBody) { 132 this.asyncRequestBody = asyncRequestBody; 133 return this; 134 } 135 isFullDuplex()136 public boolean isFullDuplex() { 137 return fullDuplex; 138 } 139 140 /** 141 * Sets whether the API is a full duplex ie, request and response are streamed in parallel. 142 */ withFullDuplex(boolean fullDuplex)143 public ClientExecutionParams<InputT, OutputT> withFullDuplex(boolean fullDuplex) { 144 this.fullDuplex = fullDuplex; 145 return this; 146 } 147 hasInitialRequestEvent()148 public boolean hasInitialRequestEvent() { 149 return hasInitialRequestEvent; 150 } 151 152 /** 153 * Sets whether this is an event streaming request over RPC. 154 */ withInitialRequestEvent(boolean hasInitialRequestEvent)155 public ClientExecutionParams<InputT, OutputT> withInitialRequestEvent(boolean hasInitialRequestEvent) { 156 this.hasInitialRequestEvent = hasInitialRequestEvent; 157 return this; 158 } 159 getOperationName()160 public String getOperationName() { 161 return operationName; 162 } 163 164 /** 165 * Sets the operation name of the API. 166 */ withOperationName(String operationName)167 public ClientExecutionParams<InputT, OutputT> withOperationName(String operationName) { 168 this.operationName = operationName; 169 return this; 170 } 171 getProtocolMetadata()172 public SdkProtocolMetadata getProtocolMetadata() { 173 return protocolMetadata; 174 } 175 176 /** 177 * Sets the protocol metadata of the API. 178 */ withProtocolMetadata(SdkProtocolMetadata protocolMetadata)179 public ClientExecutionParams<InputT, OutputT> withProtocolMetadata(SdkProtocolMetadata protocolMetadata) { 180 this.protocolMetadata = protocolMetadata; 181 return this; 182 } 183 hostPrefixExpression()184 public String hostPrefixExpression() { 185 return hostPrefixExpression; 186 } 187 188 /** 189 * Sets the resolved host prefix expression that will be added as a prefix to the original endpoint. 190 * This value is present only if the operation is tagged with endpoint trait. 191 */ hostPrefixExpression(String hostPrefixExpression)192 public ClientExecutionParams<InputT, OutputT> hostPrefixExpression(String hostPrefixExpression) { 193 this.hostPrefixExpression = hostPrefixExpression; 194 return this; 195 } 196 discoveredEndpoint()197 public URI discoveredEndpoint() { 198 return discoveredEndpoint; 199 } 200 discoveredEndpoint(URI discoveredEndpoint)201 public ClientExecutionParams<InputT, OutputT> discoveredEndpoint(URI discoveredEndpoint) { 202 this.discoveredEndpoint = discoveredEndpoint; 203 return this; 204 } 205 credentialType()206 public CredentialType credentialType() { 207 return credentialType; 208 } 209 credentialType(CredentialType credentialType)210 public ClientExecutionParams<InputT, OutputT> credentialType(CredentialType credentialType) { 211 this.credentialType = credentialType; 212 return this; 213 } 214 withMetricCollector(MetricCollector metricCollector)215 public ClientExecutionParams<InputT, OutputT> withMetricCollector(MetricCollector metricCollector) { 216 this.metricCollector = metricCollector; 217 return this; 218 } 219 putExecutionAttribute(ExecutionAttribute<T> attribute, T value)220 public <T> ClientExecutionParams<InputT, OutputT> putExecutionAttribute(ExecutionAttribute<T> attribute, T value) { 221 this.attributes.putAttribute(attribute, value); 222 return this; 223 } 224 executionAttributes()225 public ExecutionAttributes executionAttributes() { 226 return attributes; 227 } 228 getMetricCollector()229 public MetricCollector getMetricCollector() { 230 return metricCollector; 231 } 232 requestConfiguration()233 public SdkClientConfiguration requestConfiguration() { 234 return requestConfiguration; 235 } 236 withRequestConfiguration(SdkClientConfiguration requestConfiguration)237 public <T> ClientExecutionParams<InputT, OutputT> withRequestConfiguration(SdkClientConfiguration requestConfiguration) { 238 this.requestConfiguration = requestConfiguration; 239 return this; 240 } 241 } 242