Skip to content

Commit 84d17d8

Browse files
committed
Applying PR review suggestions
1 parent 91f876a commit 84d17d8

File tree

1 file changed

+24
-14
lines changed
  • opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/connectivity/http

1 file changed

+24
-14
lines changed

opamp-client/src/main/java/io/opentelemetry/opamp/client/internal/connectivity/http/OkHttpSender.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
import java.io.OutputStream;
1111
import java.util.concurrent.CompletableFuture;
1212
import java.util.function.Consumer;
13+
import okhttp3.Call;
14+
import okhttp3.Callback;
1315
import okhttp3.MediaType;
1416
import okhttp3.OkHttpClient;
1517
import okhttp3.RequestBody;
18+
import okhttp3.Response;
1619
import okio.BufferedSink;
1720
import org.jetbrains.annotations.NotNull;
1821
import org.jetbrains.annotations.Nullable;
@@ -46,20 +49,27 @@ public CompletableFuture<Response> send(Consumer<OutputStream> writer, int conte
4649
RequestBody body = new RawRequestBody(writer, contentLength, MEDIA_TYPE);
4750
builder.post(body);
4851

49-
try {
50-
okhttp3.Response response = client.newCall(builder.build()).execute();
51-
if (response.isSuccessful()) {
52-
if (response.body() != null) {
53-
future.complete(new OkHttpResponse(response));
54-
}
55-
} else {
56-
future.completeExceptionally(new HttpErrorException(response.code(), response.message()));
57-
}
58-
} catch (IOException e) {
59-
future.completeExceptionally(e);
60-
}
61-
62-
future.completeExceptionally(new IllegalStateException());
52+
client
53+
.newCall(builder.build())
54+
.enqueue(
55+
new Callback() {
56+
@Override
57+
public void onResponse(@NotNull Call call, @NotNull okhttp3.Response response) {
58+
if (response.isSuccessful()) {
59+
if (response.body() != null) {
60+
future.complete(new OkHttpResponse(response));
61+
}
62+
} else {
63+
future.completeExceptionally(
64+
new HttpErrorException(response.code(), response.message()));
65+
}
66+
}
67+
68+
@Override
69+
public void onFailure(@NotNull Call call, @NotNull IOException e) {
70+
future.completeExceptionally(e);
71+
}
72+
});
6373

6474
return future;
6575
}

0 commit comments

Comments
 (0)