mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2024-11-26 13:16:46 +00:00
1.9 KiB
1.9 KiB
Jersey Server
Register RxJerseyServerFeature
in resourceConfig
resourceConfig.register(RxJerseyServerFeature.class);
Or with configuration
RxJerseyServerFeature rxJerseyServerFeature = new RxJerseyServerFeature()
.register(AuthInterceptor.class);
resourceConfig.register(rxJerseyServerFeature);
Update your resource adding rx return type:
@Path("/")
public class HelloResource {
@GET
public Single<HelloEntity> getAsync() {
return Single.just(new HelloEntity());
}
public static class HelloEntity {
public String hello = "world";
}
}
Inteceptor
You can use RxJava enabled interceptors. Result of such interceptor will be ignored. Thrown or returned error would be redirected to jersey.
RxJava
public class SimpleInterceptor implements ObservableRequestInterceptor<Void> {
public Observable<Void> intercept(ContainerRequestContext requestContext) {
return Observable.empty();
}
}
RxJava 2
public class SimpleInterceptor implements CompletableRequestInterceptor {
public Completable intercept(ContainerRequestContext requestContext) {
return Observable.complete();
}
}
Important notes
RxJava
- It's recommended to use
rx.Single
as return type (Representing single response entity). - Multiple elements emitted in
Observable
will be treated as error. - Empty
Observable
ornull
value inObservable
orSingle
will be treated as204: No content
. Completable
will be executed and204: No content
will be returned.
RxJava 2
- It's recommended to use
io.reactivex.Maybe
which could be 0 or 1 item or an error. - Multiple elements emitted in
Observable
orFlowable
will be treated as error. - Empty
Observable
/Maybe
will be treated as204: No content
. Completable
will be executed and204: No content
will be returned.