1- # Async Http Client [ ![ Build] ( https://github.com/AsyncHttpClient/async-http-client/actions/workflows/builds.yml/badge.svg )] ( https://github.com/AsyncHttpClient/async-http-client/actions/workflows/builds.yml ) [ ![ Maven Central] ( https://maven-badges.herokuapp.com/maven-central/org.asynchttpclient/async-http-client/badge.svg )] ( https://maven-badges.herokuapp.com/maven-central/org.asynchttpclient/async-http-client/ )
1+ # Async Http Client
2+ [ ![ Build] ( https://github.com/AsyncHttpClient/async-http-client/actions/workflows/builds.yml/badge.svg )] ( https://github.com/AsyncHttpClient/async-http-client/actions/workflows/builds.yml )
3+ [ ![ Maven Central] ( https://maven-badges.herokuapp.com/maven-central/org.asynchttpclient/async-http-client/badge.svg )] ( https://maven-badges.herokuapp.com/maven-central/org.asynchttpclient/async-http-client/ )
24
35Follow [ @AsyncHttpClient ] ( https://twitter.com/AsyncHttpClient ) on Twitter.
46
@@ -18,7 +20,7 @@ Add a dependency on the main AsyncHttpClient artifact:
1820 <dependency >
1921 <groupId >org.asynchttpclient</groupId >
2022 <artifactId >async-http-client</artifactId >
21- <version >3.0.0-SNAPSHOT </version >
23+ <version >3.0.0.Beta1 </version >
2224 </dependency >
2325</dependencies >
2426```
@@ -140,17 +142,18 @@ The point of using a non blocking client is to *NOT BLOCK* the calling thread!
140142You can configure listeners to be notified of the Future's completion.
141143
142144``` java
143- ListenableFuture<Response > whenResponse= ??? ;
144- Runnable callback= () - > {
145- try {
146- Response response= whenResponse. get();
147- System . out. println(response);
148- } catch (InterruptedException | ExecutionException e){
149- e. printStackTrace();
150- }
145+ ListenableFuture<Response > whenResponse = ??? ;
146+ Runnable callback = () - > {
147+ try {
148+ Response response = whenResponse. get();
149+ System . out. println(response);
150+ } catch (InterruptedException | ExecutionException e) {
151+ e. printStackTrace();
152+ }
151153 };
152- java.util.concurrent. Executor executor= ??? ;
153- whenResponse. addListener(()- > ??? ,executor);
154+
155+ java.util.concurrent. Executor executor = ??? ;
156+ whenResponse. addListener(() - > ??? , executor);
154157```
155158
156159If the ` executor ` parameter is null, callback will be executed in the IO thread.
@@ -175,32 +178,38 @@ import static org.asynchttpclient.Dsl.*;
175178import org.asynchttpclient.* ;
176179import io.netty.handler.codec.http.HttpHeaders ;
177180
178- Future<Integer > whenStatusCode= asyncHttpClient. prepareGet(" http://www.example.com/" )
179- .execute(new AsyncHandler<Integer > (){
180- private Integer status;
181- @Override
182- public State onStatusReceived (HttpResponseStatus responseStatus )throws Exception {
183- status= responseStatus. getStatusCode();
184- return State . ABORT ;
185- }
186- @Override
187- public State onHeadersReceived (HttpHeaders headers )throws Exception {
188- return State . ABORT ;
189- }
190- @Override
191- public State onBodyPartReceived (HttpResponseBodyPart bodyPart )throws Exception {
192- return State . ABORT ;
193- }
194- @Override
195- public Integer onCompleted ()throws Exception {
196- return status;
197- }
198- @Override
199- public void onThrowable (Throwable t ){
200- }
181+ Future<Integer > whenStatusCode = asyncHttpClient. prepareGet(" http://www.example.com/" )
182+ .execute(new AsyncHandler<Integer > () {
183+ private Integer status;
184+
185+ @Override
186+ public State onStatusReceived (HttpResponseStatus responseStatus ) throws Exception {
187+ status = responseStatus. getStatusCode();
188+ return State . ABORT ;
189+ }
190+
191+ @Override
192+ public State onHeadersReceived (HttpHeaders headers ) throws Exception {
193+ return State . ABORT ;
194+ }
195+
196+ @Override
197+ public State onBodyPartReceived (HttpResponseBodyPart bodyPart ) throws Exception {
198+ return State . ABORT ;
199+ }
200+
201+ @Override
202+ public Integer onCompleted () throws Exception {
203+ return status;
204+ }
205+
206+ @Override
207+ public void onThrowable (Throwable t ) {
208+ t. printStackTrace();
209+ }
201210 });
202211
203- Integer statusCode= whenStatusCode. get();
212+ Integer statusCode = whenStatusCode. get();
204213```
205214
206215#### Using Continuations
@@ -232,23 +241,25 @@ WebSocket websocket=c.prepareGet("ws://demos.kaazing.com/echo")
232241 .execute(new WebSocketUpgradeHandler .Builder (). addWebSocketListener(
233242 new WebSocketListener (){
234243
235- @Override
236- public void onOpen (WebSocket websocket ){
237- websocket. sendTextFrame(" ..." ). sendTextFrame(" ..." );
238- }
239-
240- @Override
241- public void onClose (WebSocket websocket ){
242- }
243-
244- @Override
245- public void onTextFrame (String payload ,boolean final Fragment ,int rsv ){
246- System . out. println(payload);
247- }
248-
249- @Override
250- public void onError (Throwable t ){
251- }
244+ @Override
245+ public void onOpen (WebSocket websocket ){
246+ websocket. sendTextFrame(" ..." ). sendTextFrame(" ..." );
247+ }
248+
249+ @Override
250+ public void onClose (WebSocket websocket ) {
251+ // ...
252+ }
253+
254+ @Override
255+ public void onTextFrame (String payload ,boolean final Fragment ,int rsv ){
256+ System . out. println(payload);
257+ }
258+
259+ @Override
260+ public void onError (Throwable t ){
261+ t. printStackTrace();
262+ }
252263 }). build()). get();
253264```
254265
@@ -258,16 +269,16 @@ AsyncHttpClient has build in support for the WebDAV protocol.
258269The API can be used the same way normal HTTP request are made:
259270
260271``` java
261- Request mkcolRequest= new RequestBuilder (" MKCOL" ). setUrl(" http://host:port/folder1" ). build();
272+ Request mkcolRequest= new RequestBuilder (" MKCOL" ). setUrl(" http://host:port/folder1" ). build();
262273 Response response= c. executeRequest(mkcolRequest). get();
263274```
264275
265276or
266277
267278``` java
268- Request propFindRequest= new RequestBuilder (" PROPFIND" ). setUrl(" http://host:port" ). build();
269- Response response= c. executeRequest(propFindRequest,new AsyncHandler (){
270- // ...
279+ Request propFindRequest= new RequestBuilder (" PROPFIND" ). setUrl(" http://host:port" ). build();
280+ Response response= c. executeRequest(propFindRequest,new AsyncHandler () {
281+ // ...
271282 }). get();
272283```
273284
0 commit comments