Skip to content

Commit 02374c2

Browse files
committed
Update with latest version and WebSocket new API
1 parent a0a4135 commit 02374c2

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

README

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,17 @@ Javadoc: http://sonatype.github.com/async-http-client/apidocs/index.html
88
Getting started: http://is.gd/kexrN (PDF)
99
http://is.gd/ja6My (HTML)
1010

11-
Async Http Client library purpose is to allow Java applications to easily execute HTTP requests and asynchronously process the HTTP responses. The Async HTTP Client library is simple to use. First, in order to add it to your Maven project, simply add this dependency:
12-
13-
<repository>
14-
<id>Sonatype</id>
15-
<name>Sonatype Release</name>
16-
<url>http://oss.sonatype.org/content/repositories/releases </url>
17-
</repository>
18-
19-
and then define the dependency as:
11+
Async Http Client library purpose is to allow Java applications to easily execute HTTP requests and asynchronously process the HTTP responses. The library also supports the WebSocket Protocol. The Async HTTP Client library is simple to use. First, in order to add it to your Maven project, simply add this dependency:
2012

2113
<dependency>
2214
<groupId>com.ning</groupId>
2315
<artifactId>async-http-client</artifactId>
24-
<version>1.6.2</version>
16+
<version>1.7.0</version>
2517
</dependency>
2618

2719
You can also download the artifact
2820

29-
http://oss.sonatype.org/content/repositories/releases
21+
http://search.maven.org
3022

3123
Then in your code you can simply do:
3224

@@ -125,12 +117,35 @@ You can also mix Future with AsyncHandler to only retrieve part of the asynchron
125117

126118
String bodyResponse = f.get();
127119

128-
129120
Finally, you can also configure the AsyncHttpClient via it's AsyncHttpClientConfig object:
130121

131122
AsyncHttpClientConfig cf = new AsyncHttpClientConfig.Builder().setProxyServer(new ProxyServer("127.0.0.1", 38080)).build();
132123
AsyncHttpClient c = new AsyncHttpClient(cf);
133124

125+
Async Http Client also support WebSocket by simply doing:
126+
127+
WebSocket websocket = c.prepareGet(getTargetUrl())
128+
.execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {
129+
130+
@Override
131+
public void onMessage(String message) {
132+
}
133+
134+
@Override
135+
public void onOpen(WebSocket websocket) {
136+
websocket.sendTextMessage("...").sendBinaryMessage("...");
137+
}
138+
139+
@Override
140+
public void onClose(.WebSocket websocket) {
141+
latch.countDown();
142+
}
143+
144+
@Override
145+
public void onError(Throwable t) {
146+
}
147+
}).build()).get();
148+
134149
The library uses Java non blocking I/O for supporting asynchronous operations. The default asynchronous provider is build on top of Netty (http://www.jboss.org/netty), the Java NIO Client Server Socket Framework from JBoss, but the library exposes a configurable provider SPI which allows to easily plug in other frameworks.
135150

136151
Keep up to date on the library development by joining the Asynchronous HTTP Client discussion group

0 commit comments

Comments
 (0)