Skip to content

Commit be4bfbe

Browse files
committed
Merge pull request #1 from AsyncHttpClient/master
update from the upstream
2 parents 3341a30 + 6ca14a1 commit be4bfbe

File tree

618 files changed

+32947
-20423
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

618 files changed

+32947
-20423
lines changed

MIGRATION.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Migration Guide
2+
---------------
3+
4+
## From 1.8 to 1.9
5+
6+
AsyncHttpClient v1.9 is a preview of v2, so it comes with some breaking changes.
7+
8+
* Target JDK7, drop support for JDK5 and JDK6
9+
* Rename many AsyncHttpClientConfig parameters:
10+
* `maxTotalConnections` becomes `maxConnections`
11+
* `maxConnectionPerHost` becomes `maxConnectionsPerHost`
12+
* `connectionTimeOutInMs` becomes `connectTimeout`
13+
* `webSocketIdleTimeoutInMs` becomes `webSocketTimeout`
14+
* `idleConnectionInPoolTimeoutInMs` becomes `pooledConnectionIdleTimeout`
15+
* `idleConnectionTimeoutInMs` becomes `readTimeout`
16+
* `requestTimeoutInMs` becomes `requestTimeout`
17+
* `maxConnectionLifeTimeInMs` becomes `connectionTTL`
18+
* `redirectEnabled` becomes `followRedirect`
19+
* `allowPoolingConnection` becomes `allowPoolingConnections`
20+
* `allowSslConnectionPool` becomes `allowPoolingSslConnections`
21+
* `connectionTimeout` becomes `connectTimeout`
22+
* `compressionEnabled` becomes `compressionEnforced` (default true) so it's always enabled and can honor user defined Accept-Encoding
23+
* `requestCompressionLevel` was dropped, as it wasn't working
24+
* `SSLEngineFactory` was moved to Netty config as only Netty honors it
25+
* `useRawUrl` becomes `disableUrlEncodingForBoundedRequests`, as it's only honored by bound requests
26+
* `getAllowPoolingConnection` becomes `isAllowPoolingConnection`
27+
* Drop `PerRequestConfig`. `requestTimeOut` and `proxy` can now be directly set on the request.
28+
* Drop `java.net.URI` in favor of own `com.ning.http.client.uri.Uri`. You can use `toJavaNetURI` to convert.
29+
* Drop `Proxy.getURI` in favor of `getUrl`
30+
* Drop deprecated methods: `Request` and `RequestBuilderBase`'s `getReqType` in favor of `getMethod`, `Request.getLength` in favor of `getContentLength`
31+
* Drop deprecated `RealmBuilder.getDomain` in favor of `getNtlmDomain`
32+
* Rename `xxxParameter` (add, set, get...) into `xxxFormParam`
33+
* Rename `xxxQueryParameter` (add, set, get...) into `xxxQueryParam`
34+
* Merge `boolean Request.isRedirectEnabled` and `boolean isRedirectOverrideSet` are merged into `Boolean isRedirectEnabled`
35+
* Remove url parameter from `SignatureCalculator.calculateAndAddSignature`, as it can be fetched on the request parameter
36+
* Rename `com.ning.http.client.websocket` package into `com.ning.http.client.ws`
37+
* WebSocket Listeners now have to implement proper interfaces to be notified or fragment events: `WebSocketByteFragmentListener` and `WebSocketTextFragmentListener`
38+
* Rename WebSocket's `sendTextMessage` into `sendMessage` and `streamText` into `stream`
39+
* Rename NettyAsyncHttpProviderConfig's `handshakeTimeoutInMillis` into `handshakeTimeout`
40+
* Netty provider now creates SslEngines instances with proper hoststring and port.
41+
* Parts, Realm and ProxyServer now take a java.nio.Charset instead of a String charset name
42+
* New AsyncHandlerExtensions methods:
43+
* `onOpenConnection`,
44+
* `onConnectionOpen`,
45+
* `onPoolConnection`,
46+
* `onConnectionPooled`,
47+
* `onSendRequest`,
48+
* `onDnsResolved`,
49+
* `onSslHandshakeCompleted`
50+
* Rename FluentCaseInsensitiveStringsMap and FluentStringsMap `replace` into `replaceWith` to not conflict with new JDK8 Map methods
51+
* execute no longer throws Exceptions, all of them are notified to the handler/future

