Package com.janeirodigital.sai.core.http
Class HttpClientFactory
java.lang.Object
com.janeirodigital.sai.core.http.HttpClientFactory
- All Implemented Interfaces:
com.janeirodigital.shapetrees.client.okhttp.OkHttpClientFactory
public class HttpClientFactory
extends Object
implements com.janeirodigital.shapetrees.client.okhttp.OkHttpClientFactory
Factory to get, cache, and clear OkHttp HTTP clients matching provided configurations.
Can enable / disable SSL validation and/or Shape Tree validation
Can enable / disable SSL validation and/or Shape Tree validation
- See Also:
-
- OkHttp - HTTP client library from Square
- shapetrees-java - Shape Trees client library implementation
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Internal class to manage configuration options for http clients -
Constructor Summary
ConstructorsConstructorDescriptionHttpClientFactory
(boolean validateSsl, boolean validateShapeTrees, boolean refreshTokens) HttpClientFactory
(boolean validateSsl, boolean validateShapeTrees, boolean refreshTokens, com.janeirodigital.sai.authentication.AuthorizedSessionAccessor sessionAccessor) -
Method Summary
Modifier and TypeMethodDescriptionokhttp3.OkHttpClient
get()
okhttp3.OkHttpClient
get
(boolean validateSsl, boolean validateShapeTrees, boolean refreshTokens) Factory to provide an OkHttpClient configured to enable or disable SSL and/or Shape Tree validation based on the provided options.okhttp3.OkHttpClient
getClientForConfiguration
(boolean validateSsl, boolean validateShapeTrees, boolean refreshTokens) Build and return an OkHttpClient based on the provided options for SSL Validation, Shape Tree Validation, and Token Refresh.okhttp3.OkHttpClient
Implementation of theOkHttpClientFactory
interface provided from shapetrees-java-client-okhttp.boolean
isEmpty()
Identifies whether the local OkHttp client cache is empty or notvoid
Shuts down each initialized OkHttp client in the local cache, and then empties them from it.
-
Constructor Details
-
HttpClientFactory
public HttpClientFactory(boolean validateSsl, boolean validateShapeTrees, boolean refreshTokens, com.janeirodigital.sai.authentication.AuthorizedSessionAccessor sessionAccessor) throws SaiException - Throws:
SaiException
-
HttpClientFactory
public HttpClientFactory(boolean validateSsl, boolean validateShapeTrees, boolean refreshTokens) throws SaiException - Throws:
SaiException
-
-
Method Details
-
get
- Throws:
SaiException
-
get
public okhttp3.OkHttpClient get(boolean validateSsl, boolean validateShapeTrees, boolean refreshTokens) throws SaiException Factory to provide an OkHttpClient configured to enable or disable SSL and/or Shape Tree validation based on the provided options. A small array of clients is maintained such that there is a given client for each unique configuration.
SSL Validation should never be disabled in production!- Parameters:
validateSsl
- Disables client/server SSL validation when false.validateShapeTrees
- Disables client-side shape tree validation when false.refreshTokens
- Disables automatic attempt to refresh access tokens on HTTP 401 responses when false- Returns:
- Configured OkHttpClient
- Throws:
SaiException
- See Also:
-
getClientForConfiguration
public okhttp3.OkHttpClient getClientForConfiguration(boolean validateSsl, boolean validateShapeTrees, boolean refreshTokens) throws NoSuchAlgorithmException, KeyManagementException, SaiException Build and return an OkHttpClient based on the provided options for SSL Validation, Shape Tree Validation, and Token Refresh. SSL is disabled by installing an all-trusting certificate manager. Shape tree validation is enabled by injecting an OkHttp interceptor.- Parameters:
validateSsl
- Disables client/server SSL validation when false.validateShapeTrees
- Disables client-side shape tree validation when false.refreshTokens
- Disables automatic attempt to refresh access tokens on HTTP 401 responses when false- Returns:
- Configured OkHttpClient
- Throws:
NoSuchAlgorithmException
KeyManagementException
SaiException
-
getOkHttpClient
public okhttp3.OkHttpClient getOkHttpClient() throws com.janeirodigital.shapetrees.core.exceptions.ShapeTreeExceptionImplementation of theOkHttpClientFactory
interface provided from shapetrees-java-client-okhttp. Allows this factory to be used as the source of okhttp clients by that library.
This call explicitly setsvalidateShapeTrees
to false because it is the responsibility ofOkHttpClientFactory
enable validation, and would create an infinite loop if it were set to true.- Specified by:
getOkHttpClient
in interfacecom.janeirodigital.shapetrees.client.okhttp.OkHttpClientFactory
- Returns:
- OkHttpClient
- Throws:
com.janeirodigital.shapetrees.core.exceptions.ShapeTreeException
-
resetClients
public void resetClients()Shuts down each initialized OkHttp client in the local cache, and then empties them from it. -
isEmpty
public boolean isEmpty()Identifies whether the local OkHttp client cache is empty or not- Returns:
- true when the cache is empty
-