Search in sources :

Example 1 with ClientProxyConfig

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());
        }
    }
}
Also used : ClientProxyConfig(com.adobe.target.edge.client.ClientProxyConfig) TargetMetrics(com.adobe.target.edge.client.http.TargetMetrics) LoggingMetricConsumer(com.adobe.target.edge.client.http.LoggingMetricConsumer)

Example 2 with ClientProxyConfig

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();
}
Also used : ClientProxyConfig(com.adobe.target.edge.client.ClientProxyConfig) UnirestInstance(kong.unirest.UnirestInstance) Proxy(kong.unirest.Proxy) ClientConfig(com.adobe.target.edge.client.ClientConfig) Test(org.junit.jupiter.api.Test)

Example 3 with ClientProxyConfig

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();
}
Also used : ClientProxyConfig(com.adobe.target.edge.client.ClientProxyConfig) UnirestInstance(kong.unirest.UnirestInstance) Proxy(kong.unirest.Proxy) ClientConfig(com.adobe.target.edge.client.ClientConfig) Test(org.junit.jupiter.api.Test)

Example 4 with ClientProxyConfig

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);
}
Also used : ClientProxyConfig(com.adobe.target.edge.client.ClientProxyConfig) TargetClientException(com.adobe.target.edge.client.exception.TargetClientException) JacksonObjectMapper(com.adobe.target.edge.client.http.JacksonObjectMapper) TargetExceptionHandler(com.adobe.target.edge.client.exception.TargetExceptionHandler) JacksonObjectMapper(com.adobe.target.edge.client.http.JacksonObjectMapper) OnDeviceDecisioningHandler(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningHandler) OnDeviceDecisioningRuleSet(com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)

Aggregations

ClientProxyConfig (com.adobe.target.edge.client.ClientProxyConfig)4 ClientConfig (com.adobe.target.edge.client.ClientConfig)2 Proxy (kong.unirest.Proxy)2 UnirestInstance (kong.unirest.UnirestInstance)2 Test (org.junit.jupiter.api.Test)2 TargetClientException (com.adobe.target.edge.client.exception.TargetClientException)1 TargetExceptionHandler (com.adobe.target.edge.client.exception.TargetExceptionHandler)1 JacksonObjectMapper (com.adobe.target.edge.client.http.JacksonObjectMapper)1 LoggingMetricConsumer (com.adobe.target.edge.client.http.LoggingMetricConsumer)1 TargetMetrics (com.adobe.target.edge.client.http.TargetMetrics)1 OnDeviceDecisioningHandler (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningHandler)1 OnDeviceDecisioningRuleSet (com.adobe.target.edge.client.model.ondevice.OnDeviceDecisioningRuleSet)1