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

TNT-49972 - Fix ODD rules request proxy caching issue #77

Merged
merged 3 commits into from
Jun 18, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.6.0] - 2024-06-13
### Added
- (On Device Decisioning) Added new configuration option (`shouldArtifactRequestBypassProxyCache`). When enabled and a proxy is configured, send empty Authorization header on artifact rules request to bypass proxy-level cache

## [2.5.1] - 2024-01-12
### Fixed
- Fix geo context not being cleaned up
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=com.adobe.target
version=2.5.1
version=2.6.0
mavenCentralUrl=https://oss.sonatype.org/service/local/staging/deploy/maven2
pomDescription=Adobe Target Java SDK
pomURL=https://docs.adobe.com/content/help/en/target/using/implement-target/server-side/api-and-sdk-overview.html
Expand Down
104 changes: 69 additions & 35 deletions src/main/java/com/adobe/target/edge/client/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ClientConfig {
private boolean telemetryEnabled;
private List<String> onDeviceAllMatchingRulesMboxes;
private HttpClient httpClient;
private boolean shouldArtifactRequestBypassProxyCache;

public String getClient() {
return client;
Expand Down Expand Up @@ -172,6 +173,10 @@ public boolean isTelemetryEnabled() {
return telemetryEnabled;
}

public boolean shouldArtifactRequestBypassProxyCache() {
return shouldArtifactRequestBypassProxyCache;
}

public static final class ClientConfigBuilder {
private static final String CLUSTER_PREFIX = "mboxedge";
private static final String DELIVERY_PATH_SUFFIX = "/rest/v1/delivery";
Expand Down Expand Up @@ -202,11 +207,13 @@ public static final class ClientConfigBuilder {
private boolean telemetryEnabled = true;
private List<String> onDeviceAllMatchingRulesMboxes;
private HttpClient httpClient;
private boolean shouldArtifactRequestBypassProxyCache = false;

private ClientConfigBuilder() {}

/**
* Client Code
*
* @param client
* @return ClientConfigBuilder
*/
Expand All @@ -217,6 +224,7 @@ public ClientConfigBuilder client(String client) {

/**
* Organization ID
*
* @param organizationId
* @return ClientConfigBuilder
*/
Expand All @@ -227,6 +235,7 @@ public ClientConfigBuilder organizationId(String organizationId) {

/**
* Server Domain
*
* @param serverDomain
* @return ClientConfigBuilder
*/
Expand All @@ -237,6 +246,7 @@ public ClientConfigBuilder serverDomain(String serverDomain) {

/**
* Default Property Token
*
* @param defaultPropertyToken
* @return ClientConfigBuilder
*/
Expand All @@ -246,8 +256,8 @@ public ClientConfigBuilder defaultPropertyToken(String defaultPropertyToken) {
}

/**
* Secure (HTTPS) or not
* Default value is <b>true</b>
* Secure (HTTPS) or not Default value is <b>true</b>
*
* @param secure
* @return ClientConfigBuilder
*/
Expand All @@ -257,8 +267,8 @@ public ClientConfigBuilder secure(boolean secure) {
}

/**
* Socket Timeout
* Default value is <b>10000</b>
* Socket Timeout Default value is <b>10000</b>
*
* @param socketTimeout
* @return ClientConfigBuilder
*/
Expand All @@ -268,8 +278,8 @@ public ClientConfigBuilder socketTimeout(int socketTimeout) {
}

/**
* Connect Timeout
* Default value is <b>10000</b>
* Connect Timeout Default value is <b>10000</b>
*
* @param connectTimeout
* @return ClientConfigBuilder
*/
Expand All @@ -279,8 +289,8 @@ public ClientConfigBuilder connectTimeout(int connectTimeout) {
}

/**
* Max Connections Per Host
* Default value is <b>100</b>
* Max Connections Per Host Default value is <b>100</b>
*
* @param maxConnectionsPerHost
* @return ClientConfigBuilder
*/
Expand All @@ -290,8 +300,8 @@ public ClientConfigBuilder maxConnectionsPerHost(int maxConnectionsPerHost) {
}

/**
* Max Connections Total
* Default value is <b>200</b>
* Max Connections Total Default value is <b>200</b>
*
* @param maxConnectionsTotal
* @return ClientConfigBuilder
*/
Expand All @@ -301,9 +311,10 @@ public ClientConfigBuilder maxConnectionsTotal(int maxConnectionsTotal) {
}

/**
* Total time to live (TTL) defines maximum life span of persistent connections regardless of their
* expiration setting. No persistent connection will be re-used past its TTL value.
* Total time to live (TTL) defines maximum life span of persistent connections regardless of
* their expiration setting. No persistent connection will be re-used past its TTL value.
* Default value is <b>-1</b> which means that connections will be kept alive indefinitely.
*
* @param connectionTtlMs
* @return ClientConfigBuilder
*/
Expand All @@ -313,11 +324,11 @@ public ClientConfigBuilder connectionTtlMs(int connectionTtlMs) {
}

/**
* Idle connection validation interval defines period of inactivity in milliseconds after which persistent
* connections must be re-validated prior to being leased to the consumer. Non-positive value effectively
* disables idle connection validation.
* Note: Only available for the Apache sync client
* Default value is <b>1000</b>
* Idle connection validation interval defines period of inactivity in milliseconds after which
* persistent connections must be re-validated prior to being leased to the consumer.
* Non-positive value effectively disables idle connection validation. Note: Only available for
* the Apache sync client Default value is <b>1000</b>
*
* @param idleConnectionValidationMs
* @return ClientConfigBuilder
*/
Expand All @@ -327,8 +338,9 @@ public ClientConfigBuilder idleConnectionValidationMs(int idleConnectionValidati
}

/**
* The time in seconds to evict idle connections from the connection pool.
* Default value is <b>20</b>
* The time in seconds to evict idle connections from the connection pool. Default value is
* <b>20</b>
*
* @param evictIdleConnectionsAfterSecs
* @return ClientConfigBuilder
*/
Expand All @@ -338,8 +350,8 @@ public ClientConfigBuilder evictIdleConnectionsAfterSecs(int evictIdleConnection
}

/**
* Enable retries
* Default value is <b>true</b>
* Enable retries Default value is <b>true</b>
*
* @param enableRetries
* @return ClientConfigBuilder
*/
Expand All @@ -349,8 +361,8 @@ public ClientConfigBuilder enableRetries(boolean enableRetries) {
}

/**
* Log requests
* Default value is <b>false</b>
* Log requests Default value is <b>false</b>
*
* @param logRequests
* @return ClientConfigBuilder
*/
Expand All @@ -360,8 +372,8 @@ public ClientConfigBuilder logRequests(boolean logRequests) {
}

/**
* Telemetry Enabled
* Default value is <b>true</b>
* Telemetry Enabled Default value is <b>true</b>
*
* @param telemetryEnabled
* @return ClientConfigBuilder
*/
Expand All @@ -371,8 +383,8 @@ public ClientConfigBuilder telemetryEnabled(boolean telemetryEnabled) {
}

/**
* Log request status
* Default value is <b>false</b>
* Log request status Default value is <b>false</b>
*
* @param logRequestStatus
* @return ClientConfigBuilder
*/
Expand All @@ -383,6 +395,7 @@ public ClientConfigBuilder logRequestStatus(boolean logRequestStatus) {

/**
* Request Interceptor
*
* @param requestInterceptor
* @return ClientConfigBuilder
*/
Expand All @@ -393,6 +406,7 @@ public ClientConfigBuilder requestInterceptor(HttpRequestInterceptor requestInte

/**
* Proxy Configuration
*
* @param proxyConfig
* @return ClientConfigBuilder
*/
Expand All @@ -403,6 +417,7 @@ public ClientConfigBuilder proxyConfig(ClientProxyConfig proxyConfig) {

/**
* Exception Handler
*
* @param handler
* @return ClientConfigBuilder
*/
Expand All @@ -413,6 +428,7 @@ public ClientConfigBuilder exceptionHandler(TargetExceptionHandler handler) {

/**
* On Device Decisioning Handler
*
* @param handler
* @return ClientConfigBuilder
*/
Expand All @@ -422,8 +438,8 @@ public ClientConfigBuilder onDeviceDecisioningHandler(OnDeviceDecisioningHandler
}

/**
* Default Decisioning Method
* Default value is <b>server-side</b>
* Default Decisioning Method Default value is <b>server-side</b>
*
* @param decisioningMethod
* @return ClientConfigBuilder
*/
Expand All @@ -433,8 +449,8 @@ public ClientConfigBuilder defaultDecisioningMethod(DecisioningMethod decisionin
}

/**
* On Device Environment
* Default value is <b>production</b>
* On Device Environment Default value is <b>production</b>
*
* @param environment
* @return ClientConfigBuilder
*/
Expand All @@ -444,8 +460,8 @@ public ClientConfigBuilder onDeviceEnvironment(String environment) {
}

/**
* On Device Config Hostname
* Default value is <b>assets.adobetarget.com</b>
* On Device Config Hostname Default value is <b>assets.adobetarget.com</b>
*
* @param hostname
* @return ClientConfigBuilder
*/
Expand All @@ -455,8 +471,8 @@ public ClientConfigBuilder onDeviceConfigHostname(String hostname) {
}

/**
* On Device Decisioning Polling Interval in seconds
* Default value is <b>300</b>
* On Device Decisioning Polling Interval in seconds Default value is <b>300</b>
*
* @param pollingInterval
* @return ClientConfigBuilder
*/
Expand All @@ -467,6 +483,7 @@ public ClientConfigBuilder onDeviceDecisioningPollingIntSecs(int pollingInterval

/**
* On Device Artifact Payload
*
* @param payload
* @return ClientConfigBuilder
*/
Expand All @@ -477,6 +494,7 @@ public ClientConfigBuilder onDeviceArtifactPayload(byte[] payload) {

/**
* On Device All Matching Rules Mboxes
*
* @param mboxes
* @return ClientConfigBuilder
*/
Expand All @@ -487,6 +505,7 @@ public ClientConfigBuilder onDeviceAllMatchingRulesMboxes(List<String> mboxes) {

/**
* HTTP Client
*
* @param httpClient
* @return ClientConfigBuilder
*/
Expand All @@ -495,6 +514,19 @@ public ClientConfigBuilder httpClient(HttpClient httpClient) {
return this;
}

/**
* On Device Decisioning - artifact request behind a proxy will include an empty Authorization
* header in order to bypass the proxy's internal cache
*
* @param shouldArtifactRequestBypassProxyCache
* @return ClientConfigBuilder
*/
public ClientConfigBuilder shouldArtifactRequestBypassProxyCache(
boolean shouldArtifactRequestBypassProxyCache) {
this.shouldArtifactRequestBypassProxyCache = shouldArtifactRequestBypassProxyCache;
return this;
}

public ClientConfig build() {
ClientConfig clientConfig = new ClientConfig();
Objects.requireNonNull(organizationId, "organization id cannot be null");
Expand Down Expand Up @@ -528,6 +560,8 @@ public ClientConfig build() {
clientConfig.onDeviceAllMatchingRulesMboxes = this.onDeviceAllMatchingRulesMboxes;
clientConfig.telemetryEnabled = this.telemetryEnabled;
clientConfig.httpClient = this.httpClient;
clientConfig.shouldArtifactRequestBypassProxyCache =
this.shouldArtifactRequestBypassProxyCache;
return clientConfig;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class DefaultRuleLoader implements RuleLoader {

private static final int MAX_RETRIES = 10;

private static final String EMPTY_STRING = "";

private OnDeviceDecisioningRuleSet latestRules;
private String lastETag;
private ClientConfig clientConfig;
Expand Down Expand Up @@ -116,6 +118,9 @@ public synchronized void start(
} else {
unirestInstance.config().proxy(proxyConfig.getHost(), proxyConfig.getPort());
}
if (clientConfig.shouldArtifactRequestBypassProxyCache()) {
unirestInstance.config().setDefaultHeader("Authorization", EMPTY_STRING);
}
}
}
this.clientConfig = clientConfig;
Expand Down
Loading