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!

CX Day is Coming!

Customer Experience (CX) Day is on October 7th!! We're so excited to bring back another day full of wonderful ...

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...