Skip to content

Commit 13ecb75

Browse files
committed
fix cr
1 parent 76bcf57 commit 13ecb75

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

src/main/java/com/taboola/rest/api/RestAPIClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public static class RestAPIClientBuilder {
7575
private ExceptionFactory exceptionFactory;
7676
private ObjectMapper objectMapper;
7777
private final StringResponseFactories stringResponseFactories = new StringResponseFactories();
78-
private HttpLoggingInterceptor.Level loggingLevel;
78+
private HttpLoggingLevel loggingLevel;
7979

8080
public RestAPIClientBuilder setLoggingLevel(HttpLoggingLevel loggingLevel) {
81-
this.loggingLevel = HttpLoggingLevel.getHttpLoggingInterceptorLevel(loggingLevel);
81+
this.loggingLevel = loggingLevel;
8282
return this;
8383
}
8484

@@ -231,7 +231,7 @@ private void organizeState() {
231231
}
232232

233233
if (loggingLevel == null) {
234-
loggingLevel = HttpLoggingInterceptor.Level.BASIC;
234+
loggingLevel = HttpLoggingLevel.BASIC;
235235
}
236236
}
237237
}

src/main/java/com/taboola/rest/api/internal/CommunicationFactory.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55
import com.taboola.rest.api.internal.config.CommunicationConfig;
66
import com.taboola.rest.api.internal.interceptors.CommunicationInterceptor;
77
import com.taboola.rest.api.internal.interceptors.HeadersInterceptor;
8+
import com.taboola.rest.api.model.HttpLoggingLevel;
89

910
import okhttp3.ConnectionPool;
1011
import okhttp3.OkHttpClient;
1112
import okhttp3.logging.HttpLoggingInterceptor;
1213
import retrofit2.Retrofit;
1314
import retrofit2.converter.jackson.JacksonConverterFactory;
1415

