Skip to content

Commit dc2fd8c

Browse files
authored
Merge pull request #112 from splitio/development
Development
2 parents eaae4d1 + b41c4b5 commit dc2fd8c

File tree

11 files changed

+142
-26
lines changed

11 files changed

+142
-26
lines changed

.travis.settings.xml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
<activeByDefault>true</activeByDefault>
1111
</activation>
1212
<properties>
13-
<sonar.host.url>http://sonar.split.io:8080</sonar.host.url>
14-
<sonar.login>${env.SONAR_TOKEN}</sonar.login>
15-
<sonar.projectName>Split Java SDK</sonar.projectName>
16-
<sonar.projectVersion>development</sonar.projectVersion>
17-
<sonar.test.exclusions>**/test/**/*.*</sonar.test.exclusions>
18-
<sonar.exclusions>**/ai/**/*.*,**/jdbc/**/*.*,**/mpt/**/*.*,**/jcr/**/*.*,**/JDBC*</sonar.exclusions>
13+
<sonar.host.url>https://sonarqube.split-internal.com</sonar.host.url>
14+
<sonar.login>${env.SONAR_TOKEN}</sonar.login>
15+
<sonar.ws.timeout>300</sonar.ws.timeout>
16+
<sonar.links.ci>https://travis-ci.com/splitio/java-client</sonar.links.ci>
17+
<sonar.links.scm>https://github.com/splitio/java-client</sonar.links.scm>
18+
<sonar.projectName>java-client</sonar.projectName>
19+
<sonar.sources>./src</sonar.sources>
20+
<sonar.test.exclusions>**/test/**/*.*,**/testing/**/*.*</sonar.test.exclusions>
21+
<sonar.exclusions>**/ai/**/*.*,**/jdbc/**/*.*,**/mpt/**/*.*,**/jcr/**/*.*,**/JDBC*</sonar.exclusions>
1922
</properties>
2023
</profile>
2124
</profiles>

.travis.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
dist: trusty
22

3+
language: java
4+
35
jdk:
46
- oraclejdk8
57

8+
git:
9+
depth: false
10+
611
cache:
712
directories:
813
- $HOME/.m2
@@ -13,9 +18,5 @@ before_script:
1318
script:
1419
- mvn clean install
1520

16-
deploy:
17-
- provider: script
18-
skip_cleanup: true
19-
script: mvn -DskipTests sonar:sonar
20-
on:
21-
branch: development
21+
after_success:
22+
- bash sonar-scanner.sh

client/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
CHANGES
2+
3.3.1 (Nov 1, 2019)
3+
- Allow client to disable sending the IP address & hostname.
24

35
3.3.0 (Sep 23, 2019)
46
- rename version.properties to splitversion.properties to avoid conflicts with other tools that use the former file name and causes this SDK to not properly report the version

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.split.client</groupId>
77
<artifactId>java-client-parent</artifactId>
8-
<version>3.3.0</version>
8+
<version>3.3.1</version>
99
</parent>
1010
<artifactId>java-client</artifactId>
1111
<packaging>jar</packaging>

