Splunk Dev

Connection reset Error occurred while connect service.connect method

npbala_22
Explorer

Splunk DB connect Code:

public static void connectSplunk(){
ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername("XXXXX");
loginArgs.setPassword("yyyyyyy");
loginArgs.setHost("xxxx.yyyy.zzz.com");
loginArgs.setPort(8089);
loginArgs.setScheme("http");
Service service = Service.connect(loginArgs);
}

While Connect the Splunk with connect.service method getting below error. help to resolve
Exception in thread "main" java.lang.RuntimeException: Connection reset
at com.splunk.HttpService.send(HttpService.java:469)
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.sdn.core.sample.connectSplunk(sample.java:23)
at com.sdn.core.sample.main(sample.java:13)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:675)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at com.splunk.HttpService.send(HttpService.java:467)
... 7 more

Tags (1)
0 Karma

creigelde
New Member

Connection reset socket error occurs when the opponent is forcibly terminated without calling close(). This simply means that a TCP RST was received. TCP RST packet is that the remote side telling you the connection on which the previous TCP packet is sent is not recognized, maybe the connection has closed, maybe the port is not open, and something like these. A reset packet is simply one with no payload and with the RST bit set in the TCP header flags. There are several possible causes.

The other end has deliberately reset the connection, in a way which I will not document here. It is rare, and generally incorrect, for application software to do this, but it is not unknown for commercial software.

More commonly, it is caused by writing to a connection that the other end has already closed normally. In other words an application protocol error.

It can also be caused by closing a socket when there is unread data in the socket receive buffer.

0 Karma

shubhamgkale
Engager

import these classes:

import com.splunk.HttpService;
import com.splunk.SSLSecurityProtocol;

example

HttpService.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );
Map connectionArgs = new HashMap();
connectionArgs.put("host", "localhost");
connectionArgs.put("username", "admin");
connectionArgs.put("password", "changeme");
connectionArgs.put("port", 8089);
connectionArgs.put("scheme", "https");
Service service = Service.connect(connectionArgs);

0 Karma

p_gurav
Champion

Try adding this line:
service.login();

After :

 Service.connect(loginArgs);

Also refer:
https://answers.splunk.com/answers/64423/connection-refused-what-may-be-the-root-cause.html

0 Karma

npbala_22
Explorer

Am getting error on Service.connect(loginArgs); line.. Still getting same error

0 Karma
Get Updates on the Splunk Community!

Registration for Splunk University is Now Open!

Are you ready for an adventure in learning?   Brace yourselves because Splunk University is back, and it's ...

Splunkbase | Splunk Dashboard Examples App for SimpleXML End of Life

The Splunk Dashboard Examples App for SimpleXML will reach end of support on Dec 19, 2024, after which no new ...

Understanding Generative AI Techniques and Their Application in Cybersecurity

Watch On-Demand Artificial intelligence is the talk of the town nowadays, with industries of all kinds ...