Skip to content

Commit e485ba4

Browse files
authored
Merge pull request #202 from splunk/itsi-app-fix
Re-fetch instanceType if not provided
2 parents adb1131 + c4fc1d9 commit e485ba4

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

splunk/src/main/java/com/splunk/HttpService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ public class HttpService {
5151
private static String HTTPS_SCHEME = "https";
5252
private static String HTTP_SCHEME = "http";
5353
private static String HOSTNAME = "localhost";
54+
private static String HOSTIP = "127.0.0.1";
5455

5556
private static final HostnameVerifier HOSTNAME_VERIFIER = new HostnameVerifier() {
5657
public boolean verify(String s, SSLSession sslSession) {
57-
if (s.equals(HOSTNAME)) {
58+
if (s.equals(HOSTNAME) || s.equals(HOSTIP)) {
5859
return true;
5960
} else {
6061
HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();

splunk/src/main/java/com/splunk/Service.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,9 @@ public void setBearerToken(String value) {
13561356

13571357

13581358
public boolean enableV2SearchApi(){
1359+
if(null == this.instanceType){
1360+
this.instanceType = this.getInfo().getInstanceType();
1361+
}
13591362
if(this.instanceType.equalsIgnoreCase("cloud")) {
13601363
return versionIsAtLeast("9.0.2209");
13611364
}else{
@@ -1411,6 +1414,9 @@ boolean versionIsEarlierThan(String version) {
14111414
* or 1 if this version is greater than the given version.
14121415
*/
14131416
public int versionCompare(String otherVersion) {
1417+
if(null == this.version){
1418+
this.version = this.getInfo().getVersion();
1419+
}
14141420
String[] components1 = this.version.split("\\.");
14151421
String[] components2 = otherVersion.split("\\.");
14161422
int numComponents = Math.max(components1.length, components2.length);

splunk/src/test/java/com/splunk/ServiceTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,4 +735,19 @@ public void testEnableV2Api(){
735735
}
736736
}
737737

738+
/*
739+
Test when Service instance is created using token, it doesn't result in Null Pointer while accessing instanceType and version
740+
*/
741+
@Test
742+
public void testServiceWithTokenAuth(){
743+
Service newService = new Service(service.getHost());
744+
newService.setToken(service.getToken());
745+
try{
746+
newService.enableV2SearchApi();
747+
newService.versionCompare("9.0.2");
748+
}catch (Exception ex){
749+
Assert.assertNull(ex);
750+
}
751+
}
752+
738753
}

0 commit comments

Comments
 (0)