Skip to content

Commit 3d7f17c

Browse files
authored
Update ApacheHttpTransport implementation (#558)
* Move apache httpclient dependency to apache adapter artifacts * Rewrite Apache adapter to use new APIs * Cleanup apache implementations * Fix tests * Fix checkstyle * Fix dependencies - google-http-client does depend on commons-codec * Publish both apache adapters as google-http-client-apache with version 1.x and 2.0 * Fix dependency versions * Remove ApacheHttpTransport.Builder for 2.0 We are providing a subset of builder options and we cannot change setting after the HttpClient has been built. We should allow users to just provide their implementation via the constructor. * Allow `shutdown` to throw the IOException from closing the httpClient
1 parent 280117f commit 3d7f17c

File tree

10 files changed

+168
-380
lines changed

10 files changed

+168
-380
lines changed

google-http-client-apache-legacy/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<version>1.27.1-SNAPSHOT</version><!-- {x-version-update:google-http-client-parent:current} -->
88
<relativePath>../pom.xml</relativePath>
99
</parent>
10-
<artifactId>google-http-client-apache-legacy</artifactId>
10+
<artifactId>google-http-client-apache</artifactId>
1111
<version>1.27.1-SNAPSHOT</version><!-- {x-version-update:google-http-client-apache-legacy:current} -->
12-
<name>Apache HTTP transport for the Google HTTP Client Library for Java.</name>
12+
<name>Legacy Apache HTTP transport for the Google HTTP Client Library for Java.</name>
1313

1414
<build>
1515
<plugins>
@@ -102,6 +102,11 @@
102102
<artifactId>guava</artifactId>
103103
<scope>test</scope>
104104
</dependency>
105+
<dependency>
106+
<groupId>org.apache.httpcomponents</groupId>
107+
<artifactId>httpclient</artifactId>
108+
<version>4.2.6</version>
109+
</dependency>
105110
<dependency>
106111
<groupId>org.mockito</groupId>
107112
<artifactId>mockito-all</artifactId>

google-http-client-apache/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>google-http-client-apache</artifactId>
11-
<version>1.27.1-SNAPSHOT</version><!-- {x-version-update:google-http-client-apache:current} -->
11+
<version>2.0.1-SNAPSHOT</version><!-- {x-version-update:google-http-client-apache:current} -->
1212
<name>Apache HTTP transport for the Google HTTP Client Library for Java.</name>
1313

1414
<build>
@@ -102,6 +102,10 @@
102102
<artifactId>guava</artifactId>
103103
<scope>test</scope>
104104
</dependency>
105+
<dependency>
106+
<groupId>org.apache.httpcomponents</groupId>
107+
<artifactId>httpclient</artifactId>
108+
</dependency>
105109
<dependency>
106110
<groupId>org.mockito</groupId>
107111
<artifactId>mockito-all</artifactId>

google-http-client-apache/src/main/java/com/google/api/client/http/apache/ApacheHttpRequest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
import java.io.IOException;
2121
import org.apache.http.HttpEntityEnclosingRequest;
2222
import org.apache.http.client.HttpClient;
23+
import org.apache.http.client.config.RequestConfig;
2324
import org.apache.http.client.methods.HttpRequestBase;
24-
import org.apache.http.conn.params.ConnManagerParams;
25-
import org.apache.http.params.HttpConnectionParams;
26-
import org.apache.http.params.HttpParams;
2725

2826
/**
2927
* @author Yaniv Inbar
@@ -33,9 +31,12 @@ final class ApacheHttpRequest extends LowLevelHttpRequest {
3331

3432
private final HttpRequestBase request;
3533

34+
private RequestConfig.Builder requestConfig;
35+
3636
ApacheHttpRequest(HttpClient httpClient, HttpRequestBase request) {
3737
this.httpClient = httpClient;
3838
this.request = request;
39+
this.requestConfig = RequestConfig.custom().setRedirectsEnabled(false);
3940
}
4041

4142
@Override
@@ -45,10 +46,8 @@ public void addHeader(String name, String value) {
4546

4647
@Override
4748
public void setTimeout(int connectTimeout, int readTimeout) throws IOException {
48-
HttpParams params = request.getParams();
49-
ConnManagerParams.setTimeout(params, connectTimeout);
50-
HttpConnectionParams.setConnectionTimeout(params, connectTimeout);
51-
HttpConnectionParams.setSoTimeout(params, readTimeout);
49+
requestConfig.setConnectionRequestTimeout(connectTimeout)
50+
.setSocketTimeout(readTimeout);
5251
}
5352

5453
@Override
@@ -62,6 +61,7 @@ public LowLevelHttpResponse execute() throws IOException {
6261
entity.setContentType(getContentType());
6362
((HttpEntityEnclosingRequest) request).setEntity(entity);
6463
}
64+
request.setConfig(requestConfig.build());
6565
return new ApacheHttpResponse(request, httpClient.execute(request));
6666
}
6767
}

0 commit comments

Comments
 (0)