Skip to content

Commit a9c1ecd

Browse files
committed
refactor: Always return wrapped response with HTTP info
BREAKING CHANGE: The old executeWithDetails() and enqueueWithDetails() methods have been deleted. In addition, the basic versions of those methods now return the wrapped response that the old methods used to.
1 parent ccef306 commit a9c1ecd

File tree

4 files changed

+13
-111
lines changed

4 files changed

+13
-111
lines changed

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

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,24 @@ public interface ServiceCall<T> {
3333
/**
3434
* Synchronous request.
3535
*
36-
* @return the generic type
37-
* @throws RuntimeException the exception from HTTP request
38-
*/
39-
T execute() throws RuntimeException;
40-
41-
/**
42-
* Synchronous request with added HTTP information.
43-
*
4436
* @return a Response object with the generic response model and various HTTP information fields
45-
* @throws RuntimeException the exception from the HTTP request
46-
*/
47-
Response<T> executeWithDetails() throws RuntimeException;
48-
49-
/**
50-
* Asynchronous requests, in this case, you receive a callback when the data has been received.
51-
*
52-
* @param callback the callback
37+
* @throws RuntimeException the exception from HTTP request
5338
*/
54-
void enqueue(ServiceCallback<? super T> callback);
39+
Response<T> execute() throws RuntimeException;
5540

5641
/**
57-
* Asynchronous requests with added HTTP information. In this case, you receive a callback when the data has been
42+
* Asynchronous request with added HTTP information. In this case, you receive a callback when the data has been
5843
* received.
5944
*
6045
* @param callback the callback
6146
*/
62-
void enqueueWithDetails(ServiceCallbackWithDetails<T> callback);
63-
64-
/**
65-
* Reactive request using the RxJava 2 library. See https://github.com/ReactiveX/RxJava.
66-
*
67-
* @return a Single object containing the service call to be observed/subscribed to
68-
*/
69-
Single<T> reactiveRequest();
47+
void enqueue(ServiceCallback<? super T> callback);
7048

7149
/**
7250
* Reactive request using the RxJava 2 library. See https://github.com/ReactiveX/RxJava. In addition, the wrapped
7351
* service call will contain added HTTP information.
7452
*
7553
* @return a Single object containing the service call to be observed/subscribed to
7654
*/
77-
Single<Response<T>> reactiveRequestWithDetails();
55+
Single<Response<T>> reactiveRequest();
7856
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface ServiceCallback<T> {
2424
*
2525
* @param response the response
2626
*/
27-
void onResponse(T response);
27+
void onResponse(Response<T> response);
2828

2929
/**
3030
* Called if there is an error during the request.

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

Lines changed: 0 additions & 35 deletions
This file was deleted.

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

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.ibm.cloud.sdk.core.http.ResponseConverter;
2020
import com.ibm.cloud.sdk.core.http.ServiceCall;
2121
import com.ibm.cloud.sdk.core.http.ServiceCallback;
22-
import com.ibm.cloud.sdk.core.http.ServiceCallbackWithDetails;
2322
import com.ibm.cloud.sdk.core.service.exception.BadRequestException;
2423
import com.ibm.cloud.sdk.core.service.exception.ConflictException;
2524
import com.ibm.cloud.sdk.core.service.exception.ForbiddenException;
@@ -480,47 +479,18 @@ public ServiceCall<T> addHeader(String name, String value) {
480479
}
481480

482481
@Override
483-
public T execute() {
482+
public com.ibm.cloud.sdk.core.http.Response<T> execute() {
484483
try {
485484
Response response = call.execute();
486-
return processServiceCall(converter, response);
487-
} catch (IOException e) {
488-
throw new RuntimeException(e);
489-
}
490-
}
491-
492-
@Override
493-
public com.ibm.cloud.sdk.core.http.Response<T> executeWithDetails() throws RuntimeException {
494-
try {
495-
Response httpResponse = call.execute();
496-
T responseModel = processServiceCall(converter, httpResponse);
497-
return new com.ibm.cloud.sdk.core.http.Response<>(responseModel, httpResponse);
485+
T responseModel = processServiceCall(converter, response);
486+
return new com.ibm.cloud.sdk.core.http.Response<>(responseModel, response);
498487
} catch (IOException e) {
499488
throw new RuntimeException(e);
500489
}
501490
}
502491

503492
@Override
504493
public void enqueue(final ServiceCallback<? super T> callback) {
505-
call.enqueue(new Callback() {
506-
@Override
507-
public void onFailure(Call call, IOException e) {
508-
callback.onFailure(e);
509-
}
510-
511-
@Override
512-
public void onResponse(Call call, Response response) {
513-
try {
514-
callback.onResponse(processServiceCall(converter, response));
515-
} catch (Exception e) {
516-
callback.onFailure(e);
517-
}
518-
}
519-
});
520-
}
521-
522-
@Override
523-
public void enqueueWithDetails(final ServiceCallbackWithDetails<T> callback) {
524494
call.enqueue(new Callback() {
525495
@Override
526496
public void onFailure(Call call, IOException e) {
@@ -540,24 +510,13 @@ public void onResponse(Call call, Response response) {
540510
}
541511

542512
@Override
543-
public Single<T> reactiveRequest() {
544-
return Single.fromCallable(new Callable<T>() {
545-
@Override
546-
public T call() throws Exception {
547-
Response response = call.execute();
548-
return processServiceCall(converter, response);
549-
}
550-
});
551-
}
552-
553-
@Override
554-
public Single<com.ibm.cloud.sdk.core.http.Response<T>> reactiveRequestWithDetails() {
513+
public Single<com.ibm.cloud.sdk.core.http.Response<T>> reactiveRequest() {
555514
return Single.fromCallable(new Callable<com.ibm.cloud.sdk.core.http.Response<T>>() {
556515
@Override
557516
public com.ibm.cloud.sdk.core.http.Response<T> call() throws Exception {
558-
Response httpResponse = call.execute();
559-
T responseModel = processServiceCall(converter, httpResponse);
560-
return new com.ibm.cloud.sdk.core.http.Response<>(responseModel, httpResponse);
517+
Response response = call.execute();
518+
T responseModel = processServiceCall(converter, response);
519+
return new com.ibm.cloud.sdk.core.http.Response<>(responseModel, response);
561520
}
562521
});
563522
}

0 commit comments

Comments
 (0)