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
30 changes: 18 additions & 12 deletions src/main/java/co/elastic/support/rest/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.*;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
Expand All @@ -29,7 +32,11 @@
import org.apache.http.conn.ssl.TrustAllStrategy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.*;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicHeader;
import org.apache.http.ssl.SSLContextBuilder;
Expand Down Expand Up @@ -85,11 +92,11 @@ private HttpResponse execRequest(HttpRequestBase httpRequest) {
try {
return client.execute(httpHost, httpRequest, httpContext);
} catch (HttpHostConnectException e) {
logger.error("Host connection error.", e);
throw new RuntimeException("Host connection");
logger.error("Host connection error", e);
throw new RuntimeException("Host connection failed", e);
} catch (Exception e) {
logger.error("Unexpected Execution Error", e);
throw new RuntimeException(e.getMessage());
logger.error("Unexpected execution error", e);
throw new RuntimeException("Unexpected error during HTTP execution", e);
}
}

Expand All @@ -103,16 +110,15 @@ public HttpResponse execPost(String uri, String payload) {
logger.debug(uri + SystemProperties.fileSeparator + payload);
return execRequest(httpPost);
} catch (UnsupportedEncodingException e) {
logger.error(Constants.CONSOLE, "Error with json body.", e);
throw new RuntimeException("Could not complete post request.");
logger.error(Constants.CONSOLE, "Error with JSON body", e);
throw new RuntimeException("Could not complete POST request", e);
}
}

public HttpResponse execDelete(String uri) {
HttpDelete httpDelete = new HttpDelete(uri);
logger.debug(uri);

return execRequest(httpDelete);
return execRequest(new HttpDelete(uri));
}

public void close() {
Expand All @@ -121,7 +127,7 @@ public void close() {
client.close();
}
} catch (Exception e) {
logger.error("Error occurred closing client connection.");
logger.error("Error occurred closing client connection", e);
}
}

Expand Down Expand Up @@ -229,4 +235,4 @@ public static RestClient getClient(
throw new RuntimeException("Error establishing http connection for: " + host, e);
}
}
}
}
Loading
Loading