|
@@ -3,12 +3,16 @@ package com.dragon.tj.portal.auth.config;
|
|
|
import com.alibaba.fastjson.support.retrofit.Retrofit2ConverterFactory;
|
|
|
import com.dragon.tj.portal.auth.client.DcucAuthClient;
|
|
|
import com.dragon.tj.portal.auth.client.DcucUserClient;
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
+import okhttp3.logging.HttpLoggingInterceptor;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import retrofit2.Retrofit;
|
|
|
import retrofit2.converter.jackson.JacksonConverterFactory;
|
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
@Configuration
|
|
|
public class RetrofitConfig {
|
|
|
@Value("${client.dcuc.user.url}")
|
|
@@ -17,9 +21,27 @@ public class RetrofitConfig {
|
|
|
@Value("${client.dcuc.auth.url}")
|
|
|
private String dcucAuthUrl;
|
|
|
|
|
|
+ @Value("${client.log.enabled:false}")
|
|
|
+ private boolean logEnabled;
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public OkHttpClient okHttpClient() {
|
|
|
+ HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
|
|
|
+ loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
|
|
+
|
|
|
+ OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(10, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(60, TimeUnit.SECONDS);
|
|
|
+ if (logEnabled) {
|
|
|
+ httpClientBuilder.addInterceptor(loggingInterceptor);
|
|
|
+ }
|
|
|
+ return httpClientBuilder.build();
|
|
|
+ }
|
|
|
+
|
|
|
@Bean
|
|
|
- public DcucUserClient dcucUserClient() {
|
|
|
+ public DcucUserClient dcucUserClient(OkHttpClient okHttpClient) {
|
|
|
Retrofit retrofit = new Retrofit.Builder()
|
|
|
+ .client(okHttpClient)
|
|
|
.baseUrl(dcucUserUrl)
|
|
|
.addConverterFactory(JacksonConverterFactory.create())
|
|
|
.build();
|
|
@@ -29,6 +51,7 @@ public class RetrofitConfig {
|
|
|
@Bean
|
|
|
public DcucAuthClient dcucAuthClient() {
|
|
|
Retrofit retrofit = new Retrofit.Builder()
|
|
|
+ .client(okHttpClient())
|
|
|
.baseUrl(dcucAuthUrl)
|
|
|
.addConverterFactory(Retrofit2ConverterFactory.create())
|
|
|
.build();
|