Skip to content

Commit 66e5a23

Browse files
fgoncalvesfosterzhang
authored andcommitted
Expose client configuration through api factory (#158)
* Exposing client configuration on the api gatway factory Signed-off-by: Fred <[email protected]> * Ensure we always have a client configuration Signed-off-by: Fred <[email protected]> * Remove previously added formatting Signed-off-by: Fred <[email protected]> * Small formatting issue Signed-off-by: Fred <[email protected]>
1 parent 64b6435 commit 66e5a23

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

aws-android-sdk-apigateway-core/src/main/java/com/amazonaws/mobileconnectors/apigateway/ApiClientFactory.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package com.amazonaws.mobileconnectors.apigateway;
1717

18+
import com.amazonaws.ClientConfiguration;
1819
import com.amazonaws.auth.AWS4Signer;
1920
import com.amazonaws.auth.AWSCredentialsProvider;
2021
import com.amazonaws.auth.Signer;
@@ -38,6 +39,7 @@ public class ApiClientFactory {
3839
private String apiKey;
3940
private String regionOverride;
4041
private AWSCredentialsProvider provider;
42+
private ClientConfiguration clientConfiguration;
4143

4244
/**
4345
* Sets the endpoint of the APIs.
@@ -73,6 +75,17 @@ public ApiClientFactory region(String region) {
7375
return this;
7476
}
7577

78+
/**
79+
* Specify the client configuration to use with this factory
80+
*
81+
* @param clientConfiguration Configuration to use
82+
* @return the factory itself for chaining
83+
*/
84+
public ApiClientFactory clientConfiguration(ClientConfiguration clientConfiguration) {
85+
this.clientConfiguration = clientConfiguration;
86+
return this;
87+
}
88+
7689
/**
7790
* Sets the credentials provider, needed if APIs require authentication.
7891
*
@@ -110,15 +123,17 @@ public <T> T build(Class<T> apiClass) {
110123
/**
111124
* Gets an invocation handler for the given API.
112125
*
113-
* @param apiClass API class
126+
* @param endpoint Request endpoint
127+
* @param apiName API class name
114128
* @return an invocation handler
115129
*/
116130
ApiClientHandler getHandler(String endpoint, String apiName) {
117131
Signer signer = provider == null ? null : getSigner(getRegion(endpoint));
118132

119-
ApiClientHandler handler = new ApiClientHandler(
120-
endpoint, apiName, signer, provider, apiKey);
121-
return handler;
133+
// Ensure we always pass a configuration to the handler
134+
ClientConfiguration configuration = (clientConfiguration == null) ? new ClientConfiguration() : clientConfiguration;
135+
136+
return new ApiClientHandler(endpoint, apiName, signer, provider, apiKey, configuration);
122137
}
123138

124139
/**

aws-android-sdk-apigateway-core/src/main/java/com/amazonaws/mobileconnectors/apigateway/ApiClientHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ class ApiClientHandler implements InvocationHandler {
6767
private final ClientConfiguration clientConfiguration;
6868

6969
ApiClientHandler(String endpoint, String apiName,
70-
Signer signer, AWSCredentialsProvider provider, String apiKey) {
70+
Signer signer, AWSCredentialsProvider provider, String apiKey, ClientConfiguration clientConfiguration) {
7171
this.endpoint = endpoint;
7272
this.apiName = apiName;
7373
this.signer = signer;
7474
this.provider = provider;
7575
this.apiKey = apiKey;
76+
this.clientConfiguration = clientConfiguration;
7677

77-
clientConfiguration = new ClientConfiguration();
78-
client = new UrlHttpClient(clientConfiguration);
78+
client = new UrlHttpClient(this.clientConfiguration);
7979
requestFactory = new HttpRequestFactory();
8080
}
8181

0 commit comments

Comments
 (0)