Attempting to establish a connection to a Splunk server using the Splunk Java SDK examples:
// Create a map of arguments and add login parameters
ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername( "admin" );
loginArgs.setPassword( "changeme1" );
loginArgs.setHost( "localhost" );
loginArgs.setPort( 8089 );
// Create a Service instance and log in with the argument map
Service service = Service.connect( loginArgs );
This code results in the following exception: java.lang.IllegalArgumentException: URI can't be null.
Does anyone know how to resolve this? Thank you
Figured it out. It was an issue with the Java version. I'm running Java 8, which requires the following method be called to set the SSLSecurityProtocol:
HttpService.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );
Then proceed with the required connection args per the SDK documentation. Please see the following post for more on this issue:
https://answers.splunk.com/answers/209379/no-appropriate-protocol-protocol-is-disabled-or-ci.html
I tried the following and it worked for me
HttpService.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );
ServiceArgs serviceArgs = new ServiceArgs();
serviceArgs.setHost("mycompanySplunkServer.com");
serviceArgs.setPort(8089);
// Create a Service instance and log in with the argument map
Service service = Service.connect(serviceArgs);
service.login("MyUsername","MyPassword");
System.out.println(service.getToken().toString());
Figured it out. It was an issue with the Java version. I'm running Java 8, which requires the following method be called to set the SSLSecurityProtocol:
HttpService.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );
Then proceed with the required connection args per the SDK documentation. Please see the following post for more on this issue:
https://answers.splunk.com/answers/209379/no-appropriate-protocol-protocol-is-disabled-or-ci.html
I am getting the same issue and even after using the above line of code the problem is not solved.
I am using the remote server address to connect to Splunk using Java1.8 and Splunk jar version 1.6.2 with the below code.
HttpService.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );
ServiceArgs serviceArgs = new ServiceArgs();
serviceArgs.setUsername("Username");
serviceArgs.setPassword("Password");
serviceArgs.setHost("http://mycompanySplunkServer.com");
serviceArgs.setPort(8089);
service = Service.connect(serviceArgs);
That works. Also see the extended related answer with a code: https://answers.splunk.com/answers/209379/no-appropriate-protocol-protocol-is-disabled-or-ci.html
I downvoted this post because dosn't work
Almost an identiacal question at Connecting to Splunk via Java SDK, why am I getting error "java.lang.IllegalArgumentException: URI c...
The question there is -
-- I normally access Splunk using a url "mycompany.splunkcloud.com" and enter my credentials.
What about your case? what is the host?
The following also shows an exact code as yours - How to connect to Splunk Enterprise using the Splunk SDK for Java
ddrillic, thank you for your response. Yes, I realize the question is nearly identical, but the question you referenced remains unanswered. I asked it again with the hope of drawing attention to the issue. The Spunk SDK shows the exact code because that's where I got it from, and the way I'm using it isn't working. Perhaps, I am inputting the host name incorrectly.
My team's Splunk instance sits on an internal server, not on splunkcload.com. I am using the form "http://myCompanysServer.mycompany.com" as the host name. Any help is most appreciated.
Got it. From the server that hosts the Java code do you have connectivity to the Splunk server -
telnet <splunk host> 8089
Thanks,
Yes, I do have connectivity. Still no luck connecting via SDK