Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
Expand All @@ -21,8 +20,8 @@
import com.azure.core.http.policy.AddHeadersFromContextPolicy;
import com.azure.core.http.policy.AddHeadersPolicy;
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpLoggingPolicy;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.HttpPolicyProviders;
import com.azure.core.http.policy.RequestIdPolicy;
Expand Down Expand Up @@ -84,7 +83,7 @@ public EasmClientBuilder() {
@Override
public EasmClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down Expand Up @@ -213,60 +212,6 @@ public EasmClientBuilder endpoint(String endpoint) {
return this;
}

/*
* The ID of the target subscription.
*/
@Generated
private String subscriptionId;

/**
* Sets The ID of the target subscription.
*
* @param subscriptionId the subscriptionId value.
* @return the EasmClientBuilder.
*/
@Generated
public EasmClientBuilder subscriptionId(String subscriptionId) {
this.subscriptionId = subscriptionId;
return this;
}

/*
* The name of the Resource Group.
*/
@Generated
private String resourceGroupName;

/**
* Sets The name of the Resource Group.
*
* @param resourceGroupName the resourceGroupName value.
* @return the EasmClientBuilder.
*/
@Generated
public EasmClientBuilder resourceGroupName(String resourceGroupName) {
this.resourceGroupName = resourceGroupName;
return this;
}

/*
* The name of the Workspace.
*/
@Generated
private String workspaceName;

/**
* Sets The name of the Workspace.
*
* @param workspaceName the workspaceName value.
* @return the EasmClientBuilder.
*/
@Generated
public EasmClientBuilder workspaceName(String workspaceName) {
this.workspaceName = workspaceName;
return this;
}

/*
* Service version
*/
Expand Down Expand Up @@ -310,11 +255,12 @@ public EasmClientBuilder retryPolicy(RetryPolicy retryPolicy) {
*/
@Generated
private EasmClientImpl buildInnerClient() {
this.validateClient();
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();
EasmServiceVersion localServiceVersion
= (serviceVersion != null) ? serviceVersion : EasmServiceVersion.getLatest();
EasmClientImpl client = new EasmClientImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter(),
this.endpoint, this.subscriptionId, this.resourceGroupName, this.workspaceName, localServiceVersion);
this.endpoint, localServiceVersion);
return client;
}

Expand All @@ -331,26 +277,28 @@ private HttpPipeline createHttpPipeline() {
policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration));
policies.add(new RequestIdPolicy());
policies.add(new AddHeadersFromContextPolicy());
HttpHeaders headers = new HttpHeaders();
localClientOptions.getHeaders()
.forEach(header -> headers.set(HttpHeaderName.fromString(header.getName()), header.getValue()));
if (headers.getSize() > 0) {
HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions);
if (headers != null) {
policies.add(new AddHeadersPolicy(headers));
}
this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
this.pipelinePolicies.stream()
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
.forEach(p -> policies.add(p));
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy()));
policies.add(new AddDatePolicy());
if (tokenCredential != null) {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
}
this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
this.pipelinePolicies.stream()
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
.forEach(p -> policies.add(p));
HttpPolicyProviders.addAfterRetryPolicies(policies);
policies.add(new HttpLoggingPolicy(localHttpLogOptions));
HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0]))
.httpClient(httpClient).clientOptions(localClientOptions).build();
.httpClient(httpClient)
.clientOptions(localClientOptions)
.build();
return httpPipeline;
}

Expand All @@ -375,4 +323,11 @@ public EasmClient buildClient() {
}

private static final ClientLogger LOGGER = new ClientLogger(EasmClientBuilder.class);

@Generated
private void validateClient() {
// This method is invoked from 'buildInnerClient'/'buildClient' method.
// Developer can customize this method, to validate that the necessary conditions are met for the new client.
Objects.requireNonNull(endpoint, "'endpoint' cannot be null.");
}
}
Loading