Skip to content

Commit

Permalink
Merge pull request #463 from groldan/fix/gt_http_client
Browse files Browse the repository at this point in the history
Fix SpringEnvironmentAwareGeoToolsHttpClientFactory registration
  • Loading branch information
groldan authored May 4, 2024
2 parents 9f1cdad + ba733cf commit f1496f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
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

0 comments on commit f1496f2

Please sign in to comment.