All Apps and Add-ons

connection refused error

anilsplunk
Loves-to-Learn

i have setup splunk on my local and now trying to connect to it via java code

what i see is Service.connect() step passes

 

but further when i try to create the search job 

jobs.create(mySearch);
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import com.splunk.Application;

import com.splunk.Service;

    import com.splunk.ServiceArgs;

    import com.splunk.*;

    

    import com.splunk.HttpService;

    import com.splunk.SSLSecurityProtocol;



    


    /**

     * Log in using an authentication token

     */

    public class SplunkTest {


        static Service service = null;

        /**

         * Authentication Token.

         * Actual token length would be longer than this token length.

         * @throws IOException 

         * @throws ` 

         */

        //static String token = "1k_Ostpl6NBe4iVQ5d6I3Ohla_U5";

        

        public static void main(String args[]) throws InterruptedException, IOException {

        

        HttpService.setSslSecurityProtocol( SSLSecurityProtocol.TLSv1_2 );

         String token = "REDACTED";


            ServiceArgs loginArgs = new ServiceArgs();

            loginArgs.setPort(8089);

            loginArgs.setHost("localhost");

            loginArgs.setScheme("https");

            loginArgs.setToken(String.format("Bearer %s", token));


            // Initialize the SDK client

            service = Service.connect(loginArgs);

            System.out.println(service.getHost());

           

            System.out.println("connected successfully");

           

            JobCollection jobs = service.getJobs();

            

            

            

            //System.out.println("There are " + jobs.size() + " jobs available to 'admin'\n");

            // Create a simple search job

            String mySearch = "search * | head 5";

            

            

         // Retrieves the collection of search jobs

            //JobCollection jobs = service.getJobs();

         // Creates a search job

            Job job1 = jobs.create(mySearch);
Labels (2)
0 Karma
Get Updates on the Splunk Community!

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...

Fun with Regular Expression - multiples of nine

Fun with Regular Expression - multiples of nineThis challenge was first posted on Slack #regex channel ...