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!

[Puzzles] Solve, Learn, Repeat: Unmerging HTML Tables

[Puzzles] Solve, Learn, Repeat: Unmerging HTML TablesFor a previous puzzle, I needed some sample data, and ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...

AI for AppInspect

We’re excited to announce two new updates to AppInspect designed to save you time and make the app approval ...