Skip to content

Commit 68f0aae

Browse files
committed
feat(BaseService): Add implementation for reactive service calls with and without added detail
1 parent 1bb0e19 commit 68f0aae

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/main/java/com/ibm/cloud/sdk/core/http/ServiceCall.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package com.ibm.cloud.sdk.core.http;
1414

15+
import io.reactivex.Single;
1516
import jersey.repackaged.jsr166e.CompletableFuture;
1617

1718
/**
@@ -75,4 +76,19 @@ public interface ServiceCall<T> {
7576
* @return a CompletableFuture wrapper for your response
7677
*/
7778
CompletableFuture<Response<T>> rxWithDetails();
79+
80+
/**
81+
* Reactive request using the RxJava 2 library. See https://github.com/ReactiveX/RxJava.
82+
*
83+
* @return a Single object containing the service call to be observed/subscribed to
84+
*/
85+
Single<T> reactiveRequest();
86+
87+
/**
88+
* Reactive request using the RxJava 2 library. See https://github.com/ReactiveX/RxJava. In addition, the wrapped
89+
* service call will contain added HTTP information.
90+
*
91+
* @return a Single object containing the service call to be observed/subscribed to
92+
*/
93+
Single<Response<T>> reactiveRequestWithDetails();
7894
}

src/main/java/com/ibm/cloud/sdk/core/service/BaseService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.ibm.cloud.sdk.core.service.security.IamTokenManager;
3636
import com.ibm.cloud.sdk.core.util.CredentialUtils;
3737
import com.ibm.cloud.sdk.core.util.RequestUtils;
38+
import io.reactivex.Single;
3839
import jersey.repackaged.jsr166e.CompletableFuture;
3940
import okhttp3.Call;
4041
import okhttp3.Callback;
@@ -47,6 +48,7 @@
4748

4849
import java.io.IOException;
4950
import java.util.Map;
51+
import java.util.concurrent.Callable;
5052
import java.util.logging.Logger;
5153
import java.util.regex.Pattern;
5254

@@ -586,6 +588,29 @@ public void onResponse(Call call, Response response) {
586588
return completableFuture;
587589
}
588590

591+
@Override
592+
public Single<T> reactiveRequest() {
593+
return Single.fromCallable(new Callable<T>() {
594+
@Override
595+
public T call() throws Exception {
596+
Response response = call.execute();
597+
return processServiceCall(converter, response);
598+
}
599+
});
600+
}
601+
602+
@Override
603+
public Single<com.ibm.cloud.sdk.core.http.Response<T>> reactiveRequestWithDetails() {
604+
return Single.fromCallable(new Callable<com.ibm.cloud.sdk.core.http.Response<T>>() {
605+
@Override
606+
public com.ibm.cloud.sdk.core.http.Response<T> call() throws Exception {
607+
Response httpResponse = call.execute();
608+
T responseModel = processServiceCall(converter, httpResponse);
609+
return new com.ibm.cloud.sdk.core.http.Response<>(responseModel, httpResponse);
610+
}
611+
});
612+
}
613+
589614
@Override
590615
protected void finalize() throws Throwable {
591616
super.finalize();

0 commit comments

Comments
 (0)