Skip to content

Commit 60a8fe2

Browse files
coutoPLslandelle
authored andcommitted
Add new typesafe config integration extras module
Motivation: Current implemenation does not have any integration with popular config library. Modifications: Added extras module with Typesafe Config integration and provided AHC config wrapper for mentioned lib. Result: AsyncHttpClient can be initialized with Typesafe Config file.
1 parent c19758d commit 60a8fe2

File tree

7 files changed

+693
-61
lines changed

7 files changed

+693
-61
lines changed

client/src/main/java/org/asynchttpclient/DefaultAsyncHttpClientConfig.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.asynchttpclient.channel.ChannelPool;
2525
import org.asynchttpclient.channel.DefaultKeepAliveStrategy;
2626
import org.asynchttpclient.channel.KeepAliveStrategy;
27+
import org.asynchttpclient.config.AsyncHttpClientConfigDefaults;
2728
import org.asynchttpclient.cookie.CookieStore;
2829
import org.asynchttpclient.cookie.ThreadSafeCookieStore;
2930
import org.asynchttpclient.filter.IOExceptionFilter;
@@ -49,18 +50,6 @@
4950
*/
5051
public class DefaultAsyncHttpClientConfig implements AsyncHttpClientConfig {
5152

52-
private static final String AHC_VERSION;
53-
54-
static {
55-
try (InputStream is = DefaultAsyncHttpClientConfig.class.getResourceAsStream("/ahc-version.properties")) {
56-
Properties prop = new Properties();
57-
prop.load(is);
58-
AHC_VERSION = prop.getProperty("ahc.version", "UNKNOWN");
59-
} catch (IOException e) {
60-
throw new ExceptionInInitializerError(e);
61-
}
62-
}
63-
6453
// http
6554
private final boolean followRedirect;
6655
private final int maxRedirects;
@@ -302,7 +291,7 @@ private DefaultAsyncHttpClientConfig(// http
302291

303292
@Override
304293
public String getAhcVersion() {
305-
return AHC_VERSION;
294+
return AsyncHttpClientConfigDefaults.AHC_VERSION;
306295
}
307296

308297
// http

client/src/main/java/org/asynchttpclient/config/AsyncHttpClientConfigDefaults.java

Lines changed: 112 additions & 48 deletions
Large diffs are not rendered by default.

extras/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<module>rxjava2</module>
2121
<module>simple</module>
2222
<module>retrofit2</module>
23+
<module>typesafeconfig</module>
2324
</modules>
2425

2526
<dependencies>

extras/typesafeconfig/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Async-http-client and Typesafe Config integration
2+
3+
An `AsyncHttpClientConfig` implementation integrating [Typesafe Config][1] with Async Http Client.
4+
## Download
5+
6+
Download [the latest JAR][2] or grab via [Maven][3]:
7+
8+
```xml
9+
<dependency>
10+
<groupId>org.asynchttpclient</groupId>
11+
<artifactId>async-http-client-extras-typesafeconfig</artifactId>
12+
<version>latest.version</version>
13+
</dependency>
14+
```
15+
16+
or [Gradle][3]:
17+
18+
```groovy
19+
compile "org.asynchttpclient:async-http-client-extras-typesafeconfig:latest.version"
20+
```
21+
22+
[1]: https://github.com/lightbend/config
23+
[2]: https://search.maven.org/remote_content?g=org.asynchttpclient&a=async-http-client-extras-typesafeconfig&v=LATEST
24+
[3]: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.asynchttpclient%22%20a%3A%22async-http-client-extras-typesafeconfig%22
25+
[snap]: https://oss.sonatype.org/content/repositories/snapshots/
26+
27+
## Example usage
28+
29+
```java
30+
// creating async-http-client with Typesafe config
31+
com.typesafe.config.Config config = ...
32+
AsyncHttpClientTypesafeConfig ahcConfig = new AsyncHttpClientTypesafeConfig(config);
33+
AsyncHttpClient client = new DefaultAsyncHttpClient(ahcConfig);
34+
```

extras/typesafeconfig/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<artifactId>async-http-client-extras-parent</artifactId>
7+
<groupId>org.asynchttpclient</groupId>
8+
<version>2.2.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>async-http-client-extras-typesafe-config</artifactId>
12+
<name>Asynchronous Http Client Typesafe Config Extras</name>
13+
<description>The Async Http Client Typesafe Config Extras.</description>
14+
15+
<properties>
16+
<typesafeconfig.version>1.3.2</typesafeconfig.version>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.typesafe</groupId>
22+
<artifactId>config</artifactId>
23+
<version>${typesafeconfig.version}</version>
24+
</dependency>
25+
</dependencies>
26+
</project>

0 commit comments

Comments
 (0)