use of com.adobe.target.edge.client.ClientProxyConfig in project target-java-sdk by adobe.
the class DefaultGeoClient method start.
public void start(ClientConfig clientConfig) {
this.geoUrl = "https://" + clientConfig.getOnDeviceConfigHostname() + GEO_PATH;
unirestInstance.config().socketTimeout(clientConfig.getSocketTimeout()).connectTimeout(clientConfig.getConnectTimeout()).concurrency(clientConfig.getMaxConnectionsTotal(), clientConfig.getMaxConnectionsPerHost()).automaticRetries(clientConfig.isEnabledRetries()).enableCookieManagement(false);
if (clientConfig.isLogRequestStatus()) {
unirestInstance.config().instrumentWith(new TargetMetrics(new LoggingMetricConsumer()));
}
if (clientConfig.isProxyEnabled()) {
ClientProxyConfig proxyConfig = clientConfig.getProxyConfig();
if (proxyConfig.isAuthProxy()) {
unirestInstance.config().proxy(proxyConfig.getHost(), proxyConfig.getPort(), proxyConfig.getUsername(), proxyConfig.getPassword());
} else {
unirestInstance.config().proxy(proxyConfig.getHost(), proxyConfig.getPort());
}
}
}
use of com.adobe.target.edge.client.ClientProxyConfig in project target-java-sdk by adobe.
the class DefaultTargetHttpClientTest method testProxyConfigSetWithNoAuthentication.
@Test
void testProxyConfigSetWithNoAuthentication() {
ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).proxyConfig(new ClientProxyConfig(PROXY_HOST, PROXY_PORT)).build();
DefaultTargetHttpClient targetClient = new DefaultTargetHttpClient(clientConfig);
UnirestInstance unirestInstance = targetClient.getUnirestInstance();
Proxy unirestProxy = unirestInstance.config().getProxy();
assertNotNull(unirestProxy);
assertEquals(PROXY_HOST, unirestProxy.getHost());
assertEquals(PROXY_PORT, unirestProxy.getPort());
assertNull(unirestProxy.getUsername());
assertNull(unirestProxy.getPassword());
targetClient.close();
}
use of com.adobe.target.edge.client.ClientProxyConfig in project target-java-sdk by adobe.
the class DefaultTargetHttpClientTest method testProxyConfigSetWithAuthentication.
@Test
void testProxyConfigSetWithAuthentication() {
ClientConfig clientConfig = ClientConfig.builder().organizationId(TEST_ORG_ID).proxyConfig(new ClientProxyConfig(PROXY_HOST, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWORD)).build();
DefaultTargetHttpClient targetClient = new DefaultTargetHttpClient(clientConfig);
UnirestInstance unirestInstance = targetClient.getUnirestInstance();
Proxy unirestProxy = unirestInstance.config().getProxy();
assertNotNull(unirestProxy);
assertEquals(PROXY_HOST, unirestProxy.getHost());
assertEquals(PROXY_PORT, unirestProxy.getPort());
assertEquals(PROXY_USERNAME, unirestProxy.getUsername());
assertEquals(PROXY_PASSWORD, unirestProxy.getPassword());
targetClient.close();
}
use of com.adobe.target.edge.client.ClientProxyConfig in project target-java-sdk by adobe.
the class DefaultRuleLoader method start.
@Override
public synchronized void start(final ClientConfig clientConfig, TelemetryService telemetryService) {
if (!clientConfig.isOnDeviceDecisioningEnabled()) {
return;
}
if (started) {
return;
}
ObjectMapper mapper = new JacksonObjectMapper();
byte[] artifactPayload = clientConfig.getOnDeviceArtifactPayload();
if (artifactPayload != null) {
String payload = new String(artifactPayload, StandardCharsets.UTF_8);
OnDeviceDecisioningRuleSet ruleSet = mapper.readValue(payload, new GenericType<OnDeviceDecisioningRuleSet>() {
});
String invalidMessage = invalidRuleSetMessage(ruleSet, null);
if (invalidMessage == null) {
setLatestRules(ruleSet);
OnDeviceDecisioningHandler handler = clientConfig.getOnDeviceDecisioningHandler();
if (handler != null && !succeeded) {
succeeded = true;
handler.onDeviceDecisioningReady();
}
} else {
logger.warn(invalidMessage);
TargetExceptionHandler handler = clientConfig.getExceptionHandler();
if (handler != null) {
handler.handleException(new TargetClientException(invalidMessage));
}
}
}
started = true;
retries = 0;
if (unirestInstance != null) {
unirestInstance.config().socketTimeout(clientConfig.getSocketTimeout()).connectTimeout(clientConfig.getConnectTimeout()).concurrency(clientConfig.getMaxConnectionsTotal(), clientConfig.getMaxConnectionsPerHost()).automaticRetries(clientConfig.isEnabledRetries()).enableCookieManagement(false).setObjectMapper(mapper).setDefaultHeader("Accept", "application/json");
if (clientConfig.isProxyEnabled()) {
ClientProxyConfig proxyConfig = clientConfig.getProxyConfig();
if (proxyConfig.isAuthProxy()) {
unirestInstance.config().proxy(proxyConfig.getHost(), proxyConfig.getPort(), proxyConfig.getUsername(), proxyConfig.getPassword());
} else {
unirestInstance.config().proxy(proxyConfig.getHost(), proxyConfig.getPort());
}
}
}
this.clientConfig = clientConfig;
this.telemetryService = telemetryService;
this.scheduleTimer(0);
}
Aggregations