当前位置: 首页>>代码示例>>Java>>正文


Java HttpLoggingInterceptor类代码示例

本文整理汇总了Java中com.squareup.okhttp.logging.HttpLoggingInterceptor的典型用法代码示例。如果您正苦于以下问题:Java HttpLoggingInterceptor类的具体用法?Java HttpLoggingInterceptor怎么用?Java HttpLoggingInterceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpLoggingInterceptor类属于com.squareup.okhttp.logging包,在下文中一共展示了HttpLoggingInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newVineyardService

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public static AndroidTvBoilerplateService newVineyardService() {
    OkHttpClient client = new OkHttpClient();
    client.interceptors().add(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            Response response = chain.proceed(chain.request());
            // Catch unauthorised error
            return response;
        }
    });

    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    client.interceptors().add(interceptor);

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(AndroidTvBoilerplateService.ENDPOINT)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
    return retrofit.create(AndroidTvBoilerplateService.class);
}
 
开发者ID:hitherejoe,项目名称:AndroidTvBoilerplate,代码行数:24,代码来源:AndroidTvBoilerplateService.java

示例2: RestClient

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
/**
 * return Retrofit
 */
public Retrofit RestClient() {
  HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
  if (isDebug()) {
    logging.setLevel(logLevel());
  } else {
    logging.setLevel(Level.NONE);
  }

  OkHttpClient client = new OkHttpClient();
  client.interceptors().add(logging);
  client.interceptors().addAll(getInterceptors());

  return new Retrofit.Builder().baseUrl(baseURL())
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .addConverterFactory(getFactory())
      .client(client)
      .build();
}
 
开发者ID:PoePoeMyintSwe,项目名称:BaseWrapper,代码行数:22,代码来源:RestClient.java

示例3: provideRetrofit

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
@Provides
@PerApplication
Retrofit provideRetrofit() {
    String endpointUrl = BuildConfig.apiEndpointUrl;
    Gson gson = new GsonBuilder()
            .setDateFormat(API_DATE_FORMAT)
            .setFieldNamingPolicy(API_JSON_NAMING_POLICY)
            .registerTypeAdapter(ResponseWrapper.class, new ResponseDeserializer())
            .addSerializationExclusionStrategy(new JsonExclusionStrategy())
            .addDeserializationExclusionStrategy(new JsonExclusionStrategy())
            .create();
    GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
    OkHttpClient client = new OkHttpClient();
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    client.interceptors().add(logging);
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(endpointUrl)
            .client(client)
            .addConverterFactory(gsonConverterFactory)
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
    return retrofit;
}
 
开发者ID:macoscope,项目名称:RoomBookerMVP,代码行数:25,代码来源:NetworkModule.java

示例4: createService

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public static <S> S createService(Class<S> serviceClass) {

        //logging retrofit
        final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        final OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.setConnectTimeout(TIMEOUT, TimeUnit.SECONDS);
        okHttpClient.setReadTimeout(TIMEOUT, TimeUnit.SECONDS);
        okHttpClient.setWriteTimeout(TIMEOUT, TimeUnit.SECONDS);
        okHttpClient.interceptors().add(interceptor);

        final Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(okHttpClient)
                .build();

        return retrofit.create(serviceClass);
    }
 
开发者ID:EspecializacaoMobileIFSP,项目名称:Mensageiro,代码行数:21,代码来源:BaseNetworkConfig.java

示例5: APIClient

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
APIClient() {
    OkHttpClient client = new OkHttpClient();
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    client.interceptors().add(logging);
    client.setConnectTimeout(10, TimeUnit.SECONDS);
    client.setReadTimeout(10, TimeUnit.SECONDS);
    client.setWriteTimeout(10, TimeUnit.SECONDS);
    Retrofit retrofit = new Retrofit.Builder()
            .client(client)
            .baseUrl("http://gank.avosapps.com/api/")
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    service = retrofit.create(MeizhiService.class);
}
 
开发者ID:Alluretears,项目名称:ImageLoaders,代码行数:17,代码来源:APIClient.java

示例6: openConnection

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
/**
 * Opens a connection to the server over websocket
 *
 * @param isReconnect whether this is a re-connect attempt or not
 */
public void openConnection(final boolean isReconnect) {

    if (isReconnect) {
        if (isConnected()) {
            connect(mSessionID);
            return;
        }
    }

    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(1, TimeUnit.MINUTES);
    client.setReadTimeout(1, TimeUnit.MINUTES);
    client.setWriteTimeout(1, TimeUnit.MINUTES);
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
    client.networkInterceptors().add(loggingInterceptor);

    Request request = new Request.Builder()
            .url(mServerUri)
            .build();
    WebSocketCall.create(client, request).enqueue(mWebSocketObserver);
}
 
开发者ID:lukamarin,项目名称:Rocket.Chat-android,代码行数:28,代码来源:Meteor.java

示例7: CreateNsMethods

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
private INsRestApi CreateNsMethods(String baseUrl) {
    Retrofit retrofit;

    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();  
    // set your desired log level
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient httpClient = new OkHttpClient();  
    // add your other interceptors ...

    // add logging as last interceptor
    httpClient.interceptors().add(logging);  // <-- this is the important line for logging

    Gson gson = new GsonBuilder().create();
    retrofit = new Retrofit.Builder()
    .baseUrl(baseUrl)
    .addConverterFactory(GsonConverterFactory.create(gson))
    .client(httpClient)
    .build();

    return retrofit.create(INsRestApi.class);
}
 
开发者ID:StephenBlackWasAlreadyTaken,项目名称:xDrip-Experimental,代码行数:23,代码来源:NsRestApiReader.java

