From 67351eb180b2402b4fc564d76f67eb59a95aeb9b Mon Sep 17 00:00:00 2001 From: jhaber Date: Thu, 30 Jul 2026 15:08:08 -0400 Subject: [PATCH 1/3] add default methods to HttpClient and AsyncHttpClient so subclasses only need to implement a single method Co-Authored-By: Claude Sonnet 4.6 (1M context) --- .../horizon/apache/ApacheHttpClient.java | 5 --- .../com/hubspot/horizon/AsyncHttpClient.java | 33 +++++++++++++++++-- .../java/com/hubspot/horizon/HttpClient.java | 5 ++- .../horizon/ning/NingAsyncHttpClient.java | 10 ------ .../hubspot/horizon/ning/NingHttpClient.java | 5 --- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/HorizonApache/src/main/java/com/hubspot/horizon/apache/ApacheHttpClient.java b/HorizonApache/src/main/java/com/hubspot/horizon/apache/ApacheHttpClient.java index 51da722..27f83b1 100644 --- a/HorizonApache/src/main/java/com/hubspot/horizon/apache/ApacheHttpClient.java +++ b/HorizonApache/src/main/java/com/hubspot/horizon/apache/ApacheHttpClient.java @@ -143,11 +143,6 @@ private SocketConfig createSocketConfig(HttpConfig config) { return SocketConfig.custom().setSoTimeout(config.getRequestTimeoutMillis()).build(); } - @Override - public HttpResponse execute(HttpRequest request) throws HttpRuntimeException { - return execute(Preconditions.checkNotNull(request), Options.DEFAULT); - } - @Override public HttpResponse execute(HttpRequest request, Options options) throws HttpRuntimeException { diff --git a/HorizonCore/src/main/java/com/hubspot/horizon/AsyncHttpClient.java b/HorizonCore/src/main/java/com/hubspot/horizon/AsyncHttpClient.java index d822323..d74e060 100644 --- a/HorizonCore/src/main/java/com/hubspot/horizon/AsyncHttpClient.java +++ b/HorizonCore/src/main/java/com/hubspot/horizon/AsyncHttpClient.java @@ -1,14 +1,41 @@ package com.hubspot.horizon; import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.SettableFuture; import com.hubspot.horizon.HttpRequest.Options; import java.io.Closeable; public interface AsyncHttpClient extends Closeable { - ListenableFuture execute(HttpRequest request); - ListenableFuture execute(HttpRequest request, Options options); + default ListenableFuture execute(HttpRequest request) { + return execute(request, Options.DEFAULT); + } + + default ListenableFuture execute(HttpRequest request, Options options) { + SettableFuture responseFuture = SettableFuture.create(); + + try { + execute(request, options, new Callback() { + @Override + public void completed(HttpResponse response) { + responseFuture.set(response); + } + + @Override + public void failed(Exception e) { + responseFuture.setException(e); + } + }); + } catch (HttpRuntimeException e) { + responseFuture.setException(e); + } + + return responseFuture; + } + + default void execute(HttpRequest request, Callback callback) { + execute(request, Options.DEFAULT, callback); + } - void execute(HttpRequest request, Callback callback); void execute(HttpRequest request, Options options, Callback callback); interface Callback { diff --git a/HorizonCore/src/main/java/com/hubspot/horizon/HttpClient.java b/HorizonCore/src/main/java/com/hubspot/horizon/HttpClient.java index 07ec73c..dc37b1e 100644 --- a/HorizonCore/src/main/java/com/hubspot/horizon/HttpClient.java +++ b/HorizonCore/src/main/java/com/hubspot/horizon/HttpClient.java @@ -4,6 +4,9 @@ import java.io.Closeable; public interface HttpClient extends Closeable { - HttpResponse execute(HttpRequest request) throws HttpRuntimeException; + default HttpResponse execute(HttpRequest request) throws HttpRuntimeException { + return execute(request, Options.DEFAULT); + } + HttpResponse execute(HttpRequest request, Options options) throws HttpRuntimeException; } diff --git a/HorizonNing/src/main/java/com/hubspot/horizon/ning/NingAsyncHttpClient.java b/HorizonNing/src/main/java/com/hubspot/horizon/ning/NingAsyncHttpClient.java index 10e4920..bb311bf 100644 --- a/HorizonNing/src/main/java/com/hubspot/horizon/ning/NingAsyncHttpClient.java +++ b/HorizonNing/src/main/java/com/hubspot/horizon/ning/NingAsyncHttpClient.java @@ -108,21 +108,11 @@ public NingAsyncHttpClient(HttpConfig config) { this.mapper = config.getObjectMapper(); } - @Override - public ListenableFuture execute(HttpRequest request) { - return execute(Preconditions.checkNotNull(request), Options.DEFAULT); - } - @Override public ListenableFuture execute(HttpRequest request, Options options) { return internalExecute(request, options, EmptyCallback.INSTANCE); } - @Override - public void execute(HttpRequest request, Callback callback) { - execute(Preconditions.checkNotNull(request), Options.DEFAULT, callback); - } - @Override public void execute(HttpRequest request, Options options, Callback callback) { internalExecute(request, options, callback); diff --git a/HorizonNing/src/main/java/com/hubspot/horizon/ning/NingHttpClient.java b/HorizonNing/src/main/java/com/hubspot/horizon/ning/NingHttpClient.java index 7ab43ef..7ef711a 100644 --- a/HorizonNing/src/main/java/com/hubspot/horizon/ning/NingHttpClient.java +++ b/HorizonNing/src/main/java/com/hubspot/horizon/ning/NingHttpClient.java @@ -22,11 +22,6 @@ public NingHttpClient(HttpConfig config) { this.delegate = new NingAsyncHttpClient(Preconditions.checkNotNull(config)); } - @Override - public HttpResponse execute(HttpRequest request) throws HttpRuntimeException { - return execute(Preconditions.checkNotNull(request), Options.DEFAULT); - } - @Override public HttpResponse execute(HttpRequest request, Options options) throws HttpRuntimeException { From b848a8f95f00c778092e037d956006b9a0fa6f3b Mon Sep 17 00:00:00 2001 From: jhaber Date: Thu, 30 Jul 2026 15:08:26 -0400 Subject: [PATCH 2/3] spotless formatting Co-Authored-By: Claude Sonnet 4.6 (1M context) --- .../com/hubspot/horizon/AsyncHttpClient.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/HorizonCore/src/main/java/com/hubspot/horizon/AsyncHttpClient.java b/HorizonCore/src/main/java/com/hubspot/horizon/AsyncHttpClient.java index d74e060..1c6e455 100644 --- a/HorizonCore/src/main/java/com/hubspot/horizon/AsyncHttpClient.java +++ b/HorizonCore/src/main/java/com/hubspot/horizon/AsyncHttpClient.java @@ -14,17 +14,21 @@ default ListenableFuture execute(HttpRequest request, Options opti SettableFuture responseFuture = SettableFuture.create(); try { - execute(request, options, new Callback() { - @Override - public void completed(HttpResponse response) { - responseFuture.set(response); + execute( + request, + options, + new Callback() { + @Override + public void completed(HttpResponse response) { + responseFuture.set(response); + } + + @Override + public void failed(Exception e) { + responseFuture.setException(e); + } } - - @Override - public void failed(Exception e) { - responseFuture.setException(e); - } - }); + ); } catch (HttpRuntimeException e) { responseFuture.setException(e); } From ff62ad4a904d35b34776e78c297267126638ee43 Mon Sep 17 00:00:00 2001 From: jhaber Date: Thu, 30 Jul 2026 15:14:44 -0400 Subject: [PATCH 3/3] make Options.DEFAULT final to fix SpotBugs MS_SHOULD_BE_FINAL Co-Authored-By: Claude Sonnet 4.6 (1M context) --- HorizonCore/src/main/java/com/hubspot/horizon/HttpRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HorizonCore/src/main/java/com/hubspot/horizon/HttpRequest.java b/HorizonCore/src/main/java/com/hubspot/horizon/HttpRequest.java index 0577ea8..2354bd3 100644 --- a/HorizonCore/src/main/java/com/hubspot/horizon/HttpRequest.java +++ b/HorizonCore/src/main/java/com/hubspot/horizon/HttpRequest.java @@ -133,7 +133,7 @@ public Options getOptions() { public static class Options { - public static Options DEFAULT = new Options(); + public static final Options DEFAULT = new Options(); private Optional maxRetries = Optional.absent(); private Optional initialRetryBackoffSeconds = Optional.absent();