Aws-sdk-android: Allow to use okHttp for http traffic

Created on 7 Aug 2016  路  3Comments  路  Source: aws-amplify/aws-sdk-android

Hi, I'm interested in the possibility of using okHttp with this SDK. Would it be possible to use it if it's in the classpath instead of the current http client? It would allow me to customize many things and integrate other libraries that are optimized for android. Some benefits:

  • Use Retrofit
  • Use interceptors, for example, for logging http traffic, request times...
  • Choose cache size and policy.
  • Use HTTP 2
  • Not use deprecated classes like ClientConnectionManager (deprecated in 2013)
  • ...

Most helpful comment

@yairkukielka if all you need is AWS Signature than you can give a try to this OkHttp interceptor: https://github.com/Ghedeon/AwsInterceptor. That being said, I'm wondering if AWS team is planning to provide something similar, more friendly to Retrofit + OkHttp (officially pushed by Google as a standard now). It will unify the networking layer in our apps, so you don't have to mix AWS and Retrofit interfaces for different calls and can also save a lot of effort, by not reinventing the wheel, @Service, @Operation, @Parameter seems to be an exact clone of Square's implementation.

All 3 comments

For interceptors, the SDK natively supports adding request handlers to any request client. For any client, see the addRequestHandler(RequestHandler2).

For more advanced things, the SDK does provide the ability to implement the entire Http Client. For any given service client, there is a constructor which takes in an HttpClient interface, which lets you replace the http client the SDK will use.

See:
https://github.com/aws/aws-sdk-android/blob/master/aws-android-sdk-core/src/main/java/com/amazonaws/http/HttpClient.java (Make sure you read the comments at the top of the interface)

An example of where you would place your implementation is
https://github.com/aws/aws-sdk-android/blob/master/aws-android-sdk-kinesis/src/main/java/com/amazonaws/services/kinesis/AmazonKinesisClient.java

Line 253: " public AmazonKinesisClient(AWSCredentialsProvider awsCredentialsProvider,
ClientConfiguration clientConfiguration, HttpClient httpClient) {"

Please feel free to open this issue again if you need some more information.

The main point of this feature is to reduce the dependency of the internal HTTP components, this is one of the most needed features on this library. This would be solved implementing interfaces to create these connections.

Would be amazing to remove any HTTP component of this library and offer this as a external dependency, reducing the method count.

@yairkukielka if all you need is AWS Signature than you can give a try to this OkHttp interceptor: https://github.com/Ghedeon/AwsInterceptor. That being said, I'm wondering if AWS team is planning to provide something similar, more friendly to Retrofit + OkHttp (officially pushed by Google as a standard now). It will unify the networking layer in our apps, so you don't have to mix AWS and Retrofit interfaces for different calls and can also save a lot of effort, by not reinventing the wheel, @Service, @Operation, @Parameter seems to be an exact clone of Square's implementation.

Was this page helpful?
0 / 5 - 0 ratings