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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...