Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion splunk/src/main/java/com/splunk/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public class HttpService {
private static String HTTPS_SCHEME = "https";
private static String HTTP_SCHEME = "http";
private static String HOSTNAME = "localhost";
private static String HOSTIP = "127.0.0.1";

private static final HostnameVerifier HOSTNAME_VERIFIER = new HostnameVerifier() {
public boolean verify(String s, SSLSession sslSession) {
if (s.equals(HOSTNAME)) {
if (s.equals(HOSTNAME) || s.equals(HOSTIP)) {
return true;
} else {
HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
Expand Down
6 changes: 6 additions & 0 deletions splunk/src/main/java/com/splunk/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,9 @@ public void setBearerToken(String value) {


public boolean enableV2SearchApi(){
if(null == this.instanceType){
this.instanceType = this.getInfo().getInstanceType();
}
if(this.instanceType.equalsIgnoreCase("cloud")) {
return versionIsAtLeast("9.0.2209");
}else{
Expand Down Expand Up @@ -1411,6 +1414,9 @@ boolean versionIsEarlierThan(String version) {
* or 1 if this version is greater than the given version.
*/
public int versionCompare(String otherVersion) {
if(null == this.version){
this.version = this.getInfo().getVersion();
}
String[] components1 = this.version.split("\\.");
String[] components2 = otherVersion.split("\\.");
int numComponents = Math.max(components1.length, components2.length);
Expand Down
15 changes: 15 additions & 0 deletions splunk/src/test/java/com/splunk/ServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,19 @@ public void testEnableV2Api(){
}
}

/*
Test when Service instance is created using token, it doesn't result in Null Pointer while accessing instanceType and version
*/
@Test
public void testServiceWithTokenAuth(){
Service newService = new Service(service.getHost());
newService.setToken(service.getToken());
try{
newService.enableV2SearchApi();
newService.versionCompare("9.0.2");
}catch (Exception ex){
Assert.assertNull(ex);
}
}

}