README.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,64 @@
1-
Async Http Client
2-
-----------------
1+
Async Http Client ([@AsyncHttpClient](https://twitter.com/AsyncHttpClient) on twitter)
2+
---------------------------------------------------
33

4-
Getting started [HTML](http://sonatype.github.com/async-http-client/) [PDF](http://is.gd/kexrN)
5-
With [WebSockets](http://jfarcand.wordpress.com/2011/12/21/writing-websocket-clients-using-asynchttpclient/)
4+
[Javadoc](http://www.javadoc.io/doc/com.ning/async-http-client/)
65

7-
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:
6+
[Getting](https://jfarcand.wordpress.com/2010/12/21/going-asynchronous-using-asynchttpclient-the-basic/) [started](https://jfarcand.wordpress.com/2011/01/04/going-asynchronous-using-asynchttpclient-the-complex/), and use [WebSockets](http://jfarcand.wordpress.com/2011/12/21/writing-websocket-clients-using-asynchttpclient/)
7+
8+
Async Http Client library purpose is to allow Java applications to easily execute HTTP requests and asynchronously process the HTTP responses.
9+
The library also supports the WebSocket Protocol. The Async HTTP Client library is simple to use.
10+
11+
## Installation
12+
13+
First, in order to add it to your Maven project, simply add this dependency:
814

915
```xml
1016
<dependency>
1117
<groupId>com.ning</groupId>
1218
<artifactId>async-http-client</artifactId>
13-
<version>1.8.13</version>
19+
<version>1.9.31</version>
1420
</dependency>
1521
```
1622

1723
You can also download the artifact
1824

1925
[Maven Search](http://search.maven.org)
2026

21-
Then in your code you can simply do [Javadoc](http://asynchttpclient.github.io/async-http-client/apidocs/reference/packages.html)
27+
AHC is an abstraction layer that can work on top of the bare JDK, Netty and Grizzly.
28+
Note that the JDK implementation is very limited and you should **REALLY** use the other *real* providers.
29+
30+
You then have to add the Netty or Grizzly jars in the classpath.
31+
32+
For Netty:
33+
34+
```xml
35+
<dependency>
36+
<groupId>io.netty</groupId>
37+
<artifactId>netty</artifactId>
38+
<version>LATEST_NETTY_3_VERSION</version>
39+
</dependency>
40+
```
41+
42+
For Grizzly:
43+
44+
```xml
45+
<dependency>
46+
<groupId>org.glassfish.grizzly</groupId>
47+
<artifactId>connection-pool</artifactId>
48+
<version>LATEST_GRIZZLY_VERSION</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.glassfish.grizzly</groupId>
52+
<artifactId>grizzly-websockets</artifactId>
53+
<version>LATEST_GRIZZLY_VERSION</version>
54+
</dependency>
55+
```
56+
57+
Check [migration guide](MIGRATION.md) for migrating from 1.8 to 1.9.
58+
59+
## Usage
60+
61+
Then in your code you can simply do
2262

2363
```java
2464
import com.ning.http.client.*;
@@ -162,7 +202,7 @@ WebSocket websocket = c.prepareGet(getTargetUrl())
162202
}
163203

164204
@Override
165-
public void onClose(.WebSocket websocket) {
205+
public void onClose(WebSocket websocket) {
166206
latch.countDown();
167207
}
168208

@@ -185,10 +225,6 @@ Keep up to date on the library development by joining the Asynchronous HTTP Clie
185225

186226
[Google Group](http://groups.google.com/group/asynchttpclient)
187227

188-
or follow us on [Twitter](http://twitter.com/jfarcand)
189-
190-
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/6433679063b2351599c6ca44a08246a2 "githalytics.com")](http://githalytics.com/AsyncHttpClient/async-http-client)
191-
192228
## Contributing
193229

194230
Of course, Pull Requests are welcome.

api/pom.xml

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,54 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<parent>
5-
<groupId>org.asynchttpclient</groupId>
6-
<artifactId>async-http-client-project</artifactId>
7-
<version>2.0.0-SNAPSHOT</version>
8-
</parent>
9-
<modelVersion>4.0.0</modelVersion>
10-
<artifactId>async-http-client-api</artifactId>
11-
<name>Asynchronous Http Client API</name>
12-
<description>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<parent>
3+
<groupId>org.asynchttpclient</groupId>
4+
<artifactId>async-http-client-project</artifactId>
5+
<version>2.0.0-SNAPSHOT</version>
6+
</parent>
7+
<modelVersion>4.0.0</modelVersion>
8+
<artifactId>async-http-client-api</artifactId>
9+
<name>Asynchronous Http Client API</name>
10+
<description>
1311
The Async Http Client (AHC) API classes.
1412
</description>
1513

16-
<build>
17-
<plugins>
18-
<plugin>
19-
<groupId>org.apache.maven.plugins</groupId>
20-
<artifactId>maven-jar-plugin</artifactId>
21-
<version>2.2</version>
22-
<executions>
23-
<execution>
24-
<goals>
25-
<goal>test-jar</goal>
26-
</goals>
27-
</execution>
28-
</executions>
29-
</plugin>
30-
</plugins>
31-
</build>
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<artifactId>maven-jar-plugin</artifactId>
18+
<executions>
19+
<execution>
20+
<goals>
21+
<goal>test-jar</goal>
22+
</goals>
23+
</execution>
24+
</executions>
25+
</plugin>
26+
<plugin>
27+
<artifactId>maven-antrun-plugin</artifactId>
28+
<executions>
29+
<execution>
30+
<phase>process-classes</phase>
31+
<goals>
32+
<goal>run</goal>
33+
</goals>
34+
</execution>
35+
</executions>
36+
<configuration>
37+
<tasks>
38+
<delete>
39+
<fileset dir="${project.build.outputDirectory}/org/asynchttpclient/netty" includes="NettyAsyncHttpProvider.*" />
40+
</delete>
41+
</tasks>
42+
</configuration>
43+
</plugin>
44+
</plugins>
45+
</build>
3246

33-
<dependencies>
34-
<dependency>
35-
<groupId>com.typesafe</groupId>
36-
<artifactId>config</artifactId>
37-
<version>1.2.1</version>
38-
</dependency>
39-
<dependency>
40-
<groupId>org.slf4j</groupId>
41-
<artifactId>slf4j-api</artifactId>
42-
<version>1.7.6</version>
43-
</dependency>
44-
</dependencies>
45-
46-
</project>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.reactivestreams</groupId>
50+
<artifactId>reactive-streams</artifactId>
51+
<version>1.0.0</version>
52+
</dependency>
53+
</dependencies>
54+
</project>

api/src/main/java/org/asynchttpclient/AsyncCompletionHandler.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,45 @@
1616
*/
1717
package org.asynchttpclient;
1818

19+
import org.asynchttpclient.handler.ProgressAsyncHandler;
1920
import org.slf4j.Logger;
2021
import org.slf4j.LoggerFactory;
2122

2223
/**
2324
* An {@link AsyncHandler} augmented with an {@link #onCompleted(Response)} convenience method which gets called
2425
* when the {@link Response} processing is finished. This class also implement the {@link ProgressAsyncHandler} callback,
25-
* all doing nothing except returning {@link org.asynchttpclient.AsyncHandler.STATE#CONTINUE}
26+
* all doing nothing except returning {@link org.asynchttpclient.AsyncHandler.State#CONTINUE}
2627
*
2728
* @param <T> Type of the value that will be returned by the associated {@link java.util.concurrent.Future}
2829
*/
2930
public abstract class AsyncCompletionHandler<T> implements AsyncHandler<T>, ProgressAsyncHandler<T> {
3031

31-
private final Logger log = LoggerFactory.getLogger(AsyncCompletionHandlerBase.class);
32+
private static final Logger LOGGER = LoggerFactory.getLogger(AsyncCompletionHandler.class);
3233
private final Response.ResponseBuilder builder = new Response.ResponseBuilder();
3334

3435
/**
3536
* {@inheritDoc}
3637
*/
37-
public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception {
38+
public State onBodyPartReceived(final HttpResponseBodyPart content) throws Exception {
3839
builder.accumulate(content);
39-
return STATE.CONTINUE;
40+
return State.CONTINUE;
4041
}
4142

4243
/**
4344
* {@inheritDoc}
4445
*/
45-
public STATE onStatusReceived(final HttpResponseStatus status) throws Exception {
46+
public State onStatusReceived(final HttpResponseStatus status) throws Exception {
4647
builder.reset();
4748
builder.accumulate(status);
48-
return STATE.CONTINUE;
49+
return State.CONTINUE;
4950
}
5051

5152
/**
5253
* {@inheritDoc}
5354
*/
54-
public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception {
55+
public State onHeadersReceived(final HttpResponseHeaders headers) throws Exception {
5556
builder.accumulate(headers);
56-
return STATE.CONTINUE;
57+
return State.CONTINUE;
5758
}
5859

5960
/**
@@ -67,14 +68,11 @@ public final T onCompleted() throws Exception {
6768
* {@inheritDoc}
6869
*/
6970
public void onThrowable(Throwable t) {
70-
log.debug(t.getMessage(), t);
71+
LOGGER.debug(t.getMessage(), t);
7172
}
7273

7374
/**
7475
* Invoked once the HTTP response processing is finished.
75-
* <p/>
76-
* <p/>
77-
* Gets always invoked as last callback method.
7876
*
7977
* @param response The {@link Response}
8078
* @return T Value that will be returned by the associated {@link java.util.concurrent.Future}
@@ -86,20 +84,20 @@ public void onThrowable(Throwable t) {
8684
* Invoked when the content (a {@link java.io.File}, {@link String} or {@link java.io.FileInputStream} has been fully
8785
* written on the I/O socket.
8886
*
89-
* @return a {@link org.asynchttpclient.AsyncHandler.STATE} telling to CONTINUE or ABORT the current processing.
87+
* @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE or ABORT the current processing.
9088
*/
91-
public STATE onHeaderWriteCompleted() {
92-
return STATE.CONTINUE;
89+
public State onHeadersWritten() {
90+
return State.CONTINUE;
9391
}
9492

9593
/**
9694
* Invoked when the content (a {@link java.io.File}, {@link String} or {@link java.io.FileInputStream} has been fully
9795
* written on the I/O socket.
9896
*
99-
* @return a {@link org.asynchttpclient.AsyncHandler.STATE} telling to CONTINUE or ABORT the current processing.
97+
* @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE or ABORT the current processing.
10098
*/
101-
public STATE onContentWriteCompleted() {
102-
return STATE.CONTINUE;
99+
public State onContentWritten() {
100+
return State.CONTINUE;
103101
}
104102

105103
/**
@@ -108,9 +106,9 @@ public STATE onContentWriteCompleted() {
108106
* @param amount The amount of bytes to transfer
109107
* @param current The amount of bytes transferred
110108
* @param total The total number of bytes transferred
111-
* @return a {@link org.asynchttpclient.AsyncHandler.STATE} telling to CONTINUE or ABORT the current processing.
109+
* @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE or ABORT the current processing.
112110
*/
113-
public STATE onContentWriteProgress(long amount, long current, long total) {
114-
return STATE.CONTINUE;
111+
public State onContentWriteProgress(long amount, long current, long total) {
112+
return State.CONTINUE;
115113
}
116114
}

api/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Simple {@link AsyncHandler} of type {@link Response}
2424
*/
2525
public class AsyncCompletionHandlerBase extends AsyncCompletionHandler<Response> {
26-
private final Logger log = LoggerFactory.getLogger(AsyncCompletionHandlerBase.class);
26+
private static final Logger LOGGER = LoggerFactory.getLogger(AsyncCompletionHandlerBase.class);
2727

2828
/**
2929
* {@inheritDoc}
@@ -38,6 +38,6 @@ public Response onCompleted(Response response) throws Exception {
3838
*/
3939
@Override
4040
public void onThrowable(Throwable t) {
41-
log.debug(t.getMessage(), t);
41+
LOGGER.debug(t.getMessage(), t);
4242
}
4343
}

0 commit comments

Comments
 (0)