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
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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...