From: Gustavo Martin Morcuende Date: Sun, 11 Dec 2016 20:17:30 +0000 (+0100) Subject: Update to RxJava 2.0 X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=91acea55ef8a68642915c2034c6a6aab27153e60;p=JavaForFun Update to RxJava 2.0 --- diff --git a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/RxJavaBusinessLogic.java b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/RxJavaBusinessLogic.java index 01a6189..d86922f 100644 --- a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/RxJavaBusinessLogic.java +++ b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/RxJavaBusinessLogic.java @@ -4,7 +4,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import de.spring.webservices.domain.Car; -import rx.Observable; +import io.reactivex.Observable; public interface RxJavaBusinessLogic { diff --git a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/RxJavaBusinessLogicImpl.java b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/RxJavaBusinessLogicImpl.java index db032a0..930972f 100644 --- a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/RxJavaBusinessLogicImpl.java +++ b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/business/service/impl/RxJavaBusinessLogicImpl.java @@ -13,8 +13,8 @@ import org.springframework.stereotype.Service; 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") @@ -59,7 +59,7 @@ public class RxJavaBusinessLogicImpl implements RxJavaBusinessLogic { Exceptions.propagate(ex); } - + }); } } diff --git a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/controller/RxJavaCarController.java b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/controller/RxJavaCarController.java index 3aa72d2..34827cb 100644 --- a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/controller/RxJavaCarController.java +++ b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/controller/RxJavaCarController.java @@ -26,7 +26,7 @@ import org.springframework.web.context.request.async.DeferredResult; import de.spring.webservices.domain.Car; import de.spring.webservices.rest.business.service.RxJavaBusinessLogic; -import rx.Observable; +import io.reactivex.Observable; @RestController @RequestMapping("/api/rxjava/cars/") diff --git a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/controller/adapters/RxJavaAdapter.java b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/controller/adapters/RxJavaAdapter.java index 04ee276..a2e9920 100644 --- a/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/controller/adapters/RxJavaAdapter.java +++ b/SpringJava/RxJava/web-services-spring-rxjava-server/src/main/java/de/spring/webservices/rest/controller/adapters/RxJavaAdapter.java @@ -4,8 +4,9 @@ import org.slf4j.Logger; 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); @@ -18,7 +19,7 @@ public class RxJavaAdapter { public static final DeferredResult deferredAdapter(Observable observable) { DeferredResult deferredResult = new DeferredResult<>(ASYNC_TIMEOUT); - + observable .subscribeOn(Schedulers.io()) .subscribe(deferredResult::setResult, exception -> { @@ -32,6 +33,23 @@ public class RxJavaAdapter { return deferredResult; } + public static final DeferredResult deferredAdapter(Single single) { + + DeferredResult 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()