<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to send data to HEC using Java SDK? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-send-data-to-HEC-using-Java-SDK/m-p/320589#M93480</link>
    <description>&lt;P&gt;I'm looking for sample code that I can use to send json from my java app into the HEC.   I'm having trouble connecting to HEC from the java program.  I was hoping to be able to use the Splunk Java SDK, but I don't see any classes in there to support the HEC, so  I'm using the Apache HttpClient implementation:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://ip:8088/services/collector/event");
httppost.addHeader("Authorization", " Splunk &amp;lt;token id&amp;gt;");
String eventStr = "{sourcetype=accm_json, index=accm, event={ dataType: TEXT, filesize: 103212, processor: abc}}"
httppost.setEntity(new StringEntity(eventStr);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
System.out.println("response: " + entity);
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run the code, the java program throws an SSLHandshakeException "unable to find valid certification path to the requested target" and the splunkd.log on the HEC shows "alert certificate unknown.  &lt;/P&gt;

&lt;P&gt;I don't understand what I am supposed to provide to be able to connect to the HEC from java.  Can someone please help?  I am able to insert events into HEC using cURL:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -k &lt;A href="https://ip:8088/services/collector/event" target="test_blank"&gt;https://ip:8088/services/collector/event&lt;/A&gt; -H 'Authorization Splunk &amp;lt;token&amp;gt;' -d  '{"sourcetype": "accm-json", "index":"accm", "event": {"dataType": "TEXT", "filesize":103212, "processor": "abc"}}'
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Jan 2018 13:47:43 GMT</pubDate>
    <dc:creator>lyndac</dc:creator>
    <dc:date>2018-01-19T13:47:43Z</dc:date>
    <item>
      <title>How to send data to HEC using Java SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-send-data-to-HEC-using-Java-SDK/m-p/320589#M93480</link>
      <description>&lt;P&gt;I'm looking for sample code that I can use to send json from my java app into the HEC.   I'm having trouble connecting to HEC from the java program.  I was hoping to be able to use the Splunk Java SDK, but I don't see any classes in there to support the HEC, so  I'm using the Apache HttpClient implementation:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://ip:8088/services/collector/event");
httppost.addHeader("Authorization", " Splunk &amp;lt;token id&amp;gt;");
String eventStr = "{sourcetype=accm_json, index=accm, event={ dataType: TEXT, filesize: 103212, processor: abc}}"
httppost.setEntity(new StringEntity(eventStr);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
System.out.println("response: " + entity);
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run the code, the java program throws an SSLHandshakeException "unable to find valid certification path to the requested target" and the splunkd.log on the HEC shows "alert certificate unknown.  &lt;/P&gt;

&lt;P&gt;I don't understand what I am supposed to provide to be able to connect to the HEC from java.  Can someone please help?  I am able to insert events into HEC using cURL:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -k &lt;A href="https://ip:8088/services/collector/event" target="test_blank"&gt;https://ip:8088/services/collector/event&lt;/A&gt; -H 'Authorization Splunk &amp;lt;token&amp;gt;' -d  '{"sourcetype": "accm-json", "index":"accm", "event": {"dataType": "TEXT", "filesize":103212, "processor": "abc"}}'
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jan 2018 13:47:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-send-data-to-HEC-using-Java-SDK/m-p/320589#M93480</guid>
      <dc:creator>lyndac</dc:creator>
      <dc:date>2018-01-19T13:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data to HEC using Java SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-send-data-to-HEC-using-Java-SDK/m-p/320590#M93481</link>
      <description>&lt;P&gt;When you're using curl, you are using the &lt;CODE&gt;-k&lt;/CODE&gt; flag&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   -k, --insecure
          (TLS) By default, every SSL connection curl makes is verified to be secure. This option allows curl to proceed and operate even for server connections otherwise considered insecure.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Looks like they've changed the interface a bunch between minor verisons of http client for some reason, but here's a Stack Overflow post that shows a bunch of the methods ignoring certificates &lt;/P&gt;

&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/2703161/how-to-ignore-ssl-certificate-errors-in-apache-httpclient-4-0"&gt;https://stackoverflow.com/questions/2703161/how-to-ignore-ssl-certificate-errors-in-apache-httpclient-4-0&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;What you probably should do, though, is to add your certificate to your trust store.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://medium.com/@codebyamir/the-java-developers-guide-to-ssl-certificates-b78142b3a0fc"&gt;https://medium.com/@codebyamir/the-java-developers-guide-to-ssl-certificates-b78142b3a0fc&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 17:19:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-send-data-to-HEC-using-Java-SDK/m-p/320590#M93481</guid>
      <dc:creator>cartoonbilly</dc:creator>
      <dc:date>2020-02-19T17:19:08Z</dc:date>
    </item>
  </channel>
</rss>

