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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...