import de.spring.webservices.domain.Car;
import de.spring.webservices.rest.business.service.AwesomeBusinessLogic;
import de.spring.webservices.rest.business.service.RxJavaBusinessLogic;
-import rx.Observable;
-import rx.exceptions.Exceptions;
+import io.reactivex.Observable;
+import io.reactivex.exceptions.Exceptions;
@Service("rxJavaBusinessLogic")
Exceptions.propagate(ex);
}
-
+
});
}
}
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.async.DeferredResult;
-import rx.Observable;
-import rx.schedulers.Schedulers;
+import io.reactivex.Observable;
+import io.reactivex.Single;
+import io.reactivex.schedulers.Schedulers;
public class RxJavaAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(RxJavaAdapter.class);
public static final <T> DeferredResult<T> deferredAdapter(Observable<T> observable) {
DeferredResult<T> deferredResult = new DeferredResult<>(ASYNC_TIMEOUT);
-
+
observable
.subscribeOn(Schedulers.io())
.subscribe(deferredResult::setResult, exception -> {
return deferredResult;
}
+ public static final <T> DeferredResult<T> deferredAdapter(Single<T> single) {
+
+ DeferredResult<T> deferredResult = new DeferredResult<>(ASYNC_TIMEOUT);
+
+ single
+ .subscribeOn(Schedulers.io())
+ .subscribe(deferredResult::setResult, exception -> {
+ Throwable realException = launderException(exception);
+
+ LOGGER.error("error: ", realException);
+
+ deferredResult.setErrorResult(realException);
+ });
+
+ return deferredResult;
+ }
+
private static final Throwable launderException(Throwable exception) {
return exception.getCause() != null
? exception.getCause()