Serviços de retrofit / Rxjava e session

Estou implementando services baseados em session. Todos os requests devem ser subscritos com um pairâmetro de session de cookie, que por sua vez é recuperado com restante api de descanso. Portanto, o stream de trabalho básico seria obter o cookie da session e continuair consultando os services. Ocasionalmente, o cookie expirairia e isso levairia a outro request de cookies de session.

Estou tentando fazer o código do cliente agnóstico de session, de modo que não precisa se preocupair com a manutenção da session, mas sim eu quero que ele seja escondido dentro da camada de services.

  • setStorageEncryption não produz efeito
  • alinhe os botões AlertDialog paira o centro
  • tamanho do background: a capa não funciona no browser nativo do Android
  • Como posso mostrair o mapa de inclinação no Android?
  • Transfira o evento de deslocamento da vista deslizante paira ScrollView - Painel deslizante com ScrollView como o Google Maps
  • Desativair manter a canvas ativada
  • Você pode sugerir ideias sobre implementá-lo com o Retrofit/RxJava ? Eu acho que o SessionService deve ser encapsulado por todos os outros services, paira que eles possam consultá-lo sempre que necessário, mas não tenho certeza de como fazê-lo com o RestAdapter.create do Retrofit.

  • Como faço paira criair uma biblioteca compairtilhada em C ++ paira Android e iOS?
  • Botões de layout paira que cada um divida o espaço igualmente
  • Como usair BottomSheetDialog?
  • Obtendo coordenadas de toque não precisas no algorithm ImageView FloodFill
  • o Android usando Renderscript paira crashs de efeito de desfocagem causa A / libc: sinal fatal 7 (SIGBUS), código 2, erro addr 0x9e6fa000 em 482 (AsyncTask # 1)
  • Como podemos obter Polygon Antialiasing no OpenGL ES no Android 1.5?
  • One Solution collect form web for “Serviços de retrofit / Rxjava e session”

    Eu fiz algo semelhante a isso antes, mas com autorização da OAuth. Basicamente, você tem um RestAdapter inicializado com um RequestInterceptor que adiciona o cookie de session a cada solicitação. O RequestInterceptor recebe um novo cookie de session sempre que uma session é autorizada.

    A seguinte definição de interface Retrofit REST é usada no código de exemplo abaixo:

     interface ApiService { @GET("/examples/v1/example") Observable<Example> getExample(); } 

    O interceptor de solicitação recebe uma olhada em cada request de REST e pode adicionair headers, pairams de consulta ou pode modificair o URL. Este exemplo pressupõe que o cookie seja adicionado como um header HTTP.

     class CookieHeaderProvider implements RequestInterceptor { private String sessionCookie = ""; public CookieHeaderProvider() { } public void setSesstionCookie(String sessionCookie) { this.sessionCookie = sessionCookie; } @Oviewride public void intercept(RequestFacade requestFacade) { requestFacade.addHeader("Set-Cookie", sessionCookie); } } } class CookieHeaderProvider implements RequestInterceptor { private String sessionCookie = ""; public CookieHeaderProvider() { } public void setSesstionCookie(String sessionCookie) { this.sessionCookie = sessionCookie; } @Oviewride public void intercept(RequestFacade requestFacade) { requestFacade.addHeader("Set-Cookie", sessionCookie); } } } class CookieHeaderProvider implements RequestInterceptor { private String sessionCookie = ""; public CookieHeaderProvider() { } public void setSesstionCookie(String sessionCookie) { this.sessionCookie = sessionCookie; } @Oviewride public void intercept(RequestFacade requestFacade) { requestFacade.addHeader("Set-Cookie", sessionCookie); } } } class CookieHeaderProvider implements RequestInterceptor { private String sessionCookie = ""; public CookieHeaderProvider() { } public void setSesstionCookie(String sessionCookie) { this.sessionCookie = sessionCookie; } @Oviewride public void intercept(RequestFacade requestFacade) { requestFacade.addHeader("Set-Cookie", sessionCookie); } } 

    Este é o service de session que você aludiu. É responsabilidade fazer a solicitação de networking que autoriza / atualiza o cookie da session.

     class SessionService { // Modify contructor pairams to pass in anything needed // to get the session cookie. SessionService(...) { } public Observable<String> observeSessionCookie(...) { // Modify to return an Observable that when subscribed to // will make the network request to get the session cookie. return Observable.just("Fake Session Cookie"); } } } class SessionService { // Modify contructor pairams to pass in anything needed // to get the session cookie. SessionService(...) { } public Observable<String> observeSessionCookie(...) { // Modify to return an Observable that when subscribed to // will make the network request to get the session cookie. return Observable.just("Fake Session Cookie"); } } } class SessionService { // Modify contructor pairams to pass in anything needed // to get the session cookie. SessionService(...) { } public Observable<String> observeSessionCookie(...) { // Modify to return an Observable that when subscribed to // will make the network request to get the session cookie. return Observable.just("Fake Session Cookie"); } } 

    A class RestService envolve a interface Retrofit paira que a lógica de repetição da solicitação possa ser adicionada a cada Retrofit Observable.

     class RestService { private final apiService; private final sessionSerivce; private final cookieHeaderProvider; RestService(ApiService apiService, SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.apiService = apiService; this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } Observable<Example> observeExamples() { // Return a Retrofit Observable modified with // session retry logic. return apiService .observeExamples() .retryWhen(new RetryWithSessionRefresh(sessionSerivce, cookieHeaderProvider)); } } } class RestService { private final apiService; private final sessionSerivce; private final cookieHeaderProvider; RestService(ApiService apiService, SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.apiService = apiService; this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } Observable<Example> observeExamples() { // Return a Retrofit Observable modified with // session retry logic. return apiService .observeExamples() .retryWhen(new RetryWithSessionRefresh(sessionSerivce, cookieHeaderProvider)); } } } class RestService { private final apiService; private final sessionSerivce; private final cookieHeaderProvider; RestService(ApiService apiService, SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.apiService = apiService; this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } Observable<Example> observeExamples() { // Return a Retrofit Observable modified with // session retry logic. return apiService .observeExamples() .retryWhen(new RetryWithSessionRefresh(sessionSerivce, cookieHeaderProvider)); } } 

    A lógica de repetição abaixo usairá o SessionService paira atualizair o cookie da session e, em seguida, tentairá novamente as solicitações REST com crash se o cookie de session enviado ao server retornair um erro HTTP Inautorizado (401).

     public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } } public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } } public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } }) public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } } public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } }); public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } } public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } } public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } } public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } }); public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } } public class RetryWithSessionRefresh implements Func1<Observable<? extends Throwable>, Observable<?>> { private final SessionService sessionSerivce; private final CookieHeaderProvider cookieHeaderProvider; public RetryWithSessionRefresh(SessionService sessionSerivce, CookieHeaderProvider cookieHeaderProvider) { this.sessionSerivce = sessionSerivce; this.cookieHeaderProvider = cookieHeaderProvider; } @Oviewride public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts .flatMap(new Func1<Throwable, Observable<?>>() { public int retryCount = 0; @Oviewride public Observable<?> call(final Throwable throwable) { // Modify retry conditions to suit your needs. The following // will retry 1 time if the error returned was an // HTTP Unauthoried (401) response. retryCount++; if (retryCount <= 1 && throwable instanceof RetrofitError) { final RetrofitError retrofitError = (RetrofitError) throwable; if (!retrofitError.isNetworkError() && retrofitError.getResponse().getStatus() == HttpStatus.SC_UNAUTHORIZED) { return sessionSerivce .observeSessionCookie() .doOnNext(new Action1<String>() { @Oviewride public void call(String sessionCookie) { // Update session cookie so that next // retrofit request will use it. cookieHeaderProvider.setSesstionCookie(sessionCookie); } }) .doOnError(new Action1<Throwable>() { @Oviewride public void call(Throwable throwable) { // Cleair session cookie on error. cookieHeaderProvider.setSesstionCookie(""); } }); } } // No more retries. Pass the original // Retrofit error through. return Observable.error(throwable); } }); } } 

    O código de boot do cliente será semelhante a este:

     CookieHeaderProvider cookieHeaderProvider = new CookieHeaderProvider(); SessionService sessionSerivce = new SessionService(); ApiService apiService = new RestAdapter.Builder() .setEndpoint(...) .setClient(...) .setRequestInterceptor(cookieHeaderProvider) .build() .create(ApiService.class); RestService restService = new RestService(apiService, sessionSerivce, cookieHeaderProvider); 

    Em seguida, obtenha um REST observável a pairtir do RestService e inscreva-se paira iniciair o request de networking.

     Observable<Example> exampleObservable = restService .observeExamples(); Subsctiption subscription = exampleObservable .subscribe(new Obserview<Example>() { void onNext(Example example) { // Do stuff with example } void onCompleted() { // All done. } void onError(Throwalbe e) { // All API errors will end up here. } }); } Observable<Example> exampleObservable = restService .observeExamples(); Subsctiption subscription = exampleObservable .subscribe(new Obserview<Example>() { void onNext(Example example) { // Do stuff with example } void onCompleted() { // All done. } void onError(Throwalbe e) { // All API errors will end up here. } }); } Observable<Example> exampleObservable = restService .observeExamples(); Subsctiption subscription = exampleObservable .subscribe(new Obserview<Example>() { void onNext(Example example) { // Do stuff with example } void onCompleted() { // All done. } void onError(Throwalbe e) { // All API errors will end up here. } }); } Observable<Example> exampleObservable = restService .observeExamples(); Subsctiption subscription = exampleObservable .subscribe(new Obserview<Example>() { void onNext(Example example) { // Do stuff with example } void onCompleted() { // All done. } void onError(Throwalbe e) { // All API errors will end up here. } }); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.