diff --git a/client/pom.xml b/client/pom.xml
index d9c1629a..2c1892ca 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -64,6 +64,7 @@
io.split.schemas:*
io.codigo.grammar:*
org.apache.httpcomponents.*
+ org.apache.hc.*
com.google.*
org.yaml:snakeyaml:*
diff --git a/client/src/main/java/io/split/client/SplitFactoryImpl.java b/client/src/main/java/io/split/client/SplitFactoryImpl.java
index b4877708..22384f5d 100644
--- a/client/src/main/java/io/split/client/SplitFactoryImpl.java
+++ b/client/src/main/java/io/split/client/SplitFactoryImpl.java
@@ -121,7 +121,7 @@
import static io.split.client.utils.SplitExecutorFactory.buildExecutorService;
public class SplitFactoryImpl implements SplitFactory {
- private static final org.slf4j.Logger _log = LoggerFactory.getLogger(SplitFactoryImpl.class);
+ private static final org.slf4j.Logger _log = LoggerFactory.getLogger(SplitFactoryImpl.class);
private static final String LEGACY_LOG_MESSAGE = "The sdk initialize in localhost mode using Legacy file. The splitFile or "
+
"inputStream doesn't add it to the config.";
@@ -193,7 +193,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
if (config.alternativeHTTPModule() == null) {
_splitHttpClient = buildSplitHttpClient(apiToken, config, _sdkMetadata, _requestDecorator);
} else {
- _splitHttpClient = config.alternativeHTTPModule().createClient(apiToken, _sdkMetadata, _requestDecorator);
+ _splitHttpClient = config.alternativeHTTPModule().createClient(apiToken, _sdkMetadata); // ,
+ // _requestDecorator);
}
// Roots
@@ -240,7 +241,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
EventsSender eventsSender = EventsSender.create(_splitHttpClient, _eventsRootTarget, _telemetryStorageProducer);
_eventsTask = EventsTask.create(config.eventSendIntervalInMillis(), eventsStorage, eventsSender,
config.getThreadFactory());
- _telemetrySyncTask = new TelemetrySyncTask(config.getTelemetryRefreshRate(), _telemetrySynchronizer, config.getThreadFactory());
+ _telemetrySyncTask = new TelemetrySyncTask(config.getTelemetryRefreshRate(), _telemetrySynchronizer,
+ config.getThreadFactory());
// Evaluator
_evaluator = new EvaluatorImp(splitCache, segmentCache);
@@ -263,7 +265,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
// SyncManager
SplitTasks splitTasks = SplitTasks.build(_splitSynchronizationTask, _segmentSynchronizationTaskImp,
_impressionsManager, _eventsTask, _telemetrySyncTask, _uniqueKeysTracker);
- SplitAPI splitAPI = SplitAPI.build(_splitHttpClient, buildSSEdHttpClient(apiToken, config, _sdkMetadata), _requestDecorator);
+ SplitAPI splitAPI = SplitAPI.build(_splitHttpClient, buildSSEdHttpClient(apiToken, config, _sdkMetadata),
+ _requestDecorator);
_syncManager = SyncManagerImp.build(splitTasks, _splitFetcher, splitCache, splitAPI,
segmentCache, _gates, _telemetryStorageProducer, _telemetrySynchronizer, config, splitParser,
@@ -334,8 +337,10 @@ protected SplitFactoryImpl(String apiToken, SplitClientConfig config, CustomStor
_evaluator = new EvaluatorImp(userCustomSplitAdapterConsumer, userCustomSegmentAdapterConsumer);
_impressionsSender = PluggableImpressionSender.create(customStorageWrapper);
_uniqueKeysTracker = createUniqueKeysTracker(config);
- _impressionsManager = buildImpressionsManager(config, userCustomImpressionAdapterConsumer, userCustomImpressionAdapterProducer);
- _telemetrySyncTask = new TelemetrySyncTask(config.getTelemetryRefreshRate(), _telemetrySynchronizer, config.getThreadFactory());
+ _impressionsManager = buildImpressionsManager(config, userCustomImpressionAdapterConsumer,
+ userCustomImpressionAdapterProducer);
+ _telemetrySyncTask = new TelemetrySyncTask(config.getTelemetryRefreshRate(), _telemetrySynchronizer,
+ config.getThreadFactory());
SplitTasks splitTasks = SplitTasks.build(null, null,
_impressionsManager, null, _telemetrySyncTask, _uniqueKeysTracker);
diff --git a/client/src/main/java/io/split/client/dtos/SplitHttpResponse.java b/client/src/main/java/io/split/client/dtos/SplitHttpResponse.java
index a5474cf5..259ed079 100644
--- a/client/src/main/java/io/split/client/dtos/SplitHttpResponse.java
+++ b/client/src/main/java/io/split/client/dtos/SplitHttpResponse.java
@@ -1,7 +1,7 @@
package io.split.client.dtos;
-import java.util.Map;
-import org.apache.hc.core5.http.Header;
+import java.util.List;
+
/**
* A structure for returning http call results information
*/
@@ -11,15 +11,42 @@ public class SplitHttpResponse {
private final String _body;
private final Header[] _responseHeaders;
+ public static class Header {
+ private String _name;
+ private List _values;
+
+ public Header(String name, List values) {
+ _name = name;
+ _values = values;
+ }
+
+ public String getName() {
+ return _name;
+ }
+
+ public List getValues() {
+ return _values;
+ }
+ };
+
public SplitHttpResponse(Integer statusCode, String statusMessage, String body, Header[] headers) {
_statusCode = statusCode;
_statusMessage = statusMessage;
_body = body;
_responseHeaders = headers;
}
+
+ public SplitHttpResponse(Integer statusCode, String statusMessage, String body, List headers) {
+ _statusCode = statusCode;
+ _statusMessage = statusMessage;
+ _body = body;
+ _responseHeaders = headers.toArray(new Header[0]);
+ }
+
public Integer statusCode() {
return _statusCode;
}
+
public String statusMessage() {
return _statusMessage;
}
diff --git a/client/src/main/java/io/split/client/impressions/HttpImpressionsSender.java b/client/src/main/java/io/split/client/impressions/HttpImpressionsSender.java
index 06df64cc..35c0f57f 100644
--- a/client/src/main/java/io/split/client/impressions/HttpImpressionsSender.java
+++ b/client/src/main/java/io/split/client/impressions/HttpImpressionsSender.java
@@ -4,6 +4,7 @@
import io.split.client.dtos.ImpressionCount;
import io.split.client.dtos.SplitHttpResponse;
import io.split.client.dtos.TestImpressions;
+import io.split.client.utils.Json;
import io.split.client.utils.Utils;
import io.split.service.SplitHttpClient;
@@ -11,7 +12,6 @@
import io.split.telemetry.domain.enums.LastSynchronizationRecordsEnum;
import io.split.telemetry.domain.enums.ResourceEnum;
import io.split.telemetry.storage.TelemetryRuntimeProducer;
-import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -67,10 +67,12 @@ private HttpImpressionsSender(SplitHttpClient client, URI impressionBulkTarget,
public void postImpressionsBulk(List impressions) {
long initTime = System.currentTimeMillis();
try {
- HttpEntity entity = Utils.toJsonEntity(impressions);
- Map> additionalHeaders = Collections.singletonMap(IMPRESSIONS_MODE_HEADER,
- Collections.singletonList(_mode.toString()));
- SplitHttpResponse response = _client.post(_impressionBulkTarget, entity, additionalHeaders);
+ Map> additionalHeaders = new HashMap<>();
+ additionalHeaders.put(IMPRESSIONS_MODE_HEADER, Collections.singletonList(_mode.toString()));
+ additionalHeaders.put("Content-Type", Collections.singletonList("application/json"));
+
+ SplitHttpResponse response = _client.post(_impressionBulkTarget, Json.toJson(impressions),
+ additionalHeaders);
if (response.statusCode() < HttpStatus.SC_OK || response.statusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) {
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.IMPRESSION_SYNC, response.statusCode());
@@ -95,8 +97,12 @@ public void postCounters(HashMap raw) {
}
try {
+
+ Map> additionalHeaders = new HashMap<>();
+ additionalHeaders.put("Content-Type", Collections.singletonList("application/json"));
+
SplitHttpResponse response = _client.post(_impressionCountTarget,
- Utils.toJsonEntity(ImpressionCount.fromImpressionCounterData(raw)),
+ Json.toJson(ImpressionCount.fromImpressionCounterData(raw)),
null);
if (response.statusCode() < HttpStatus.SC_OK || response.statusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) {
diff --git a/client/src/main/java/io/split/service/CustomHttpModule.java b/client/src/main/java/io/split/service/CustomHttpModule.java
index 20e8b3de..4f34cf7d 100644
--- a/client/src/main/java/io/split/service/CustomHttpModule.java
+++ b/client/src/main/java/io/split/service/CustomHttpModule.java
@@ -6,5 +6,5 @@
import java.io.IOException;
public interface CustomHttpModule {
- public SplitHttpClient createClient(String apiToken, SDKMetadata sdkMetadata, RequestDecorator requestDecorator) throws IOException;
+ public SplitHttpClient createClient(String apiToken, SDKMetadata sdkMetadata) throws IOException;
}
diff --git a/client/src/main/java/io/split/service/HttpPostImp.java b/client/src/main/java/io/split/service/HttpPostImp.java
index e5baa001..b33bf210 100644
--- a/client/src/main/java/io/split/service/HttpPostImp.java
+++ b/client/src/main/java/io/split/service/HttpPostImp.java
@@ -1,15 +1,18 @@
package io.split.service;
import io.split.client.dtos.SplitHttpResponse;
-import io.split.client.utils.Utils;
+import io.split.client.utils.Json;
import io.split.telemetry.domain.enums.HttpParamsWrapper;
import io.split.telemetry.storage.TelemetryRuntimeProducer;
-import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -25,16 +28,19 @@ public HttpPostImp(SplitHttpClient client, TelemetryRuntimeProducer telemetryRun
public void post(URI uri, Object object, String posted, HttpParamsWrapper httpParamsWrapper) {
long initTime = System.currentTimeMillis();
- HttpEntity entity = Utils.toJsonEntity(object);
try {
- SplitHttpResponse response = _client.post(uri, entity, null);
+ Map> headers = new HashMap<>();
+ headers.put("Content-Type", Collections.singletonList("application/json"));
+ SplitHttpResponse response = _client.post(uri, Json.toJson(object), headers);
if (response.statusCode() < HttpStatus.SC_OK || response.statusCode() >= HttpStatus.SC_MULTIPLE_CHOICES) {
_telemetryRuntimeProducer.recordSyncError(httpParamsWrapper.getResourceEnum(), response.statusCode());
return;
}
- _telemetryRuntimeProducer.recordSyncLatency(httpParamsWrapper.getHttpLatenciesEnum(), System.currentTimeMillis() - initTime);
- _telemetryRuntimeProducer.recordSuccessfulSync(httpParamsWrapper.getLastSynchronizationRecordsEnum(), System.currentTimeMillis());
+ _telemetryRuntimeProducer.recordSyncLatency(httpParamsWrapper.getHttpLatenciesEnum(),
+ System.currentTimeMillis() - initTime);
+ _telemetryRuntimeProducer.recordSuccessfulSync(httpParamsWrapper.getLastSynchronizationRecordsEnum(),
+ System.currentTimeMillis());
} catch (Throwable t) {
_logger.warn("Exception when posting " + posted + object, t);
}
diff --git a/client/src/main/java/io/split/service/SplitHttpClient.java b/client/src/main/java/io/split/service/SplitHttpClient.java
index 7105d16b..899fcf56 100644
--- a/client/src/main/java/io/split/service/SplitHttpClient.java
+++ b/client/src/main/java/io/split/service/SplitHttpClient.java
@@ -3,8 +3,6 @@
import io.split.engine.common.FetchOptions;
import io.split.client.dtos.SplitHttpResponse;
-import org.apache.hc.core5.http.HttpEntity;
-
import java.io.Closeable;
import java.io.IOException;
import java.net.URI;
@@ -30,6 +28,6 @@ public interface SplitHttpClient extends Closeable {
* @return The response structure SplitHttpResponse
*/
public SplitHttpResponse post(URI uri,
- HttpEntity entity,
+ String entity,
Map> additionalHeaders) throws IOException;
-}
\ No newline at end of file
+}
diff --git a/client/src/main/java/io/split/service/SplitHttpClientImpl.java b/client/src/main/java/io/split/service/SplitHttpClientImpl.java
index 64ca3a55..f5eecc46 100644
--- a/client/src/main/java/io/split/service/SplitHttpClientImpl.java
+++ b/client/src/main/java/io/split/service/SplitHttpClientImpl.java
@@ -9,9 +9,10 @@
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
-import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.HttpEntities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
@@ -19,8 +20,11 @@
import java.net.URISyntaxException;
import org.apache.hc.core5.http.HttpRequest;
import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
public final class SplitHttpClientImpl implements SplitHttpClient {
@@ -87,10 +91,14 @@ public SplitHttpResponse get(URI uri, FetchOptions options, Map new SplitHttpResponse.Header(h.getName(), Collections.singletonList(h.getValue())))
+ .collect(Collectors.toList()));
+ // response.getHeaders());
} catch (Exception e) {
throw new IllegalStateException(String.format("Problem in http get operation: %s", e), e);
} finally {
@@ -98,7 +106,7 @@ public SplitHttpResponse get(URI uri, FetchOptions options, Map> additionalHeaders)
+ public SplitHttpResponse post(URI uri, String body, Map> additionalHeaders)
throws IOException {
CloseableHttpResponse response = null;
@@ -112,7 +120,7 @@ public SplitHttpResponse post(URI uri, HttpEntity entity, Map new SplitHttpResponse.Header(h.getName(), Collections.singletonList(h.getValue())))
+ .collect(Collectors.toList()));
} catch (Exception e) {
throw new IOException(String.format("Problem in http post operation: %s", e), e);
} finally {
diff --git a/okhttp-modules/pom.xml b/okhttp-modules/pom.xml
index 11939042..1472566d 100644
--- a/okhttp-modules/pom.xml
+++ b/okhttp-modules/pom.xml
@@ -49,7 +49,11 @@
4.13.0
compile
-
+
+ org.apache.httpcomponents.client5
+ httpclient5
+ 5.0.3
+
junit
@@ -82,4 +86,4 @@
-
\ No newline at end of file
+
diff --git a/okhttp-modules/src/main/java/io/split/httpmodules/okhttp/OkHttpClientImpl.java b/okhttp-modules/src/main/java/io/split/httpmodules/okhttp/OkHttpClientImpl.java
index d642cabe..3164dca5 100644
--- a/okhttp-modules/src/main/java/io/split/httpmodules/okhttp/OkHttpClientImpl.java
+++ b/okhttp-modules/src/main/java/io/split/httpmodules/okhttp/OkHttpClientImpl.java
@@ -1,25 +1,15 @@
package io.split.httpmodules.okhttp;
-import io.split.client.RequestDecorator;
import io.split.client.dtos.SplitHttpResponse;
import io.split.client.utils.SDKMetadata;
import io.split.engine.common.FetchOptions;
import io.split.service.SplitHttpClient;
import okhttp3.*;
-import okhttp3.OkHttpClient.*;
-import okhttp3.Request.*;
import okhttp3.logging.HttpLoggingInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import split.org.apache.hc.client5.http.classic.methods.HttpGet;
-import split.org.apache.hc.core5.http.Header;
-import split.org.apache.hc.core5.http.HttpEntity;
-import split.org.apache.hc.core5.http.HttpRequest;
-import split.org.apache.hc.core5.http.io.entity.EntityUtils;
-import split.org.apache.hc.core5.http.message.BasicHeader;
-
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.Proxy;
@@ -40,28 +30,26 @@ public class OkHttpClientImpl implements SplitHttpClient {
private static final String HEADER_CLIENT_MACHINE_NAME = "SplitSDKMachineName";
private static final String HEADER_CLIENT_MACHINE_IP = "SplitSDKMachineIP";
private static final String HEADER_CLIENT_VERSION = "SplitSDKVersion";
- private RequestDecorator _requestDecorator;
private String _apikey;
protected SDKMetadata _metadata;
- public OkHttpClientImpl(String apiToken, SDKMetadata sdkMetadata, RequestDecorator requestDecorator,
- Proxy proxy, String proxyAuthKerberosPrincipalName, boolean debugEnabled,
- int readTimeout, int connectionTimeout) throws IOException {
+ public OkHttpClientImpl(String apiToken, SDKMetadata sdkMetadata,
+ Proxy proxy, String proxyAuthKerberosPrincipalName, boolean debugEnabled,
+ int readTimeout, int connectionTimeout) throws IOException {
_apikey = apiToken;
_metadata = sdkMetadata;
- _requestDecorator = requestDecorator;
setHttpClient(proxy, proxyAuthKerberosPrincipalName, debugEnabled,
readTimeout, connectionTimeout);
}
protected void setHttpClient(Proxy proxy, String proxyAuthKerberosPrincipalName, boolean debugEnabled,
- int readTimeout, int connectionTimeout) throws IOException {
+ int readTimeout, int connectionTimeout) throws IOException {
httpClient = initializeClient(proxy, proxyAuthKerberosPrincipalName, debugEnabled,
readTimeout, connectionTimeout);
}
protected OkHttpClient initializeClient(Proxy proxy, String proxyAuthKerberosPrincipalName, boolean debugEnabled,
- int readTimeout, int connectionTimeout) throws IOException {
+ int readTimeout, int connectionTimeout) throws IOException {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
if (debugEnabled) {
logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);
@@ -87,7 +75,7 @@ protected OkHttpClient initializeClient(Proxy proxy, String proxyAuthKerberosPri
}
public HTTPKerberosAuthInterceptor getProxyAuthenticator(String proxyKerberosPrincipalName,
- Map kerberosOptions) throws IOException {
+ Map kerberosOptions) throws IOException {
return new HTTPKerberosAuthInterceptor(proxyKerberosPrincipalName, kerberosOptions);
}
@@ -133,8 +121,8 @@ public SplitHttpResponse get(URI uri, FetchOptions options, Map> additionalHeaders) {
+ public SplitHttpResponse post(URI url, String entity,
+ Map> additionalHeaders) {
try {
okhttp3.Request.Builder requestBuilder = getRequestBuilder();
requestBuilder.url(url.toString());
@@ -142,8 +130,8 @@ public SplitHttpResponse post(URI url, HttpEntity entity,
setAdditionalAndDecoratedHeaders(requestBuilder, additionalHeaders);
requestBuilder.addHeader("Accept-Encoding", "gzip");
requestBuilder.addHeader("Content-Type", "application/json");
- String post = EntityUtils.toString((HttpEntity) entity);
- RequestBody postBody = RequestBody.create(post.getBytes());
+ // String post = EntityUtils.toString((HttpEntity) entity);
+ RequestBody postBody = RequestBody.create(entity.getBytes());
requestBuilder.post(postBody);
Request request = requestBuilder.build();
@@ -179,6 +167,7 @@ protected okhttp3.Request.Builder getRequestBuilder() {
protected Request getRequest(okhttp3.Request.Builder requestBuilder) {
return requestBuilder.build();
}
+
protected void setBasicHeaders(okhttp3.Request.Builder requestBuilder) {
requestBuilder.addHeader(HEADER_API_KEY, "Bearer " + _apikey);
requestBuilder.addHeader(HEADER_CLIENT_VERSION, _metadata.getSdkVersion());
@@ -189,7 +178,8 @@ protected void setBasicHeaders(okhttp3.Request.Builder requestBuilder) {
: _apikey);
}
- protected void setAdditionalAndDecoratedHeaders(okhttp3.Request.Builder requestBuilder, Map> additionalHeaders) {
+ protected void setAdditionalAndDecoratedHeaders(okhttp3.Request.Builder requestBuilder,
+ Map> additionalHeaders) {
if (additionalHeaders != null) {
for (Map.Entry> entry : additionalHeaders.entrySet()) {
for (String value : entry.getValue()) {
@@ -197,24 +187,19 @@ protected void setAdditionalAndDecoratedHeaders(okhttp3.Request.Builder requestB
}
}
}
- HttpRequest request = new HttpGet("");
- _requestDecorator.decorateHeaders(request);
- for (Header header : request.getHeaders()) {
- requestBuilder.addHeader(header.getName(), header.getValue());
- }
}
- protected Header[] getResponseHeaders(Response response) {
- List responseHeaders = new ArrayList<>();
+ protected SplitHttpResponse.Header[] getResponseHeaders(Response response) {
+ List responseHeaders = new ArrayList<>();
Map> map = response.headers().toMultimap();
for (Map.Entry> entry : map.entrySet()) {
if (entry.getKey() != null) {
- BasicHeader responseHeader = new BasicHeader(entry.getKey(), entry.getValue());
- responseHeaders.add(responseHeader);
+ responseHeaders.add(new SplitHttpResponse.Header(entry.getKey(), entry.getValue()));
}
}
- return responseHeaders.toArray(new split.org.apache.hc.core5.http.Header[0]);
+ return responseHeaders.toArray(new SplitHttpResponse.Header[0]);
}
+
@Override
public void close() throws IOException {
httpClient.dispatcher().executorService().shutdown();
diff --git a/okhttp-modules/src/main/java/io/split/httpmodules/okhttp/OkHttpModule.java b/okhttp-modules/src/main/java/io/split/httpmodules/okhttp/OkHttpModule.java
index 77fe1d97..cfd45a5c 100644
--- a/okhttp-modules/src/main/java/io/split/httpmodules/okhttp/OkHttpModule.java
+++ b/okhttp-modules/src/main/java/io/split/httpmodules/okhttp/OkHttpModule.java
@@ -4,7 +4,6 @@
import java.net.InetSocketAddress;
import java.net.Proxy;
-import io.split.client.RequestDecorator;
import io.split.client.utils.SDKMetadata;
import io.split.service.CustomHttpModule;
@@ -41,8 +40,8 @@ private OkHttpModule(ProxyAuthScheme proxyAuthScheme,
}
@Override
- public OkHttpClientImpl createClient(String apiToken, SDKMetadata sdkMetadata, RequestDecorator requestDecorator) throws IOException {
- return new OkHttpClientImpl(apiToken, sdkMetadata, requestDecorator,
+ public OkHttpClientImpl createClient(String apiToken, SDKMetadata sdkMetadata) throws IOException {
+ return new OkHttpClientImpl(apiToken, sdkMetadata,
_proxy, _proxyAuthKerberosPrincipalName, _debugEnabled,
_readTimeout, _connectionTimeout);
}