Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.databunker</groupId>
<artifactId>databunkerpro-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>DatabunkerPro Java Client</name>
Expand All @@ -20,18 +20,11 @@
</properties>

<dependencies>
<!-- Apache HttpClient -->
<!-- Apache HttpClient 5 (httpcore5 comes in transitively) -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
</dependency>

<!-- Apache HttpCore -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.16</version>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.6.4</version>
</dependency>

<!-- Jackson for JSON processing -->
Expand Down Expand Up @@ -87,7 +80,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.15.0</version>
<configuration>
<source>11</source>
<target>11</target>
Expand All @@ -96,7 +89,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.4.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -109,7 +102,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.2</version>
<version>3.12.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/org/databunker/DatabunkerproApi.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.databunker;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.http.client.methods.HttpGet;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.databunker.options.BasicOptions;
import org.databunker.options.UserOptions;
import org.databunker.options.SharedRecordOptions;
Expand Down Expand Up @@ -84,7 +86,7 @@ private Map<String, Object> makeRequest(String endpoint, Map<String, Object> dat
if (requestMetadata != null) {
bodyData.put("request_metadata", requestMetadata);
}
StringEntity entity = new StringEntity(objectMapper.writeValueAsString(bodyData));
StringEntity entity = new StringEntity(objectMapper.writeValueAsString(bodyData), ContentType.APPLICATION_JSON);
request.setEntity(entity);
}

Expand All @@ -93,7 +95,7 @@ private Map<String, Object> makeRequest(String endpoint, Map<String, Object> dat
String responseString = EntityUtils.toString(entity);
Map<String, Object> result = objectMapper.readValue(responseString, Map.class);

if (response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() >= 300) {
if (response.getCode() < 200 || response.getCode() >= 300) {
if (result.containsKey("status")) {
return result;
} else {
Expand Down Expand Up @@ -134,7 +136,7 @@ private byte[] rawRequest(String endpoint, Map<String, Object> data, Map<String,
if (requestMetadata != null) {
bodyData.put("request_metadata", requestMetadata);
}
StringEntity entity = new StringEntity(objectMapper.writeValueAsString(bodyData));
StringEntity entity = new StringEntity(objectMapper.writeValueAsString(bodyData), ContentType.APPLICATION_JSON);
request.setEntity(entity);
}

Expand Down Expand Up @@ -1696,6 +1698,8 @@ public Map<String, Object> getSystemMetrics(Map<String, Object> requestMetadata)
HttpEntity entity = response.getEntity();
String metricsText = EntityUtils.toString(entity);
return parsePrometheusMetrics(metricsText);
} catch (ParseException error) {
throw new IOException("Failed to parse the metrics response", error);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/databunker/DatabunkerproApiPciTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.databunker;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/databunker/DatabunkerproApiTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.databunker;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down
Loading