4
4
package com .azure .security .attestation ;
5
5
6
6
import com .azure .core .annotation .ServiceClientBuilder ;
7
+ import com .azure .core .client .traits .ConfigurationTrait ;
8
+ import com .azure .core .client .traits .EndpointTrait ;
9
+ import com .azure .core .client .traits .HttpTrait ;
10
+ import com .azure .core .client .traits .TokenCredentialTrait ;
7
11
import com .azure .core .credential .TokenCredential ;
8
12
import com .azure .core .http .HttpClient ;
9
13
import com .azure .core .http .HttpHeader ;
15
19
import com .azure .core .http .policy .AddHeadersFromContextPolicy ;
16
20
import com .azure .core .http .policy .AddHeadersPolicy ;
17
21
import com .azure .core .http .policy .BearerTokenAuthenticationPolicy ;
22
+ import com .azure .core .http .policy .HttpLogDetailLevel ;
18
23
import com .azure .core .http .policy .HttpLogOptions ;
19
24
import com .azure .core .http .policy .HttpLoggingPolicy ;
20
25
import com .azure .core .http .policy .HttpPipelinePolicy ;
21
26
import com .azure .core .http .policy .HttpPolicyProviders ;
22
27
import com .azure .core .http .policy .RequestIdPolicy ;
28
+ import com .azure .core .http .policy .RetryOptions ;
23
29
import com .azure .core .http .policy .RetryPolicy ;
24
30
import com .azure .core .http .policy .UserAgentPolicy ;
25
31
import com .azure .core .util .ClientOptions ;
26
32
import com .azure .core .util .Configuration ;
27
33
import com .azure .core .util .CoreUtils ;
34
+ import com .azure .core .util .HttpClientOptions ;
35
+ import com .azure .core .util .builder .ClientBuilderUtil ;
28
36
import com .azure .core .util .logging .ClientLogger ;
29
37
import com .azure .core .util .serializer .JacksonAdapter ;
30
38
import com .azure .security .attestation .implementation .AttestationClientImpl ;
115
123
AttestationAdministrationClient .class ,
116
124
AttestationAdministrationAsyncClient .class ,
117
125
})
118
- public final class AttestationAdministrationClientBuilder {
126
+ public final class AttestationAdministrationClientBuilder implements
127
+ ConfigurationTrait <AttestationAdministrationClientBuilder >,
128
+ EndpointTrait <AttestationAdministrationClientBuilder >,
129
+ HttpTrait <AttestationAdministrationClientBuilder >,
130
+ TokenCredentialTrait <AttestationAdministrationClientBuilder > {
119
131
private static final String SDK_NAME = "name" ;
120
132
private static final String SDK_VERSION = "version" ;
121
133
private static final RetryPolicy DEFAULT_RETRY_POLICY = new RetryPolicy ("retry-after-ms" , ChronoUnit .MILLIS );
@@ -134,6 +146,7 @@ public final class AttestationAdministrationClientBuilder {
134
146
private HttpLogOptions httpLogOptions ;
135
147
private HttpPipeline pipeline ;
136
148
private HttpPipelinePolicy retryPolicy ;
149
+ private RetryOptions retryOptions ;
137
150
private Configuration configuration ;
138
151
private AttestationServiceVersion serviceVersion ;
139
152
private AttestationTokenValidationOptions tokenValidationOptions ;
@@ -170,6 +183,8 @@ public AttestationAdministrationClientBuilder() {
170
183
* </pre>
171
184
* <!-- end com.azure.security.attestation.AttestationAdministrationClientBuilder.buildClient -->
172
185
* @return an instance of {@link AttestationClient}.
186
+ * @throws IllegalStateException If both {@link #retryOptions(RetryOptions)}
187
+ * and {@link #retryPolicy(RetryPolicy)} have been set.
173
188
*/
174
189
public AttestationAdministrationClient buildClient () {
175
190
return new AttestationAdministrationClient (buildAsyncClient ());
@@ -189,6 +204,8 @@ public AttestationAdministrationClient buildClient() {
189
204
* </pre>
190
205
* <!-- end com.azure.security.attestation.AttestationAdministrationClientBuilder.buildAsyncClient -->
191
206
* @return an instance of {@link AttestationClient}.
207
+ * @throws IllegalStateException If both {@link #retryOptions(RetryOptions)}
208
+ * and {@link #retryPolicy(RetryPolicy)} have been set.
192
209
*/
193
210
public AttestationAdministrationAsyncClient buildAsyncClient () {
194
211
return new AttestationAdministrationAsyncClient (buildInnerClient (), this .tokenValidationOptions );
@@ -201,6 +218,7 @@ public AttestationAdministrationAsyncClient buildAsyncClient() {
201
218
* @param endpoint The endpoint to connect to.
202
219
* @return the AttestationClientBuilder.
203
220
*/
221
+ @ Override
204
222
public AttestationAdministrationClientBuilder endpoint (String endpoint ) {
205
223
Objects .requireNonNull (endpoint );
206
224
try {
@@ -223,55 +241,87 @@ public AttestationAdministrationClientBuilder serviceVersion(AttestationServiceV
223
241
return this ;
224
242
}
225
243
/**
226
- * Sets the credential to be used for communicating with the service.
227
- * @param credential Specifies the credential to be used for authentication.
244
+ * Sets the {@link TokenCredential} used to authorize requests sent to the service. Refer to the Azure SDK for Java
245
+ * <a href="https://aka.ms/azsdk/java/docs/identity">identity and authentication</a>
246
+ * documentation for more details on proper usage of the {@link TokenCredential} type.
247
+ *
248
+ * @param credential {@link TokenCredential} used to authorize requests sent to the service.
228
249
* @return the AttestationClientBuilder.
229
250
*/
251
+ @ Override
230
252
public AttestationAdministrationClientBuilder credential (TokenCredential credential ) {
231
253
Objects .requireNonNull (credential );
232
254
this .tokenCredential = credential ;
233
255
return this ;
234
256
}
235
257
236
258
/**
237
- * Sets The HTTP pipeline to send requests through.
259
+ * Sets the {@link HttpPipeline} to use for the service client.
260
+ *
261
+ * <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
262
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
263
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
264
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
265
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
266
+ * documentation of types that implement this trait to understand the full set of implications.</p>
238
267
*
239
- * @param pipeline the pipeline value .
268
+ * @param pipeline {@link HttpPipeline} to use for sending service requests and receiving responses .
240
269
* @return the AttestationClientBuilder.
241
270
*/
271
+ @ Override
242
272
public AttestationAdministrationClientBuilder pipeline (HttpPipeline pipeline ) {
243
273
this .pipeline = pipeline ;
244
274
return this ;
245
275
}
246
276
247
277
/**
248
- * Sets The HTTP client used to send the request.
278
+ * Sets the {@link HttpClient} to use for sending and receiving requests to and from the service.
279
+ *
280
+ * <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
281
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
282
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
283
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
284
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
285
+ * documentation of types that implement this trait to understand the full set of implications.</p>
249
286
*
250
- * @param httpClient the httpClient value .
287
+ * @param httpClient The {@link HttpClient} to use for requests .
251
288
* @return the AttestationClientBuilder.
252
289
*/
290
+ @ Override
253
291
public AttestationAdministrationClientBuilder httpClient (HttpClient httpClient ) {
254
292
this .httpClient = httpClient ;
255
293
return this ;
256
294
}
257
295
258
296
/**
259
- * Sets The configuration store that is used during construction of the service client.
297
+ * Sets the client-specific configuration used to retrieve client or global configuration properties
298
+ * when building a client.
260
299
*
261
- * @param configuration the configuration value .
300
+ * @param configuration Configuration store used to retrieve client configurations .
262
301
* @return the AttestationClientBuilder.
263
302
*/
303
+ @ Override
264
304
public AttestationAdministrationClientBuilder configuration (Configuration configuration ) {
265
305
this .configuration = configuration ;
266
306
return this ;
267
307
}
268
308
269
309
/**
270
- * Sets The logging configuration for HTTP requests and responses.
310
+ * Sets the {@link HttpLogOptions logging configuration} to use when sending and receiving requests to and from
311
+ * the service. If a {@code logLevel} is not provided, default value of {@link HttpLogDetailLevel#NONE} is set.
271
312
*
272
- * @param httpLogOptions the httpLogOptions value.
313
+ * <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
314
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
315
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
316
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
317
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
318
+ * documentation of types that implement this trait to understand the full set of implications.</p>
319
+ *
320
+ * @param httpLogOptions The {@link HttpLogOptions logging configuration} to use when sending and receiving requests
321
+ * to and from the service.
273
322
* @return the AttestationClientBuilder.
274
323
*/
324
+ @ Override
275
325
public AttestationAdministrationClientBuilder httpLogOptions (HttpLogOptions httpLogOptions ) {
276
326
this .httpLogOptions = httpLogOptions ;
277
327
return this ;
@@ -280,6 +330,9 @@ public AttestationAdministrationClientBuilder httpLogOptions(HttpLogOptions http
280
330
/**
281
331
* Sets The retry policy that will attempt to retry failed requests, if applicable.
282
332
*
333
+ * <p>
334
+ * Setting this is mutually exclusive with using {@link #retryOptions(RetryOptions)}.
335
+ *
283
336
* @param retryPolicy the retryPolicy value.
284
337
* @return the AttestationClientBuilder.
285
338
*/
@@ -289,27 +342,65 @@ public AttestationAdministrationClientBuilder retryPolicy(RetryPolicy retryPolic
289
342
}
290
343
291
344
/**
292
- * Sets the {@link ClientOptions} which enables various options to be set on the client. For example setting an
293
- * {@code applicationId} using {@link ClientOptions#setApplicationId(String)} to configure
294
- * the {@link UserAgentPolicy} for telemetry/monitoring purposes.
345
+ * Sets the {@link RetryOptions} for all the requests made through the client.
346
+ *
347
+ * <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
348
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
349
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
350
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
351
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
352
+ * documentation of types that implement this trait to understand the full set of implications.</p>
353
+ * <p>
354
+ * Setting this is mutually exclusive with using {@link #retryPolicy(RetryPolicy)}.
295
355
*
296
- * <p>More About <a href="https://azure.github.io/azure-sdk/general_azurecore.html#telemetry-policy">Azure Core: Telemetry policy</a>
356
+ * @param retryOptions The {@link RetryOptions} to use for all the requests made through the client.
357
+ * @return the AttestationAdministrationClientBuilder.
358
+ */
359
+ @ Override
360
+ public AttestationAdministrationClientBuilder retryOptions (RetryOptions retryOptions ) {
361
+ this .retryOptions = retryOptions ;
362
+ return this ;
363
+ }
364
+
365
+ /**
366
+ * Allows for setting common properties such as application ID, headers, proxy configuration, etc. Note that it is
367
+ * recommended that this method be called with an instance of the {@link HttpClientOptions}
368
+ * class (a subclass of the {@link ClientOptions} base class). The HttpClientOptions subclass provides more
369
+ * configuration options suitable for HTTP clients, which is applicable for any class that implements this HttpTrait
370
+ * interface.
297
371
*
298
- * @param clientOptions {@link ClientOptions}.
372
+ * <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
373
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
374
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
375
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
376
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
377
+ * documentation of types that implement this trait to understand the full set of implications.</p>
299
378
*
379
+ * @param clientOptions A configured instance of {@link HttpClientOptions}.
300
380
* @return the updated {@link AttestationAdministrationClientBuilder} object
381
+ * @see HttpClientOptions
301
382
*/
383
+ @ Override
302
384
public AttestationAdministrationClientBuilder clientOptions (ClientOptions clientOptions ) {
303
385
this .clientOptions = clientOptions ;
304
386
return this ;
305
387
}
306
388
307
389
/**
308
- * Adds a custom Http pipeline policy.
390
+ * Adds a {@link HttpPipelinePolicy pipeline policy} to apply on each request sent.
391
+ *
392
+ * <p><strong>Note:</strong> It is important to understand the precedence order of the HttpTrait APIs. In
393
+ * particular, if a {@link HttpPipeline} is specified, this takes precedence over all other APIs in the trait, and
394
+ * they will be ignored. If no {@link HttpPipeline} is specified, a HTTP pipeline will be constructed internally
395
+ * based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this
396
+ * trait that are also ignored if an {@link HttpPipeline} is specified, so please be sure to refer to the
397
+ * documentation of types that implement this trait to understand the full set of implications.</p>
309
398
*
310
- * @param policy The custom Http pipeline policy to add .
399
+ * @param policy A {@link HttpPipelinePolicy pipeline policy} .
311
400
* @return this {@link AttestationAdministrationClientBuilder}.
401
+ * @throws NullPointerException If {@code pipelinePolicy} is {@code null}.
312
402
*/
403
+ @ Override
313
404
public AttestationAdministrationClientBuilder addPolicy (HttpPipelinePolicy policy ) {
314
405
Objects .requireNonNull (policy , "'policy' cannot be null." );
315
406
@@ -389,7 +480,7 @@ private AttestationClientImpl buildInnerClient() {
389
480
policies .addAll (perCallPolicies );
390
481
HttpPolicyProviders .addBeforeRetryPolicies (policies );
391
482
392
- policies .add (retryPolicy == null ? DEFAULT_RETRY_POLICY : retryPolicy );
483
+ policies .add (ClientBuilderUtil . validateAndGetRetryPolicy ( retryPolicy , retryOptions , DEFAULT_RETRY_POLICY ) );
393
484
394
485
policies .add (new AddDatePolicy ());
395
486
0 commit comments