Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose client configuration through api factory #158

Merged
merged 4 commits into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.amazonaws.mobileconnectors.apigateway;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWS4Signer;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.Signer;
Expand All @@ -38,6 +39,7 @@ public class ApiClientFactory {
private String apiKey;
private String regionOverride;
private AWSCredentialsProvider provider;
private ClientConfiguration clientConfiguration;

/**
* Sets the endpoint of the APIs.
Expand Down Expand Up @@ -73,6 +75,17 @@ public ApiClientFactory region(String region) {
return this;
}

/**
* Specify the client configuration to use with this factory
*
* @param clientConfiguration Configuration to use
* @return the factory itself for chaining
*/
public ApiClientFactory clientConfiguration(ClientConfiguration clientConfiguration) {
this.clientConfiguration = clientConfiguration;
return this;
}

/**
* Sets the credentials provider, needed if APIs require authentication.
*
Expand Down Expand Up @@ -110,15 +123,17 @@ public <T> T build(Class<T> apiClass) {
/**
* Gets an invocation handler for the given API.
*
* @param apiClass API class
* @param endpoint Request endpoint
* @param apiName API class name
* @return an invocation handler
*/
ApiClientHandler getHandler(String endpoint, String apiName) {
Signer signer = provider == null ? null : getSigner(getRegion(endpoint));

ApiClientHandler handler = new ApiClientHandler(
endpoint, apiName, signer, provider, apiKey);
return handler;
// Ensure we always pass a configuration to the handler
ClientConfiguration configuration = (clientConfiguration == null) ? new ClientConfiguration() : clientConfiguration;

return new ApiClientHandler(endpoint, apiName, signer, provider, apiKey, configuration);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ class ApiClientHandler implements InvocationHandler {
private final ClientConfiguration clientConfiguration;

ApiClientHandler(String endpoint, String apiName,
Signer signer, AWSCredentialsProvider provider, String apiKey) {
Signer signer, AWSCredentialsProvider provider, String apiKey, ClientConfiguration clientConfiguration) {
this.endpoint = endpoint;
this.apiName = apiName;
this.signer = signer;
this.provider = provider;
this.apiKey = apiKey;
this.clientConfiguration = clientConfiguration;

clientConfiguration = new ClientConfiguration();
client = new UrlHttpClient(clientConfiguration);
client = new UrlHttpClient(this.clientConfiguration);
requestFactory = new HttpRequestFactory();
}

Expand Down