From 865114289f6b392a644ab90057cc696ac396353e Mon Sep 17 00:00:00 2001 From: Xiaolu Dai Date: Sun, 7 Nov 2021 17:58:44 +0800 Subject: [PATCH] refactor the env post processor for Azure Core/SDK envs, add more http client configurations, fix bug --- ...ConfigurationEnvironmentPostProcessor.java | 149 +++++++++++++++--- ...ureEventHubMessagingAutoConfiguration.java | 2 + .../properties/core/client/HttpClientCP.java | 27 ++++ ...igurationEnvironmentPostProcessorTest.java | 104 ++++++++++++ .../azure/spring/core/aware/ClientAware.java | 7 + .../azure/spring/core/aware/ProxyAware.java | 2 +- .../AzureHttpProxyOptionsConverter.java | 6 +- ...AbstractAzureHttpClientBuilderFactory.java | 3 + ...s.java => AbstractAzureSdkProperties.java} | 4 +- .../client/HttpClientProperties.java | 29 ++++ .../properties/proxy/ProxyProperties.java | 12 +- .../properties/AbstractServiceProperties.java | 2 +- .../core/properties/CommonProperties.java | 4 +- 13 files changed, 315 insertions(+), 36 deletions(-) create mode 100644 sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalConfigurationEnvironmentPostProcessorTest.java rename sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/{AzureSdkProperties.java => AbstractAzureSdkProperties.java} (95%) diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalConfigurationEnvironmentPostProcessor.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalConfigurationEnvironmentPostProcessor.java index ef3a86b270822..606323545ba20 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalConfigurationEnvironmentPostProcessor.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalConfigurationEnvironmentPostProcessor.java @@ -3,56 +3,153 @@ package com.azure.spring.cloud.autoconfigure.context; -import com.azure.core.util.Configuration; -import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; -import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.env.EnvironmentPostProcessor; import org.springframework.core.Ordered; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; import static com.azure.core.util.Configuration.PROPERTY_AZURE_AUTHORITY_HOST; import static com.azure.core.util.Configuration.PROPERTY_AZURE_CLIENT_CERTIFICATE_PATH; import static com.azure.core.util.Configuration.PROPERTY_AZURE_CLIENT_ID; import static com.azure.core.util.Configuration.PROPERTY_AZURE_CLIENT_SECRET; +import static com.azure.core.util.Configuration.PROPERTY_AZURE_CLOUD; +import static com.azure.core.util.Configuration.PROPERTY_AZURE_HTTP_LOG_DETAIL_LEVEL; import static com.azure.core.util.Configuration.PROPERTY_AZURE_PASSWORD; +import static com.azure.core.util.Configuration.PROPERTY_AZURE_REQUEST_RETRY_COUNT; +import static com.azure.core.util.Configuration.PROPERTY_AZURE_SUBSCRIPTION_ID; import static com.azure.core.util.Configuration.PROPERTY_AZURE_TENANT_ID; import static com.azure.core.util.Configuration.PROPERTY_AZURE_USERNAME; /** - * An EnvironmentPostProcessor to set spring.cloud.azure.* properties to Azure SDK global configuration. + * An EnvironmentPostProcessor to convert environment variables predefined by Azure Core and Azure SDKs to Azure Spring + * properties, and add a property source for them as well. */ public class AzureGlobalConfigurationEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { - public static final String CREDENTIAL_PREFIX = AzureGlobalProperties.PREFIX + ".credential."; - public static final String PROFILE_PREFIX = AzureGlobalProperties.PREFIX + ".profile."; + private static final Logger LOGGER = LoggerFactory.getLogger(AzureGlobalConfigurationEnvironmentPostProcessor.class); @Override public int getOrder() { return Ordered.LOWEST_PRECEDENCE; } + + enum AzureCoreEnvMapping { + + clientId(PROPERTY_AZURE_CLIENT_ID, "credential.client-id"), + + clientSecret(PROPERTY_AZURE_CLIENT_SECRET, "credential.client-secret"), + + clientCertificatePath(PROPERTY_AZURE_CLIENT_CERTIFICATE_PATH, "credential.client-certificate-path"), + + username(PROPERTY_AZURE_USERNAME, "credential.username"), + + password(PROPERTY_AZURE_PASSWORD, "credential.password"), + + tenantId(PROPERTY_AZURE_TENANT_ID, "profile.tenant-id"), + + subscriptionId(PROPERTY_AZURE_SUBSCRIPTION_ID, "profile.subscription-id"), + + azureCloud(PROPERTY_AZURE_CLOUD, "profile.cloud"), + + authorityHost(PROPERTY_AZURE_AUTHORITY_HOST, "profile.environment.active-directory-endpoint"), + + // TODO (xiada): PROPERTY_AZURE_LOG_LEVEL, how to set this to env? + + httpLogLevel(PROPERTY_AZURE_HTTP_LOG_DETAIL_LEVEL, "client.logging.level"), + + maxRetry(PROPERTY_AZURE_REQUEST_RETRY_COUNT, "retry.max-attempts"); + + // TODO (xiada): we can't configure http at global level: + // PROPERTY_AZURE_REQUEST_CONNECT_TIMEOUT, + // PROPERTY_AZURE_REQUEST_WRITE_TIMEOUT, + // PROPERTY_AZURE_REQUEST_RESPONSE_TIMEOUT, + // PROPERTY_AZURE_REQUEST_READ_TIMEOUT, + // PROPERTY_NO_PROXY + + // TODO (xiada): how to set this proxy? + // proxy(PROPERTY_HTTP_PROXY, PROPERTY_HTTPS_PROXY) + + + private final String coreEnvName; + private final String springPropertyName; + private final Function converter; + + AzureCoreEnvMapping(String coreEnvName, String springPropertyName) { + this(coreEnvName, springPropertyName, Function.identity()); + } + + AzureCoreEnvMapping(String coreEnvName, String springPropertyName, Function converter) { + this.coreEnvName = coreEnvName; + this.springPropertyName = "spring.cloud.azure." + springPropertyName; + this.converter = converter; + } + } + + enum AzureSdkEnvMapping { + keyVaultSecretEndpoint("AZURE_KEYVAULT_ENDPOINT", "keyvault.secret.endpoint"), + keyVaultCertificateEndpoint("AZURE_KEYVAULT_ENDPOINT", "keyvault.certificate.endpoint"); + + private final String sdkEnvName; + private final String springPropertyName; + private final Function converter; + + AzureSdkEnvMapping(String sdkEnvName, String springPropertyName) { + this(sdkEnvName, springPropertyName, Function.identity()); + } + + AzureSdkEnvMapping(String sdkEnvName, String springPropertyName, Function converter) { + this.sdkEnvName = sdkEnvName; + this.springPropertyName = "spring.cloud.azure." + springPropertyName; + this.converter = converter; + } + } @Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { - final Configuration globalConfiguration = Configuration.getGlobalConfiguration(); - - PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - propertyMapper.from(environment.getProperty(CREDENTIAL_PREFIX + "client-id")) - .to(p -> globalConfiguration.put(PROPERTY_AZURE_CLIENT_ID, p)); - propertyMapper.from(environment.getProperty(CREDENTIAL_PREFIX + "client-secret")) - .to(p -> globalConfiguration.put(PROPERTY_AZURE_CLIENT_SECRET, p)); - propertyMapper.from(environment.getProperty(CREDENTIAL_PREFIX + "client-certificate-path")) - .to(p -> globalConfiguration.put(PROPERTY_AZURE_CLIENT_CERTIFICATE_PATH, p)); - propertyMapper.from(environment.getProperty(CREDENTIAL_PREFIX + "username")) - .to(p -> globalConfiguration.put(PROPERTY_AZURE_USERNAME, p)); - propertyMapper.from(environment.getProperty(CREDENTIAL_PREFIX + "password")) - .to(p -> globalConfiguration.put(PROPERTY_AZURE_PASSWORD, p)); - propertyMapper.from(environment.getProperty(CREDENTIAL_PREFIX + "managed-identity-client-id")) - .to(p -> globalConfiguration.put(PROPERTY_AZURE_CLIENT_ID, p)); - - propertyMapper.from(environment.getProperty(PROFILE_PREFIX + "tenant-id")) - .to(p -> globalConfiguration.put(PROPERTY_AZURE_TENANT_ID, p)); - propertyMapper.from(environment.getProperty(PROFILE_PREFIX + "environment.active-directory-endpoint")) - .to(p -> globalConfiguration.put(PROPERTY_AZURE_AUTHORITY_HOST, p)); + Map source = new HashMap<>(); + + for (AzureCoreEnvMapping mapping : AzureCoreEnvMapping.values()) { + if (environment.containsProperty(mapping.coreEnvName)) { + String property = environment.getProperty(mapping.coreEnvName); + source.put(mapping.springPropertyName, mapping.converter.apply(property)); + } + } + + for (AzureSdkEnvMapping mapping : AzureSdkEnvMapping.values()) { + if (environment.containsProperty(mapping.sdkEnvName)) { + String property = environment.getProperty(mapping.sdkEnvName); + source.put(mapping.springPropertyName, mapping.converter.apply(property)); + } + } + + if (!source.isEmpty()) { + environment.getPropertySources().addLast(new AzureCoreEnvPropertySource("Azure Core/SDK", source)); + } else { + LOGGER.debug("No env predefined by Azure Core/SDKs are set, skip adding the AzureCoreEnvPropertySource."); + } + } + + private static class AzureCoreEnvPropertySource extends MapPropertySource { + + /** + * Create a new {@code MapPropertySource} with the given name and {@code Map}. + * + * @param name the associated name + * @param source the Map source (without {@code null} values in order to get consistent {@link #getProperty} + * and {@link + * #containsProperty} behavior) + */ + AzureCoreEnvPropertySource(String name, Map source) { + super(name, source); + } } + + } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureEventHubMessagingAutoConfiguration.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureEventHubMessagingAutoConfiguration.java index 1ea42cf70a9bf..65626edfde38c 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureEventHubMessagingAutoConfiguration.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureEventHubMessagingAutoConfiguration.java @@ -6,6 +6,7 @@ import com.azure.messaging.eventhubs.CheckpointStore; import com.azure.spring.cloud.autoconfigure.condition.ConditionalOnAnyProperty; import com.azure.spring.cloud.autoconfigure.eventhubs.properties.AzureEventHubProperties; +import com.azure.spring.core.properties.AzurePropertiesUtils; import com.azure.spring.eventhubs.core.EventHubProcessorContainer; import com.azure.spring.eventhubs.core.EventHubsTemplate; import com.azure.spring.eventhubs.core.processor.DefaultEventHubNamespaceProcessorFactory; @@ -48,6 +49,7 @@ public class AzureEventHubMessagingAutoConfiguration { @ConditionalOnMissingBean public NamespaceProperties eventHubNamespaceProperties(AzureEventHubProperties properties) { NamespaceProperties namespaceProperties = new NamespaceProperties(); + AzurePropertiesUtils.copyAzureCommonProperties(properties, namespaceProperties); BeanUtils.copyProperties(properties, namespaceProperties); return namespaceProperties; } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/properties/core/client/HttpClientCP.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/properties/core/client/HttpClientCP.java index 9ecf1d5575e5c..79df4e42a04c2 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/properties/core/client/HttpClientCP.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/properties/core/client/HttpClientCP.java @@ -15,6 +15,9 @@ public class HttpClientCP extends ClientCP implements ClientAware.HttpClient { private Duration writeTimeout; private Duration responseTimeout; private Duration readTimeout; + private Duration connectTimeout; + private Integer maximumConnectionPoolSize; + private Duration connectionIdleTimeout; @Override public Duration getWriteTimeout() { @@ -42,4 +45,28 @@ public Duration getReadTimeout() { public void setReadTimeout(Duration readTimeout) { this.readTimeout = readTimeout; } + + public Duration getConnectTimeout() { + return connectTimeout; + } + + public void setConnectTimeout(Duration connectTimeout) { + this.connectTimeout = connectTimeout; + } + + public Integer getMaximumConnectionPoolSize() { + return maximumConnectionPoolSize; + } + + public void setMaximumConnectionPoolSize(Integer maximumConnectionPoolSize) { + this.maximumConnectionPoolSize = maximumConnectionPoolSize; + } + + public Duration getConnectionIdleTimeout() { + return connectionIdleTimeout; + } + + public void setConnectionIdleTimeout(Duration connectionIdleTimeout) { + this.connectionIdleTimeout = connectionIdleTimeout; + } } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalConfigurationEnvironmentPostProcessorTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalConfigurationEnvironmentPostProcessorTest.java new file mode 100644 index 0000000000000..8551303ce0e3d --- /dev/null +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/context/AzureGlobalConfigurationEnvironmentPostProcessorTest.java @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.cloud.autoconfigure.context; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.PropertiesPropertySource; + +import java.util.Properties; + +import static com.azure.core.util.Configuration.PROPERTY_AZURE_CLIENT_ID; + +class AzureGlobalConfigurationEnvironmentPostProcessorTest { + + @Test + void springPropertyShouldHaveValueIfAzureCoreEnvSet() { + PropertiesPropertySource propertiesPropertySource = buildTestProperties(PROPERTY_AZURE_CLIENT_ID, "test-client-id"); + + ConfigurableEnvironment environment = getEnvironment(propertiesPropertySource); + + Assertions.assertEquals("test-client-id", environment.getProperty(PROPERTY_AZURE_CLIENT_ID)); + Assertions.assertEquals("test-client-id", environment.getProperty("spring.cloud.azure.credential.client-id")); + } + + @Test + void springPropertyShouldHaveValueIfAzureSdkEnvSet() { + PropertiesPropertySource propertiesPropertySource = buildTestProperties("AZURE_KEYVAULT_ENDPOINT", "test-endpoint"); + + ConfigurableEnvironment environment = getEnvironment(propertiesPropertySource); + + Assertions.assertEquals("test-endpoint", environment.getProperty("AZURE_KEYVAULT_ENDPOINT")); + Assertions.assertEquals("test-endpoint", environment.getProperty("spring.cloud.azure.keyvault.secret.endpoint")); + Assertions.assertEquals("test-endpoint", environment.getProperty("spring.cloud.azure.keyvault.certificate.endpoint")); + } + + @Test + void azureCoreEnvShouldNotBeTakenIfSpringPropertiesSet() { + Properties properties = new Properties(); + properties.put(PROPERTY_AZURE_CLIENT_ID, "core-client-id"); + properties.put("spring.cloud.azure.credential.client-id", "spring-client-id"); + PropertiesPropertySource propertiesPropertySource = new PropertiesPropertySource("test-properties", properties); + + ConfigurableEnvironment environment = getEnvironment(propertiesPropertySource); + + Assertions.assertEquals("core-client-id", environment.getProperty(PROPERTY_AZURE_CLIENT_ID)); + Assertions.assertEquals("spring-client-id", environment.getProperty("spring.cloud.azure.credential.client-id")); + } + + @Test + void azureSdkEnvShouldNotBeTakenIfSpringPropertiesSet() { + Properties properties = new Properties(); + properties.put("AZURE_KEYVAULT_ENDPOINT", "sdk-endpoint"); + properties.put("spring.cloud.azure.keyvault.secret.endpoint", "spring-endpoint"); + PropertiesPropertySource propertiesPropertySource = new PropertiesPropertySource("test-properties", properties); + + ConfigurableEnvironment environment = getEnvironment(propertiesPropertySource); + + Assertions.assertEquals("sdk-endpoint", environment.getProperty("AZURE_KEYVAULT_ENDPOINT")); + Assertions.assertEquals("spring-endpoint", environment.getProperty("spring.cloud.azure.keyvault.secret.endpoint")); + } + + private PropertiesPropertySource buildTestProperties(String key, String value) { + Properties properties = new Properties(); + properties.put(key, value); + return new PropertiesPropertySource("test-properties", properties); + } + + + private ConfigurableEnvironment getEnvironment(PropertiesPropertySource propertiesPropertySource) { + return getEnvironment(propertiesPropertySource, null); + } + + private ConfigurableEnvironment getEnvironment(PropertiesPropertySource propertiesPropertySource, + EnvironmentPostProcessor environmentPostProcessor) { + SpringApplication springApplication = new SpringApplicationBuilder() + .sources(AzureGlobalConfigurationEnvironmentPostProcessorTest.class) + .web(WebApplicationType.NONE).build(); + + ConfigurableApplicationContext context = springApplication.run(); + + if (propertiesPropertySource != null) { + context.getEnvironment().getPropertySources().addFirst(propertiesPropertySource); + } + + if (environmentPostProcessor == null) { + environmentPostProcessor = new AzureGlobalConfigurationEnvironmentPostProcessor(); + } + + environmentPostProcessor.postProcessEnvironment(context.getEnvironment(), springApplication); + + ConfigurableEnvironment configurableEnvironment = context.getEnvironment(); + context.close(); + + return configurableEnvironment; + } + +} diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/aware/ClientAware.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/aware/ClientAware.java index 09dc1314517d8..411eec2cb1623 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/aware/ClientAware.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/aware/ClientAware.java @@ -35,12 +35,19 @@ interface Client { * Interface to be implemented by classes that wish to describe a http based client sdk. */ interface HttpClient extends Client { + Duration getWriteTimeout(); Duration getResponseTimeout(); Duration getReadTimeout(); + Duration getConnectTimeout(); + + Integer getMaximumConnectionPoolSize(); + + Duration getConnectionIdleTimeout(); + } /** diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/aware/ProxyAware.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/aware/ProxyAware.java index ab6159d0ed2d2..ee0bf90fd09cc 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/aware/ProxyAware.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/aware/ProxyAware.java @@ -27,7 +27,7 @@ interface Proxy { String getHostname(); - int getPort(); + Integer getPort(); String getAuthenticationType(); diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/converter/AzureHttpProxyOptionsConverter.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/converter/AzureHttpProxyOptionsConverter.java index c6732fa191de4..3d019ec491b94 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/converter/AzureHttpProxyOptionsConverter.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/converter/AzureHttpProxyOptionsConverter.java @@ -5,6 +5,8 @@ import com.azure.core.http.ProxyOptions; import com.azure.spring.core.properties.proxy.HttpProxyProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.core.convert.converter.Converter; import org.springframework.util.StringUtils; @@ -15,11 +17,13 @@ */ public final class AzureHttpProxyOptionsConverter implements Converter { + private static final Logger LOGGER = LoggerFactory.getLogger(AzureHttpProxyOptionsConverter.class); public static final AzureHttpProxyOptionsConverter HTTP_PROXY_CONVERTER = new AzureHttpProxyOptionsConverter(); @Override public ProxyOptions convert(HttpProxyProperties proxyProperties) { - if (!StringUtils.hasText(proxyProperties.getHostname())) { + if (!StringUtils.hasText(proxyProperties.getHostname()) || proxyProperties.getPort() == null) { + LOGGER.debug("Proxy hostname or port is not set."); return null; } diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/factory/AbstractAzureHttpClientBuilderFactory.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/factory/AbstractAzureHttpClientBuilderFactory.java index 428d3cbb81e3a..619ba4cc78f94 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/factory/AbstractAzureHttpClientBuilderFactory.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/factory/AbstractAzureHttpClientBuilderFactory.java @@ -117,6 +117,9 @@ protected void configureHttpTransportProperties(T builder) { httpClientOptions.setWriteTimeout(properties.getWriteTimeout()); httpClientOptions.responseTimeout(properties.getResponseTimeout()); httpClientOptions.readTimeout(properties.getReadTimeout()); + httpClientOptions.setConnectTimeout(properties.getConnectTimeout()); + httpClientOptions.setConnectionIdleTimeout(properties.getConnectionIdleTimeout()); + httpClientOptions.setMaximumConnectionPoolSize(properties.getMaximumConnectionPoolSize()); } } diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/AzureSdkProperties.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/AbstractAzureSdkProperties.java similarity index 95% rename from sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/AzureSdkProperties.java rename to sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/AbstractAzureSdkProperties.java index d930e02dc9bf4..0951649b204b1 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/AzureSdkProperties.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/AbstractAzureSdkProperties.java @@ -3,8 +3,8 @@ package com.azure.spring.core.properties; -import com.azure.spring.core.properties.client.ClientProperties; import com.azure.spring.core.properties.authentication.TokenCredentialProperties; +import com.azure.spring.core.properties.client.ClientProperties; import com.azure.spring.core.properties.profile.AzureProfile; import com.azure.spring.core.properties.proxy.ProxyProperties; import com.azure.spring.core.properties.retry.RetryProperties; @@ -12,7 +12,7 @@ /** * Unified properties for Azure SDK clients. */ -public abstract class AzureSdkProperties implements AzureProperties { +public abstract class AbstractAzureSdkProperties implements AzureProperties { private ClientProperties client = new ClientProperties(); private ProxyProperties proxy = new ProxyProperties(); diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/client/HttpClientProperties.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/client/HttpClientProperties.java index 2b27622975208..39db40c96d00d 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/client/HttpClientProperties.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/client/HttpClientProperties.java @@ -15,6 +15,9 @@ public final class HttpClientProperties extends ClientProperties implements Clie private Duration writeTimeout; private Duration responseTimeout; private Duration readTimeout; + private Duration connectTimeout; + private Duration connectionIdleTimeout; + private Integer maximumConnectionPoolSize; public Duration getWriteTimeout() { return writeTimeout; @@ -40,4 +43,30 @@ public void setReadTimeout(Duration readTimeout) { this.readTimeout = readTimeout; } + @Override + public Duration getConnectTimeout() { + return connectTimeout; + } + + public void setConnectTimeout(Duration connectTimeout) { + this.connectTimeout = connectTimeout; + } + + @Override + public Integer getMaximumConnectionPoolSize() { + return maximumConnectionPoolSize; + } + + public void setMaximumConnectionPoolSize(Integer maximumConnectionPoolSize) { + this.maximumConnectionPoolSize = maximumConnectionPoolSize; + } + + @Override + public Duration getConnectionIdleTimeout() { + return connectionIdleTimeout; + } + + public void setConnectionIdleTimeout(Duration connectionIdleTimeout) { + this.connectionIdleTimeout = connectionIdleTimeout; + } } diff --git a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/proxy/ProxyProperties.java b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/proxy/ProxyProperties.java index b2f053650c76c..00b8372aafd52 100644 --- a/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/proxy/ProxyProperties.java +++ b/sdk/spring/spring-cloud-azure-core/src/main/java/com/azure/spring/core/properties/proxy/ProxyProperties.java @@ -12,11 +12,12 @@ public class ProxyProperties implements ProxyAware.Proxy { private String type; private String hostname; - private int port; + private Integer port; private String authenticationType; private String username; private String password; + @Override public String getType() { return type; } @@ -25,6 +26,7 @@ public void setType(String type) { this.type = type; } + @Override public String getHostname() { return hostname; } @@ -33,14 +35,16 @@ public void setHostname(String hostname) { this.hostname = hostname; } - public int getPort() { + @Override + public Integer getPort() { return port; } - public void setPort(int port) { + public void setPort(Integer port) { this.port = port; } + @Override public String getAuthenticationType() { return authenticationType; } @@ -49,6 +53,7 @@ public void setAuthenticationType(String authenticationType) { this.authenticationType = authenticationType; } + @Override public String getUsername() { return username; } @@ -57,6 +62,7 @@ public void setUsername(String username) { this.username = username; } + @Override public String getPassword() { return password; } diff --git a/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/service/core/properties/AbstractServiceProperties.java b/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/service/core/properties/AbstractServiceProperties.java index b52693777434d..a47bf18f28337 100644 --- a/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/service/core/properties/AbstractServiceProperties.java +++ b/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/service/core/properties/AbstractServiceProperties.java @@ -4,8 +4,8 @@ package com.azure.spring.service.core.properties; import com.azure.spring.core.properties.AzureProperties; -import com.azure.spring.core.properties.client.ClientProperties; import com.azure.spring.core.properties.authentication.TokenCredentialProperties; +import com.azure.spring.core.properties.client.ClientProperties; import com.azure.spring.core.properties.profile.AzureProfile; import com.azure.spring.core.properties.proxy.ProxyProperties; import com.azure.spring.core.properties.retry.RetryProperties; diff --git a/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/eventhubs/core/properties/CommonProperties.java b/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/eventhubs/core/properties/CommonProperties.java index c678f6b8d8db5..f7060ce6d4de1 100644 --- a/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/eventhubs/core/properties/CommonProperties.java +++ b/sdk/spring/spring-messaging-azure-eventhubs/src/main/java/com/azure/spring/eventhubs/core/properties/CommonProperties.java @@ -5,13 +5,13 @@ import com.azure.spring.core.aware.authentication.ConnectionStringAware; import com.azure.spring.core.connectionstring.implementation.EventHubConnectionString; -import com.azure.spring.core.properties.AzureSdkProperties; +import com.azure.spring.core.properties.AbstractAzureSdkProperties; import com.azure.spring.service.eventhubs.properties.EventHubCommonDescriptor; /** * Common properties shared by event hub namespace, a producer, and a consumer. */ -abstract class CommonProperties extends AzureSdkProperties implements EventHubCommonDescriptor, ConnectionStringAware { +abstract class CommonProperties extends AbstractAzureSdkProperties implements EventHubCommonDescriptor, ConnectionStringAware { private String domainName = "servicebus.windows.net";