Splunk Dev

Unble to connect to splunk server via java sdk

chitranjan155
New Member

Hi,

PFB the code i am using to connect to splunk using java sdk.

         HttpService.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );
     ServiceArgs serviceArgs = new ServiceArgs();
     serviceArgs.setHost("mycompanysplunkServer.net");  // complete url https://mycompanysplunkServer.net
     serviceArgs.setPort(8089);
     serviceArgs.setUsername("myusername");
     serviceArgs.setPassword("mypassword");

     // Create a Service instance and log in with the argument map
     Service service = Service.connect(serviceArgs);

     System.out.println(service.getToken().toString());
     for (Application app : service.getApplications().values()) {
         System.out.println(app.getName());
     }

I am able to connect to local splunk using localhost as host. However when i am using mycompanysplunkServer.net to connect to splunk server i am getting connection timeout error.
Below is error stack.

Exception in thread "main" java.lang.RuntimeException: Operation timed out (Connection timed out)
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 com.splunk.Service.login(Service.java:1103)
at com.splunk.Service.connect(Service.java:189)
at com.test.slpunkUiDemo.SplunkConnectApp.main(SplunkConnectApp.java:20)
Caused by: java.net.ConnectException: Operation timed out (Connection timed out)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConne...
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1162)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1056)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.jav...
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1340)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1315)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:264)
at com.splunk.HttpService.send(HttpService.java:445)
... 6 more

Labels (1)
0 Karma

fredthefrog
Explorer

Try this instead:
ServiceArgs serviceArgs = new ServiceArgs();
serviceArgs.setHost("mycompanysplunkServer.net"); // complete url https://mycompanysplunkServer.net
serviceArgs.setPort(8089);
serviceArgs.setUsername("myusername");
serviceArgs.setPassword("mypassword");
serviceArgs.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Splunk Add-on for Microsoft Windows 11.0.3: Parse Once, Search Faster

The updated Splunk Add-on for Microsoft Windows helps customers search Windows events faster by reducing ...

What's New in Splunk Enterprise Security 8.8 and Beyond

Threats move at machine speed. Keeping up should not depend on having the biggest budget, the largest team, or ...

A Four-Part Event Series: State of Observability - Where AI Meets Performance

As AI agents take on more complex tasks, teams need greater visibility into how they behave, what they cost, ...