示例8: instance

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public static BibleGatewayService instance(@NonNull Context context) {
    if (sService == null) {
        final Cache cache = new Cache(new File(context.getCacheDir(), HTTP_CACHE_FILE_NAME),
                HTTP_CACHE_SIZE);

        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        final OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.setConnectTimeout(30, TimeUnit.SECONDS);
        okHttpClient.setReadTimeout(30, TimeUnit.SECONDS);
        okHttpClient.setCache(cache);
        okHttpClient.interceptors().add(interceptor);

        Retrofit retrofit = new Retrofit.Builder().
                baseUrl(BibleGatewayService.API_BASE_URL).
                addConverterFactory(GsonConverterFactory.create()).
                addCallAdapterFactory(RxJavaCallAdapterFactory.create()).
                client(okHttpClient).
                build();

        sService = retrofit.create(BibleGatewayService.class);
    }
    return sService;
}
 
开发者ID:filipebezerra,项目名称:VerseOfTheDay,代码行数:26,代码来源:BibleGatewayApiController.java

示例9: newVineyardService

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public static VineyardService newVineyardService() {
    OkHttpClient client = new OkHttpClient();
    client.interceptors().add(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            Response response = chain.proceed(chain.request());
            // Catch unauthorised error
            return response;
        }
    });

    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    client.interceptors().add(interceptor);

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(VineyardService.ENDPOINT)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
    return retrofit.create(VineyardService.class);
}
 
开发者ID:hitherejoe,项目名称:Vineyard,代码行数:24,代码来源:VineyardService.java

示例10: connectToApi

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
private void connectToApi() {
    HttpLoggingInterceptor.Level logLevel = HttpLoggingInterceptor.Level.BODY;
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(logLevel);

    OkHttpClient okHttpClient = this.createClient();
    final Request request = new Request.Builder()
            .url(this.url)
            .addHeader(CONTENT_TYPE_LABEL, CONTENT_TYPE_VALUE_JSON)
            .get()
            .build();

    try {
        this.response = okHttpClient.newCall(request).execute().body().string();
    } catch (IOException e) {
        Log.e(this.getClass().getName(), "An error occured while trying to execute the HTTP call", e);
    }
}
 
开发者ID:feragusper,项目名称:BuenosAiresAntesYDespues,代码行数:19,代码来源:ApiConnection.java

示例11: SimWatchClient

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
private SimWatchClient(Configuration configuration) {
    OkHttpClient client = new OkHttpClient();
    if (configuration.isRequestLoggingEnabled()) {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(
                new HttpLoggingInterceptor.Logger() {
                    @Override
                    public void log(String message) {
                        LOG.info(message);
                    }
                });
        interceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
        client.interceptors().add(interceptor);
    }

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(configuration.getUrl())
            .client(client)
            .addConverterFactory(GsonConverterFactory.create(GsonUtil.getGson()))
            .build();
    backend = retrofit.create(BackendService.class);
}
 
开发者ID:WiReSEP,项目名称:SimWatch,代码行数:22,代码来源:SimWatchClient.java

示例12: providesOkHttpClient

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
@Provides
@Singleton
public OkHttpClient providesOkHttpClient(Context context) {
    OkHttpClient client = new OkHttpClient();
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
    client.interceptors().add(interceptor);
    client.networkInterceptors().add(new StethoInterceptor());
    File httpCacheDir = new File(context.getCacheDir() + "/okhttp");
    httpCacheDir.mkdirs();
    cleanDir(httpCacheDir);
    long httpCacheSize = 50 * 1024 * 1024; // 50 MiB
    Cache cache = new Cache(httpCacheDir, httpCacheSize);
    client.setCache(cache);
    return client;
}
 
开发者ID:tevjef,项目名称:Vapor,代码行数:17,代码来源:OkCloudAppModule.java

示例13: setDebugging

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
/**
 * Enable/disable debugging for this API client.
 *
 * @param debugging To enable (true) or disable (false) debugging
 * @return ApiClient
 */
public ApiClient setDebugging(boolean debugging) {
    if (debugging != this.debugging) {
        if (debugging) {
            loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(Level.BODY);
            httpClient.interceptors().add(loggingInterceptor);
        } else {
            httpClient.interceptors().remove(loggingInterceptor);
            loggingInterceptor = null;
        }
    }
    this.debugging = debugging;
    return this;
}
 
开发者ID:ina-foss,项目名称:afp-api-client,代码行数:21,代码来源:ApiClient.java

示例14: providesOkHttpClient

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
@Provides
@Singleton
public OkHttpClient providesOkHttpClient(Application application) {
    OkHttpClient client = new OkHttpClient();
    client.setCache(new Cache(application.getCacheDir(), CACHE_SIZE));

    HttpLoggingInterceptor logger = new HttpLoggingInterceptor();
    logger.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.HEADERS : HttpLoggingInterceptor.Level.NONE);
    client.interceptors().add(logger);

    return client;
}
 
开发者ID:asadmshah,项目名称:moviegur,代码行数:13,代码来源:NetworkModule.java

示例15: newTMDBService

import com.squareup.okhttp.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public static TMDBService newTMDBService(){
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient httpClient = new OkHttpClient();
    httpClient.interceptors().add(logging);

    Retrofit movieAPIRest = new Retrofit.Builder()
            .baseUrl(TMDBService.MOVIE_DB_HOST)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(httpClient)
            .build();

    return movieAPIRest.create(TMDBService.class);
}
 
开发者ID:lucastanziano,项目名称:Blockbuster,代码行数:16,代码来源:ServiceFactory.java


注:本文中的com.squareup.okhttp.logging.HttpLoggingInterceptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。