client/src/main/java/io/split/client/SplitClientConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class SplitClientConfig {
3030
private final int _numThreadsForSegmentFetch;
3131
private final boolean _debugEnabled;
3232
private final boolean _labelsEnabled;
33+
private final boolean _ipAddressEnabled;
3334
private final int _ready;
3435
private final int _waitBeforeShutdown;
3536
private final int _eventsQueueSize;
@@ -65,6 +66,7 @@ private SplitClientConfig(String endpoint,
6566
int ready,
6667
boolean debugEnabled,
6768
boolean labelsEnabled,
69+
boolean ipAddressEnabled,
6870
int waitBeforeShutdown,
6971
HttpHost proxy,
7072
String proxyUsername,
@@ -88,6 +90,7 @@ private SplitClientConfig(String endpoint,
8890
_ready = ready;
8991
_debugEnabled = debugEnabled;
9092
_labelsEnabled = labelsEnabled;
93+
_ipAddressEnabled = ipAddressEnabled;
9194
_waitBeforeShutdown = waitBeforeShutdown;
9295
_proxy = proxy;
9396
_proxyUsername = proxyUsername;
@@ -158,6 +161,8 @@ public boolean debugEnabled() {
158161

159162
public boolean labelsEnabled() { return _labelsEnabled;}
160163

164+
public boolean ipAddressEnabled() { return _ipAddressEnabled; }
165+
161166
public int blockUntilReady() {
162167
return _ready;
163168
}
@@ -219,6 +224,7 @@ public static final class Builder {
219224
private int _ready = -1; // -1 means no blocking
220225
private int _metricsRefreshRate = 60;
221226
private boolean _labelsEnabled = true;
227+
private boolean _ipAddressEnabled = true;
222228
private int _waitBeforeShutdown = 5000;
223229
private String _proxyHost = "localhost";
224230
private int _proxyPort = -1;
@@ -444,6 +450,10 @@ public Builder disableLabels() {
444450
return this;
445451
}
446452

453+
public Builder disableIPAddress() {
454+
_ipAddressEnabled = false;
455+
return this;
456+
}
447457

448458
/**
449459
* The SDK kicks off background threads to download data necessary
@@ -626,6 +636,7 @@ public SplitClientConfig build() {
626636
_ready,
627637
_debugEnabled,
628638
_labelsEnabled,
639+
_ipAddressEnabled,
629640
_waitBeforeShutdown,
630641
proxy(),
631642
_proxyUsername,

client/src/main/java/io/split/client/SplitFactoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
9898
.setConnectionManager(cm)
9999
.setDefaultRequestConfig(requestConfig)
100100
.setSSLSocketFactory(sslsf)
101-
.addInterceptorLast(AddSplitHeadersFilter.instance(apiToken))
101+
.addInterceptorLast(AddSplitHeadersFilter.instance(apiToken, config.ipAddressEnabled()))
102102
.addInterceptorLast(new GzipEncoderRequestInterceptor())
103103
.addInterceptorLast(new GzipDecoderResponseInterceptor());
104104

client/src/main/java/io/split/client/interceptors/AddSplitHeadersFilter.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@
1919
public class AddSplitHeadersFilter implements HttpRequestInterceptor {
2020
private static final Logger _log = LoggerFactory.getLogger(AddSplitHeadersFilter.class);
2121

22-
private static final String CLIENT_MACHINE_NAME_HEADER = "SplitSDKMachineName";
23-
private static final String CLIENT_MACHINE_IP_HEADER = "SplitSDKMachineIP";
24-
private static final String CLIENT_VERSION = "SplitSDKVersion";
25-
private static final String SDK_SPEC_VERSION = "SplitSDKSpecVersion";
26-
private static final String OUR_SDK_SPEC_VERSION = "1.3";
22+
/* package private for testing purposes */
23+
static final String AUTHORIZATION_HEADER = "Authorization";
24+
static final String CLIENT_MACHINE_NAME_HEADER = "SplitSDKMachineName";
25+
static final String CLIENT_MACHINE_IP_HEADER = "SplitSDKMachineIP";
26+
static final String CLIENT_VERSION = "SplitSDKVersion";
2727

2828
private final String _apiTokenBearer;
2929
private final String _hostname;
3030
private final String _ip;
3131

32-
public static AddSplitHeadersFilter instance(String apiToken) {
32+
public static AddSplitHeadersFilter instance(String apiToken, boolean ipAddressEnabled) {
33+
if (!ipAddressEnabled) {
34+
return new AddSplitHeadersFilter(apiToken, null, null);
35+
}
36+
3337
String hostname = null;
3438
String ip = null;
3539

@@ -53,11 +57,9 @@ private AddSplitHeadersFilter(String apiToken, String hostname, String ip) {
5357
}
5458

5559
@Override
56-
public void process(HttpRequest request, HttpContext httpContext) throws HttpException, IOException {
57-
request.addHeader("Authorization", _apiTokenBearer);
60+
public void process(HttpRequest request, HttpContext httpContext) {
61+
request.addHeader(AUTHORIZATION_HEADER, _apiTokenBearer);
5862
request.addHeader(CLIENT_VERSION, SplitClientConfig.splitSdkVersion);
59-
;
60-
request.addHeader(SDK_SPEC_VERSION, OUR_SDK_SPEC_VERSION);
6163

6264
if (_hostname != null) {
6365
request.addHeader(CLIENT_MACHINE_NAME_HEADER, _hostname);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.split.client.interceptors;
2+
3+
import org.apache.http.HttpException;
4+
import org.apache.http.HttpRequest;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.mockito.ArgumentCaptor;
8+
import org.mockito.Captor;
9+
import org.mockito.Mockito;
10+
11+
import org.apache.http.protocol.HttpContext;
12+
import org.mockito.runners.MockitoJUnitRunner;
13+
14+
import java.io.IOException;
15+
import java.util.List;
16+
17+
import static org.hamcrest.Matchers.*;
18+
import static org.hamcrest.core.IsEqual.equalTo;
19+
import static org.junit.Assert.assertThat;
20+
21+
22+
@RunWith(MockitoJUnitRunner.class)
23+
public class AddSplitHeadersFilterTest {
24+
25+
@Captor
26+
private ArgumentCaptor<String> headerNameCaptor;
27+
28+
@Captor
29+
private ArgumentCaptor<String> headerValueCaptor;
30+
31+
@Test
32+
public void testHeadersWithIpAndHostname() throws IOException, HttpException {
33+
AddSplitHeadersFilter filter = AddSplitHeadersFilter.instance("abc", true);
34+
HttpRequest req = Mockito.mock(HttpRequest.class);
35+
HttpContext ctx = Mockito.mock(HttpContext.class);
36+
37+
filter.process(req, ctx);
38+
Mockito.verify(req, Mockito.times(4)).addHeader(headerNameCaptor.capture(), headerValueCaptor.capture());
39+
40+
List<String> headerNames = headerNameCaptor.getAllValues();
41+
List<String> headerValues = headerValueCaptor.getAllValues();
42+
43+
assertThat(headerNames.size(), is(equalTo(4)));
44+
assertThat(headerValues.size(), is(equalTo(4)));
45+
46+
assertThat(headerNames, contains(AddSplitHeadersFilter.AUTHORIZATION_HEADER,
47+
AddSplitHeadersFilter.CLIENT_VERSION,
48+
AddSplitHeadersFilter.CLIENT_MACHINE_NAME_HEADER,
49+
AddSplitHeadersFilter.CLIENT_MACHINE_IP_HEADER));
50+
}
51+
52+
@Test
53+
public void testHeadersWithoutIpAndHostname() {
54+
AddSplitHeadersFilter filter = AddSplitHeadersFilter.instance("abc", false);
55+
HttpRequest req = Mockito.mock(HttpRequest.class);
56+
HttpContext ctx = Mockito.mock(HttpContext.class);
57+
58+
filter.process(req, ctx);
59+
Mockito.verify(req, Mockito.times(2)).addHeader(headerNameCaptor.capture(), headerValueCaptor.capture());
60+
61+
List<String> headerNames = headerNameCaptor.getAllValues();
62+
List<String> headerValues = headerValueCaptor.getAllValues();
63+
64+
assertThat(headerNames.size(), is(equalTo(2)));
65+
assertThat(headerValues.size(), is(equalTo(2)));
66+
67+
assertThat(headerNames, contains(AddSplitHeadersFilter.AUTHORIZATION_HEADER,
68+
AddSplitHeadersFilter.CLIENT_VERSION));
69+
70+
assertThat(headerNames, not(contains(AddSplitHeadersFilter.CLIENT_MACHINE_NAME_HEADER,
71+
AddSplitHeadersFilter.CLIENT_MACHINE_IP_HEADER)));
72+
}
73+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.split.client</groupId>
66
<artifactId>java-client-parent</artifactId>
7-
<version>3.3.0</version>
7+
<version>3.3.1</version>
88
<dependencyManagement>
99
<dependencies>
1010
<dependency>

sonar-scanner.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#/bin/bash -e
2+
3+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
4+
mvn --batch-mode sonar:sonar -DskipTests \
5+
-Dsonar.pullrequest.provider='GitHub' \
6+
-Dsonar.pullrequest.github.repository='splitio/java-client' \
7+
-Dsonar.pullrequest.key=$TRAVIS_PULL_REQUEST \
8+
-Dsonar.pullrequest.branch=$TRAVIS_PULL_REQUEST_BRANCH \
9+
-Dsonar.pullrequest.base=$TRAVIS_BRANCH
10+
else
11+
if [ "$TRAVIS_BRANCH" == 'master' ]; then
12+
mvn --batch-mode sonar:sonar -DskipTests \
13+
-Dsonar.branch.name=$TRAVIS_BRANCH
14+
else
15+
if [ "$TRAVIS_BRANCH" == 'development' ]; then
16+
TARGET_BRANCH='master'
17+
else
18+
TARGET_BRANCH='development'
19+
fi
20+
mvn --batch-mode sonar:sonar -DskipTests \
21+
-Dsonar.branch.name=$TRAVIS_BRANCH \
22+
-Dsonar.branch.target=$TARGET_BRANCH
23+
fi
24+
fi

0 commit comments

Comments
 (0)