Search in sources :

Example 1 with AuthInterceptor

use of com.gpcoder.interceptor.AuthInterceptor in project Java-Tutorial by gpcodervn.

the class OkHttpClientWithInterceptorExample method main.

public static void main(String[] args) throws IOException {
    client = new OkHttpClient.Builder().addInterceptor(new LoggingInterceptor()).addInterceptor(new AuthInterceptor()).addNetworkInterceptor(new LoggingInterceptor()).build();
    createOrder();
    retrieveOrder();
    updateOrder();
    deleteOrder();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) LoggingInterceptor(com.gpcoder.interceptor.LoggingInterceptor) AuthInterceptor(com.gpcoder.interceptor.AuthInterceptor)

Example 2 with AuthInterceptor

use of com.gpcoder.interceptor.AuthInterceptor in project Java-Tutorial by gpcodervn.

the class FeignClientCreator method getService.

public static <T> T getService(Class<T> clazz) {
    okhttp3.OkHttpClient okHttpClient = new okhttp3.OkHttpClient.Builder().addInterceptor(new LoggingInterceptor()).addInterceptor(new AuthInterceptor()).addNetworkInterceptor(new LoggingInterceptor()).build();
    OkHttpClient feignOkHttp = new OkHttpClient(okHttpClient);
    return Feign.builder().client(feignOkHttp).encoder(new FormEncoder(new GsonEncoder())).decoder(new GsonDecoder()).logger(new Slf4jLogger(clazz)).errorDecoder(new MyErrorDecoder()).logLevel(Logger.Level.FULL).target(clazz, BASE_URL);
}
Also used : LoggingInterceptor(com.gpcoder.interceptor.LoggingInterceptor) OkHttpClient(feign.okhttp.OkHttpClient) GsonEncoder(feign.gson.GsonEncoder) MyErrorDecoder(com.gpcoder.handler.MyErrorDecoder) Slf4jLogger(feign.slf4j.Slf4jLogger) AuthInterceptor(com.gpcoder.interceptor.AuthInterceptor) GsonDecoder(feign.gson.GsonDecoder) FormEncoder(feign.form.FormEncoder)

Aggregations

AuthInterceptor (com.gpcoder.interceptor.AuthInterceptor)2 LoggingInterceptor (com.gpcoder.interceptor.LoggingInterceptor)2 MyErrorDecoder (com.gpcoder.handler.MyErrorDecoder)1 FormEncoder (feign.form.FormEncoder)1 GsonDecoder (feign.gson.GsonDecoder)1 GsonEncoder (feign.gson.GsonEncoder)1 OkHttpClient (feign.okhttp.OkHttpClient)1 Slf4jLogger (feign.slf4j.Slf4jLogger)1 OkHttpClient (okhttp3.OkHttpClient)1