Search in sources :

Example 6 with OkClient

use of retrofit.client.OkClient in project halyard by spinnaker.

the class RetrofitConfig method okClient.

@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
OkClient okClient() {
    OkHttpClient client = okHttpClientConfig.create();
    client.setConnectionPool(new ConnectionPool(maxIdleConnections, keepAliveDurationMs));
    client.setRetryOnConnectionFailure(retryOnConnectionFailure);
    return new OkClient(client);
}
Also used : ConnectionPool(com.squareup.okhttp.ConnectionPool) OkHttpClient(com.squareup.okhttp.OkHttpClient) OkClient(retrofit.client.OkClient) Scope(org.springframework.context.annotation.Scope) Bean(org.springframework.context.annotation.Bean)

Example 7 with OkClient

use of retrofit.client.OkClient in project steps by linroid.

the class WeatherApp method initWeatherService.

private void initWeatherService() {
    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(Config.ENDPOINT).setClient(new OkClient(new OkHttpClient())).setLogLevel(RestAdapter.LogLevel.BASIC).setErrorHandler(new ErrorHandler() {

        @Override
        public Throwable handleError(RetrofitError retrofitError) {
            Timber.e(retrofitError, "访问 %s 出错", retrofitError.getUrl());
            return retrofitError;
        }
    }).setRequestInterceptor(new RequestInterceptor() {

        @Override
        public void intercept(RequestFacade requestFacade) {
            requestFacade.addQueryParam("ak", Config.BAIDU_AK);
            requestFacade.addEncodedQueryParam("mcode", Config.M_CODE);
            requestFacade.addQueryParam("output", "json");
        }
    }).build();
    weatherService = restAdapter.create(WeatherService.class);
}
Also used : ErrorHandler(retrofit.ErrorHandler) OkHttpClient(com.squareup.okhttp.OkHttpClient) OkClient(retrofit.client.OkClient) WeatherService(com.linroid.weather.data.WeatherService) RequestInterceptor(retrofit.RequestInterceptor) RestAdapter(retrofit.RestAdapter) RetrofitError(retrofit.RetrofitError)

Example 8 with OkClient

use of retrofit.client.OkClient in project divide by HiddenStage.

the class AbstractWebManager method createRestAdapter.

private RestAdapter createRestAdapter(Config config) {
    RestAdapter.Builder builder = new RestAdapter.Builder();
    builder.setClient(new OkClient(config.client)).setEndpoint(config.serverUrl).setLogLevel(RestAdapter.LogLevel.FULL).setLog(new RestAdapter.Log() {

        @Override
        public void log(String s) {
            retrologger.debug(s);
        }
    }).setConverter(new GsonConverter(new Gson())).setRequestInterceptor(new RequestInterceptor() {

        @Override
        public void intercept(RequestFacade requestFacade) {
            onRequest(requestFacade);
        }
    }).setProfiler(new Profiler() {

        @Override
        public Object beforeCall() {
            return null;
        }

        @Override
        public void afterCall(RequestInformation requestInformation, long l, int i, Object o) {
            retrologger.error("afterCall(" + requestInformation.getRelativePath() + ":" + requestInformation.getMethod() + ": " + i + " : " + o);
            requestEventPublisher.onNext(new RequestObject(requestInformation, l, i, o));
        }
    });
    return builder.build();
}
Also used : GsonConverter(retrofit.converter.GsonConverter) OkClient(retrofit.client.OkClient) Gson(com.google.gson.Gson) RequestInterceptor(retrofit.RequestInterceptor) RequestFacade(retrofit.RequestInterceptor.RequestFacade) Profiler(retrofit.Profiler) RestAdapter(retrofit.RestAdapter)

Example 9 with OkClient

use of retrofit.client.OkClient in project divide by HiddenStage.

the class AuthServerHelper method buildTestService.

private TestService buildTestService(String url) {
    if (testService == null) {
        RestAdapter restAdapter = new RestAdapter.Builder().setClient(new OkClient()).setEndpoint(url).setLogLevel(RestAdapter.LogLevel.FULL).setLog(new RestAdapter.Log() {

            @Override
            public void log(String s) {
                System.out.println(s);
            }
        }).build();
        testService = restAdapter.create(TestService.class);
    }
    return testService;
}
Also used : OkClient(retrofit.client.OkClient) RestAdapter(retrofit.RestAdapter)

Aggregations

OkClient (retrofit.client.OkClient)9 OkHttpClient (com.squareup.okhttp.OkHttpClient)7 RestAdapter (retrofit.RestAdapter)7 RequestInterceptor (retrofit.RequestInterceptor)4 GsonConverter (retrofit.converter.GsonConverter)3 Cache (com.squareup.okhttp.Cache)2 Provides (dagger.Provides)2 Singleton (javax.inject.Singleton)2 Gson (com.google.gson.Gson)1 WeatherService (com.linroid.weather.data.WeatherService)1 PreferencesUtility (com.naman14.timber.utils.PreferencesUtility)1 ConnectionPool (com.squareup.okhttp.ConnectionPool)1 Interceptor (com.squareup.okhttp.Interceptor)1 Request (com.squareup.okhttp.Request)1 ClientService (com.tevinjeffrey.rmp.client.ClientService)1 RMPClient (com.tevinjeffrey.rmp.client.RMPClient)1 Bean (org.springframework.context.annotation.Bean)1 Scope (org.springframework.context.annotation.Scope)1 ErrorHandler (retrofit.ErrorHandler)1 Profiler (retrofit.Profiler)1