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!

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...

Purpose in Action: How Splunk Is Helping Power an Inclusive Future for All

At Cisco, purpose isn’t a tagline—it’s a commitment. Cisco’s FY25 Purpose Report outlines how the company is ...

[Upcoming Webinar] Demo Day: Transforming IT Operations with Splunk

Join us for a live Demo Day at the Cisco Store on January 21st 10:00am - 11:00am PST In the fast-paced world ...