16+
import org.apache.logging.log4j.LogManager;
17+
import org.apache.logging.log4j.Logger;
18+
1519
/**
1620
* Created by vladi
1721
* Date: 10/4/2017
1822
* Time: 10:54 PM
1923
* By Taboola
2024
*/
2125
public final class CommunicationFactory {
22-
26+
private static final Logger logger = LogManager.getLogger(CommunicationFactory.class);
2327
private final Retrofit retrofit;
2428

2529
public CommunicationFactory(CommunicationConfig communicationConfig) {
@@ -33,9 +37,9 @@ private HttpLoggingInterceptor createLoggingInterceptor(CommunicationConfig conf
3337
if (config.isDebug()) {
3438
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
3539
} else {
36-
loggingInterceptor.setLevel(config.getLoggingLevel());
40+
loggingInterceptor.setLevel(getHttpLoggingInterceptorLevel(config.getLoggingLevel()));
3741
}
38-
if (loggingInterceptor.getLevel() == HttpLoggingInterceptor.Level.BODY) {
42+
if (loggingInterceptor.getLevel() == HttpLoggingInterceptor.Level.BODY || loggingInterceptor.getLevel() == HttpLoggingInterceptor.Level.HEADERS) {
3943
loggingInterceptor.redactHeader("Authorization");
4044
loggingInterceptor.redactHeader("Cookie");
4145
}
@@ -62,6 +66,23 @@ private OkHttpClient createOkHttpClient(CommunicationConfig config) {
6266
.build();
6367
}
6468

69+
70+
public static HttpLoggingInterceptor.Level getHttpLoggingInterceptorLevel(HttpLoggingLevel httpLoggingLevel) {
71+
switch (httpLoggingLevel) {
72+
case NONE:
73+
return HttpLoggingInterceptor.Level.NONE;
74+
case BASIC:
75+
return HttpLoggingInterceptor.Level.BASIC;
76+
case HEADERS:
77+
return HttpLoggingInterceptor.Level.HEADERS;
78+
case BODY:
79+
return HttpLoggingInterceptor.Level.BODY;
80+
default:
81+
logger.error("Getting unknown HttpLoggingLevel [{}]", httpLoggingLevel.name());
82+
return HttpLoggingInterceptor.Level.BASIC;
83+
}
84+
}
85+
6586
public <E> E createRetrofitEndpoint(Class<E> clazz) {
6687
return retrofit.create(clazz);
6788
}

src/main/java/com/taboola/rest/api/internal/config/CommunicationConfig.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.taboola.rest.api.internal.config;
22

33

4-
import okhttp3.logging.HttpLoggingInterceptor;
5-
64
import java.util.Collection;
75

86
import com.fasterxml.jackson.databind.ObjectMapper;
97
import com.taboola.rest.api.exceptions.factories.ExceptionFactory;
108
import com.taboola.rest.api.internal.StringResponseFactories;
9+
import com.taboola.rest.api.model.HttpLoggingLevel;
1110
import com.taboola.rest.api.model.RequestHeader;
1211

1312
/**
@@ -29,12 +28,12 @@ public class CommunicationConfig {
2928
private final ExceptionFactory exceptionFactory;
3029
private final ObjectMapper objectMapper;
3130
private final StringResponseFactories stringResponseFactories;
32-
private final HttpLoggingInterceptor.Level loggingLevel;
31+
private final HttpLoggingLevel loggingLevel;
3332

3433
public CommunicationConfig(String baseUrl, Long connectionTimeoutMillis, Long readTimeoutMillis,
3534
Long writeTimeoutMillis, Integer maxIdleConnections, Long keepAliveDurationMillis,
3635
Collection<RequestHeader> headers, boolean debug, ExceptionFactory exceptionFactory,
37-
ObjectMapper objectMapper, StringResponseFactories stringResponseFactories, HttpLoggingInterceptor.Level loggingLevel) {
36+
ObjectMapper objectMapper, StringResponseFactories stringResponseFactories, HttpLoggingLevel loggingLevel) {
3837
this.baseUrl = baseUrl;
3938
this.connectionTimeoutMillis = connectionTimeoutMillis;
4039
this.readTimeoutMillis = readTimeoutMillis;
@@ -93,7 +92,7 @@ public StringResponseFactories getStringResponseFactories() {
9392
return stringResponseFactories;
9493
}
9594

96-
public HttpLoggingInterceptor.Level getLoggingLevel() {
95+
public HttpLoggingLevel getLoggingLevel() {
9796
return loggingLevel;
9897
}
9998

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
11
package com.taboola.rest.api.model;
22

3-
import okhttp3.logging.HttpLoggingInterceptor;
4-
5-
import org.apache.logging.log4j.LogManager;
6-
import org.apache.logging.log4j.Logger;
7-
83
public enum HttpLoggingLevel {
94

105
NONE,
116
BASIC,
127
HEADERS,
138
BODY;
14-
15-
private static final Logger logger = LogManager.getLogger(HttpLoggingLevel.class);
16-
17-
public static HttpLoggingInterceptor.Level getHttpLoggingInterceptorLevel(HttpLoggingLevel httpLoggingLevel) {
18-
switch (httpLoggingLevel) {
19-
case NONE:
20-
return HttpLoggingInterceptor.Level.NONE;
21-
case BASIC:
22-
return HttpLoggingInterceptor.Level.BASIC;
23-
case HEADERS:
24-
return HttpLoggingInterceptor.Level.HEADERS;
25-
case BODY:
26-
return HttpLoggingInterceptor.Level.BODY;
27-
default:
28-
logger.error("Getting unknown HttpLoggingLevel [{}]", httpLoggingLevel.name());
29-
return HttpLoggingInterceptor.Level.BASIC;
30-
}
31-
}
329
}

src/test/java/com/taboola/rest/api/internal/CommunicationFactoryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.taboola.rest.api.exceptions.factories.DefaultExceptionFactory;
1212
import com.taboola.rest.api.internal.config.CommunicationConfig;
1313
import com.taboola.rest.api.internal.config.UserAgentHeader;
14+
import com.taboola.rest.api.model.HttpLoggingLevel;
1415

1516
import okhttp3.logging.HttpLoggingInterceptor;
1617
import retrofit2.http.GET;
@@ -38,7 +39,7 @@ public void beforeTest() {
3839
CommunicationConfig communicationConfig = new CommunicationConfig("http://localhost",
3940
1L, 1L, 1L, 1, 60L,
4041
Collections.singleton(new UserAgentHeader("Dummy-Agent")),true, new DefaultExceptionFactory(),
41-
new ObjectMapper(), new StringResponseFactories(), HttpLoggingInterceptor.Level.BASIC);
42+
new ObjectMapper(), new StringResponseFactories(), HttpLoggingLevel.BASIC);
4243
testInstance = new CommunicationFactory(communicationConfig);
4344
}
4445

0 commit comments

Comments
 (0)