Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SpringEnvironmentAwareGeoToolsHttpClientFactory registration #463

Merged
merged 1 commit into from
May 4, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ public void initialize(ConfigurableApplicationContext applicationContext) {
}
System.setProperty("org.geotools.referencing.forceXY", "true");

Boolean useEnvAwareHttpClient =
boolean useEnvAwareHttpClient =
applicationContext
.getEnvironment()
.getProperty(
"geotools.httpclient.proxy.enabled", Boolean.class, Boolean.TRUE);
if (useEnvAwareHttpClient) {
// factoryName matches the one in
// src/main/resources/META-INF/services/org.geotools.http.HTTPClientFactory
String factoryName =
SpringEnvironmentAwareGeoToolsHttpClientFactory.class.getCanonicalName();
Hints.putSystemDefault(Hints.HTTP_CLIENT_FACTORY, factoryName);
Hints.putSystemDefault(
Hints.HTTP_CLIENT_FACTORY,
SpringEnvironmentAwareGeoToolsHttpClientFactory.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.geotools.http.HTTPClient;
import org.geotools.http.HTTPClientFinder;
import org.geotools.util.factory.Hints;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -44,6 +46,16 @@ void enabledByDefault() {
context.getBean(
GeoToolsHttpClientProxyConfigurationProperties.class))
.hasFieldOrPropertyWithValue("enabled", true);

HTTPClient client = HTTPClientFinder.createClient();
assertThat(client)
.as(
"""
Expected SpringEnvironmentAwareGeoToolsHttpClient \
after GeoToolsStaticContextInitializer sets \
SpringEnvironmentAwareGeoToolsHttpClientFactory as the default factory
""")
.isInstanceOf(SpringEnvironmentAwareGeoToolsHttpClient.class);
});
}

Expand All @@ -56,8 +68,7 @@ void testInitializerSetsForceXYSystemProperty() {

@Test
void testInitializerSetsHttpClientFactorySystemProperty() {
final String expected =
SpringEnvironmentAwareGeoToolsHttpClientFactory.class.getCanonicalName();
final var expected = SpringEnvironmentAwareGeoToolsHttpClientFactory.class;

assertNull(Hints.getSystemDefault(Hints.HTTP_CLIENT_FACTORY));
runner.run(
Expand Down
Loading