Polish Reactor & RxJava response extractors

This commit is contained in:
Sam Brannen 2016-07-15 17:54:24 +02:00
parent 1731460eac
commit 58804da369
2 changed files with 22 additions and 19 deletions

View File

@ -31,7 +31,7 @@ import reactor.core.publisher.Mono;
/** /**
* Static factory methods for {@link ResponseExtractor} based on the {@link Flux} and * Static factory methods for {@link ResponseExtractor} based on the {@link Flux} and
* {@link Mono} API. * {@link Mono} APIs.
* *
* @author Brian Clozel * @author Brian Clozel
* @since 5.0 * @since 5.0
@ -41,7 +41,7 @@ public class ResponseExtractors {
private static final Object EMPTY_BODY = new Object(); private static final Object EMPTY_BODY = new Object();
/** /**
* Extract the response body and decode it, returning it as a {@code Mono<T>} * Extract the response body and decode it, returning it as a {@code Mono<T>}.
* @see ResolvableType#forClassWithGenerics(Class, Class[]) * @see ResolvableType#forClassWithGenerics(Class, Class[])
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -53,7 +53,7 @@ public class ResponseExtractors {
} }
/** /**
* Extract the response body and decode it, returning it as a {@code Mono<T>} * Extract the response body and decode it, returning it as a {@code Mono<T>}.
*/ */
public static <T> ResponseExtractor<Mono<T>> body(Class<T> sourceClass) { public static <T> ResponseExtractor<Mono<T>> body(Class<T> sourceClass) {
ResolvableType bodyType = ResolvableType.forClass(sourceClass); ResolvableType bodyType = ResolvableType.forClass(sourceClass);
@ -61,7 +61,7 @@ public class ResponseExtractors {
} }
/** /**
* Extract the response body and decode it, returning it as a {@code Flux<T>} * Extract the response body and decode it, returning it as a {@code Flux<T>}.
* @see ResolvableType#forClassWithGenerics(Class, Class[]) * @see ResolvableType#forClassWithGenerics(Class, Class[])
*/ */
public static <T> ResponseExtractor<Flux<T>> bodyStream(ResolvableType bodyType) { public static <T> ResponseExtractor<Flux<T>> bodyStream(ResolvableType bodyType) {
@ -70,7 +70,7 @@ public class ResponseExtractors {
} }
/** /**
* Extract the response body and decode it, returning it as a {@code Flux<T>} * Extract the response body and decode it, returning it as a {@code Flux<T>}.
*/ */
public static <T> ResponseExtractor<Flux<T>> bodyStream(Class<T> sourceClass) { public static <T> ResponseExtractor<Flux<T>> bodyStream(Class<T> sourceClass) {
ResolvableType bodyType = ResolvableType.forClass(sourceClass); ResolvableType bodyType = ResolvableType.forClass(sourceClass);
@ -79,7 +79,7 @@ public class ResponseExtractors {
/** /**
* Extract the full response body as a {@code ResponseEntity} with its body decoded as * Extract the full response body as a {@code ResponseEntity} with its body decoded as
* a single type {@code T} * a single type {@code T}.
* @see ResolvableType#forClassWithGenerics(Class, Class[]) * @see ResolvableType#forClassWithGenerics(Class, Class[])
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -100,7 +100,7 @@ public class ResponseExtractors {
/** /**
* Extract the full response body as a {@code ResponseEntity} with its body decoded as * Extract the full response body as a {@code ResponseEntity} with its body decoded as
* a single type {@code T} * a single type {@code T}.
*/ */
public static <T> ResponseExtractor<Mono<ResponseEntity<T>>> response( public static <T> ResponseExtractor<Mono<ResponseEntity<T>>> response(
Class<T> bodyClass) { Class<T> bodyClass) {
@ -110,7 +110,7 @@ public class ResponseExtractors {
/** /**
* Extract the full response body as a {@code ResponseEntity} with its body decoded as * Extract the full response body as a {@code ResponseEntity} with its body decoded as
* a {@code Flux<T>} * a {@code Flux<T>}.
* @see ResolvableType#forClassWithGenerics(Class, Class[]) * @see ResolvableType#forClassWithGenerics(Class, Class[])
*/ */
public static <T> ResponseExtractor<Mono<ResponseEntity<Flux<T>>>> responseStream( public static <T> ResponseExtractor<Mono<ResponseEntity<Flux<T>>>> responseStream(
@ -123,7 +123,7 @@ public class ResponseExtractors {
/** /**
* Extract the full response body as a {@code ResponseEntity} with its body decoded as * Extract the full response body as a {@code ResponseEntity} with its body decoded as
* a {@code Flux<T>} * a {@code Flux<T>}.
*/ */
public static <T> ResponseExtractor<Mono<ResponseEntity<Flux<T>>>> responseStream( public static <T> ResponseExtractor<Mono<ResponseEntity<Flux<T>>>> responseStream(
Class<T> sourceClass) { Class<T> sourceClass) {
@ -132,7 +132,7 @@ public class ResponseExtractors {
} }
/** /**
* Extract the response headers as an {@code HttpHeaders} instance * Extract the response headers as an {@code HttpHeaders} instance.
*/ */
public static ResponseExtractor<Mono<HttpHeaders>> headers() { public static ResponseExtractor<Mono<HttpHeaders>> headers() {
return (clientResponse, messageConverters) -> clientResponse.map(resp -> resp.getHeaders()); return (clientResponse, messageConverters) -> clientResponse.map(resp -> resp.getHeaders());
@ -160,4 +160,5 @@ public class ResponseExtractors {
return messageConverters.stream().filter(e -> e.canRead(type, mediaType)) return messageConverters.stream().filter(e -> e.canRead(type, mediaType))
.findFirst(); .findFirst();
} }
}
}

View File

@ -36,14 +36,15 @@ import rx.Single;
/** /**
* Static factory methods for {@link ResponseExtractor} * Static factory methods for {@link ResponseExtractor}
* based on the {@link Observable} and {@link Single} API. * based on the {@link Observable} and {@link Single} APIs.
* *
* @author Brian Clozel * @author Brian Clozel
* @since 5.0
*/ */
public class RxJava1ResponseExtractors { public class RxJava1ResponseExtractors {
/** /**
* Extract the response body and decode it, returning it as a {@code Single<T>} * Extract the response body and decode it, returning it as a {@code Single<T>}.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> ResponseExtractor<Single<T>> body(Class<T> sourceClass) { public static <T> ResponseExtractor<Single<T>> body(Class<T> sourceClass) {
@ -55,7 +56,7 @@ public class RxJava1ResponseExtractors {
} }
/** /**
* Extract the response body and decode it, returning it as an {@code Observable<T>} * Extract the response body and decode it, returning it as an {@code Observable<T>}.
*/ */
public static <T> ResponseExtractor<Observable<T>> bodyStream(Class<T> sourceClass) { public static <T> ResponseExtractor<Observable<T>> bodyStream(Class<T> sourceClass) {
@ -67,7 +68,7 @@ public class RxJava1ResponseExtractors {
/** /**
* Extract the full response body as a {@code ResponseEntity} * Extract the full response body as a {@code ResponseEntity}
* with its body decoded as a single type {@code T} * with its body decoded as a single type {@code T}.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> ResponseExtractor<Single<ResponseEntity<T>>> response(Class<T> sourceClass) { public static <T> ResponseExtractor<Single<ResponseEntity<T>>> response(Class<T> sourceClass) {
@ -86,7 +87,7 @@ public class RxJava1ResponseExtractors {
/** /**
* Extract the full response body as a {@code ResponseEntity} * Extract the full response body as a {@code ResponseEntity}
* with its body decoded as an {@code Observable<T>} * with its body decoded as an {@code Observable<T>}.
*/ */
public static <T> ResponseExtractor<Single<ResponseEntity<Observable<T>>>> responseStream(Class<T> sourceClass) { public static <T> ResponseExtractor<Single<ResponseEntity<Observable<T>>>> responseStream(Class<T> sourceClass) {
ResolvableType resolvableType = ResolvableType.forClass(sourceClass); ResolvableType resolvableType = ResolvableType.forClass(sourceClass);
@ -99,7 +100,7 @@ public class RxJava1ResponseExtractors {
} }
/** /**
* Extract the response headers as an {@code HttpHeaders} instance * Extract the response headers as an {@code HttpHeaders} instance.
*/ */
public static ResponseExtractor<Single<HttpHeaders>> headers() { public static ResponseExtractor<Single<HttpHeaders>> headers() {
return (clientResponse, messageConverters) -> RxJava1SingleConverter return (clientResponse, messageConverters) -> RxJava1SingleConverter
@ -124,4 +125,5 @@ public class RxJava1ResponseExtractors {
ResolvableType type, MediaType mediaType) { ResolvableType type, MediaType mediaType) {
return messageConverters.stream().filter(e -> e.canRead(type, mediaType)).findFirst(); return messageConverters.stream().filter(e -> e.canRead(type, mediaType)).findFirst();
} }
}
}