Creating ApacheHttpTransport using HttpClient constructor argument is throwing java.lang.UnsupportedOperationException
public static HttpTransport getHttpTransport() {
final PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager(CONNECTION_TTL_MILLIS,
TimeUnit.MILLISECONDS);
httpClientConnectionManager.setDefaultMaxPerRoute(TOTAL_MAX_CONNECTIONS_PER_ROUTE);
httpClientConnectionManager.setMaxTotal(TOTAL_MAX_CONNECTIONS);
httpClientConnectionManager.setValidateAfterInactivity(INACTIVE_CONNECTION_VALIDATION_MILLIS);
final RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(CONNECT_TIMEOUT_MILLLIS)
.setSocketTimeout(SOCKET_TIMEOUT_MILLIS)
.build();
final CloseableHttpClient httpClient = HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setConnectionManager(httpClientConnectionManager)
.build();
return new ApacheHttpTransport(httpClient);
}
public static void main(String args[]) {
ApacheHttpClientUtil.getHttpTransport();
}
Environment details
- OS: Mac 10.13.5 (17F77)
- Java version: 1.8.0_161
- google-http-java-client version: 1.25.0
Steps to reproduce
Create ApacheHttpTransport object using constructor which takes HttpClient object.
HttpClient is created using HttpClientBuilder.
Stacktrace
Caused by: java.lang.UnsupportedOperationException: null
at org.apache.http.impl.client.InternalHttpClient.getParams(InternalHttpClient.java:211)
at com.google.api.client.http.apache.ApacheHttpTransport.<init>(ApacheHttpTransport.java:126)
at com.mobileiron.corona.efa.config.FireBaseConfiguration$ApacheHttpClientUtil.getHttpTransport(FireBaseConfiguration.java:133)
at com.mobileiron.corona.efa.config.FireBaseConfiguration.<init>(FireBaseConfiguration.java:47)
at com.mobileiron.corona.efa.config.FireBaseConfiguration$$EnhancerBySpringCGLIB$$a638c5f0.<init>(<generated>)
at sun.reflect.GeneratedConstructorAccessor437.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:170)
... 88 common frames omitted
It looks like HttpClientBuilder is creating instance of InternalHttpClient which throws UnsupportedOperationException when calling getParams method. Since many people use apache client's HttpClientBuilder it will good to fix the issue.
Most of the APIs(APIs from Apache Http Client) used by ApacheHttpTransport are deprecated.
Creating ApacheHttpTransport using HttpClient constructor argument is throwing java.lang.UnsupportedOperationException
Environment details
Steps to reproduce
Create ApacheHttpTransport object using constructor which takes HttpClient object.
HttpClient is created using HttpClientBuilder.
Stacktrace
It looks like HttpClientBuilder is creating instance of InternalHttpClient which throws UnsupportedOperationException when calling getParams method. Since many people use apache client's HttpClientBuilder it will good to fix the issue.