Retrofit.Builder clonedRetrofitBuilder = retrofitBuilder.baseUrl(url).build().newBuilder(); this.retrofit = clonedRetrofitBuilder.client(clonedOkHttpBuilder.build()) .addConverterFactory(converterFactory).build();
/** * Replaces the input {@link AbstractBase} into this one. This method will create a new retrofit object in order to * correctly isolate this configuration. * <p /> * DON'T REMOVE FINAL KEYWORD, THIS METHOD IS USED IN A CONSTRUCTOR. * * @param base the base to replace */ protected final void replaceWith(AbstractBase<?> base) { // in order to have a retrofit instance and correctly isolate this configuration from the copied one, we build // retrofit OkHttpClient okhttp = base.okhttpBuilder.build(); retrofit = base.retrofitBuilder.callFactory(okhttp).build(); // get new builders // okhttp builder okhttpBuilder = okhttp.newBuilder(); // retrofit builder retrofitBuilder = retrofit.newBuilder(); // copy header interceptors headerInterceptors = new HashMap<>(); headerInterceptors.putAll(base.headerInterceptors); // copy header values headerValues = new HashMap<>(); headerValues.putAll(base.headerValues); }
private Observable<RTMConnectionServerResponse> fetchRTMServerFromRemote(final String routerHost, final String appId, final String installationId, int secure) { LOGGER.d("fetchRTMServerFromRemote. router=" + routerHost + ", appId=" + appId); Retrofit tmpRetrofit = retrofit.newBuilder().baseUrl(routerHost).build(); AppRouterService tmpService = tmpRetrofit.create(AppRouterService.class); Observable<RTMConnectionServerResponse> result = tmpService.getRTMConnectionServer(appId, installationId, secure); if (AppConfiguration.isAsynchronized()) { result = result.subscribeOn(Schedulers.io()); } AppConfiguration.SchedulerCreator creator = AppConfiguration.getDefaultScheduler(); if (null != creator) { result = result.observeOn(creator.create()); } return result.map(new Function<RTMConnectionServerResponse, RTMConnectionServerResponse>() { @Override public RTMConnectionServerResponse apply(RTMConnectionServerResponse rtmConnectionServerResponse) throws Exception { SystemSetting setting = AppConfiguration.getDefaultSetting(); if (null != rtmConnectionServerResponse && null != setting) { rtmConnectionServerResponse.setTtl(rtmConnectionServerResponse.getTtl() + System.currentTimeMillis() / 1000); String cacheResult = JSON.toJSONString(rtmConnectionServerResponse); setting.saveString(getPersistenceKeyZone(appId, false), routerHost, cacheResult); } return rtmConnectionServerResponse; } }); }
Retrofit.Builder clonedRetrofitBuilder = retrofitBuilder.baseUrl(url).build().newBuilder(); this.retrofit = clonedRetrofitBuilder.client(this.client) .addConverterFactory(converterFactory).build();