Splunk Search

I'm unable to connect to splunk using java application.

spideyweb008
New Member
  1. I'm accessing splunk via a VPN. So if I'm trying to access splunk via browser, after logging in using username and password, I have to provide a VIP access code as well to complete the authentication process.

  2. In java, I've tried to execute the below two codes and for each code the corresponding exception that I got is also shared below.

Starting of my java file :

public class SplunkTestService {

public void getConnectionAndTest() {

    HttpService.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );

// HttpService.setSslSecurityProtocol( SSLSecurityProtocol.SSLv3 );

    ServiceArgs serviceArgs = new ServiceArgs();
            ..........................

Code :1 :

ServiceArgs serviceArgs = new ServiceArgs();
serviceArgs.setHost("https://127.0.0.1");
serviceArgs.setPort(8089);
Service service = Service.connect(serviceArgs);
service.login("USERNAME","PASSWORD");

Exception : 1:

Exception in thread "main" java.lang.IllegalArgumentException: URI can't be null.
at sun.net.spi.DefaultProxySelector.select(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
at com.splunk.HttpService.send(HttpService.java:445)
at com.splunk.Service.send(Service.java:1295)
at com.splunk.HttpService.post(HttpService.java:348)
at com.splunk.Service.login(Service.java:1124)
at.....

Code :2 :

ServiceArgs serviceArgs = new ServiceArgs();
serviceArgs.setHost("127.0.0.1");
serviceArgs.setPort(8089);
Service service = Service.connect(serviceArgs);
service.login("USERNAME","PASSWORD");

Exception : 2 :

refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
at com.splunk.HttpService.send(HttpService.java:451)
at com.splunk.Service.send(Service.java:1295)
at com.splunk.HttpService.post(HttpService.java:348)
at com.splunk.Service.login(Service.java:1124)
at.....

0 Karma

p_gurav
Champion

Can you try actual IP or localhost instead like serviceArgs.setHost("https://<IP or localhost>") instead of 127.0.0.1?

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...