Splunk Dev

Getting ClassCastException with Service.connect for Splunk sdk Java

deepaksplunk201
New Member

Hi,
I am using Splunk sdk for Java to access splunk REST API endpoints. I am trying to call API as per below code:
Code Snippet:
...
Map connectArgs=new HashMap();
connectArgs.put("host", "splunk");
connectArgs.put("username", "username");
connectArgs.put("password", "pass");
connectArgs.put("port", "8089");
connectArgs.put("scheme", "https");
Service splunkService=Service.connect(connectArgs); //Line with exception
...

It gives ClassCastException at service call "Service splunkService=Service.connect(connectArgs); ". Please find below for exception log:
...
Exception in thread "main" java.lang.ClassCastException: java.base/java.lang.String cannot be cast to java.base/java.lang.Integer
at com.splunk.Service.(Service.java:166)
...

Is there any dependency needs to be added to avoid exception. Please let me know where is the issue.

Thanks,

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@deepaksplunk201  @gayatri001 

I think port is Integer.

 

connectArgs.put("port", 8089);

 

 

Check below link for example.


https://www.programcreek.com/java-api-examples/?code=apache%2Fattic-apex-malhar%2Fattic-apex-malhar-...

 

Thanks
KV
▄︻̷̿┻̿═━一

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

0 Karma

gayatri001
New Member

Does the issues resolved. If yes may i know how. Even i am facing the same issue.

Tags (1)
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

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

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...