Skip to content

Commit 77295b9

Browse files
committed
java: Remove debug logic
1 parent 573397d commit 77295b9

File tree

1 file changed

+4
-90
lines changed

1 file changed

+4
-90
lines changed

java/lib/src/main/java/com/svix/SvixHttpClient.java

+4-90
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
88
import com.svix.exceptions.ApiException;
99

10-
import lombok.Getter;
11-
1210
import okhttp3.*;
1311

1412
import java.io.IOException;
1513
import java.util.List;
1614
import java.util.Map;
17-
import java.util.Objects;
1815
import java.util.concurrent.ThreadLocalRandom;
1916
import java.util.concurrent.locks.LockSupport;
2017

@@ -24,14 +21,12 @@ public class SvixHttpClient {
2421
private final List<Long> retrySchedule;
2522
private final OkHttpClient client;
2623
private final ObjectMapper objectMapper;
27-
private final boolean debug;
2824

2925
public SvixHttpClient(
3026
HttpUrl baseUrl, Map<String, String> defaultHeaders, List<Long> retrySchedule) {
3127
this.baseUrl = baseUrl;
3228
this.defaultHeaders = defaultHeaders;
3329
this.retrySchedule = retrySchedule;
34-
this.debug = Objects.equals(System.getenv("DEBUG"), "YES");
3530
this.client = new OkHttpClient();
3631

3732
ObjectMapper mapper = new ObjectMapper();
@@ -77,14 +72,13 @@ public <Req, Res> Res executeRequest(
7772
String.valueOf(ThreadLocalRandom.current().nextLong(0, Long.MAX_VALUE)));
7873

7974
Request request = reqBuilder.build();
80-
Result res = executeRequestWithRetry(request, jsonBody);
81-
Response response = res.getSecond();
75+
Response response = executeRequestWithRetry(request, jsonBody);
8276

8377
if (response.body() == null) {
8478
throw new ApiException("Body is null", response.code(), "");
8579
}
8680

87-
String bodyString = res.getFirst(); // response.body().string();
81+
String bodyString = response.body().string();
8882

8983
if (response.code() == 204) {
9084
return null;
@@ -98,10 +92,8 @@ public <Req, Res> Res executeRequest(
9892
"Non 200 status code: `" + response.code() + "`", response.code(), bodyString);
9993
}
10094

101-
private Result executeRequestWithRetry(Request request, String body) throws IOException {
102-
dbgReq(request, body);
95+
private Response executeRequestWithRetry(Request request, String body) throws IOException {
10396
Response response = client.newCall(request).execute();
104-
String resBody = dbgRes(response);
10597

10698
int retryCount = 0;
10799
while (response.code() >= 500 && retryCount < retrySchedule.size()) {
@@ -114,87 +106,9 @@ private Result executeRequestWithRetry(Request request, String body) throws IOEx
114106
request.newBuilder()
115107
.header("svix-retry-count", String.valueOf(retryCount + 1))
116108
.build();
117-
dbgReq(retryRequest, body);
118109
response = client.newCall(retryRequest).execute();
119-
resBody = dbgRes(response);
120110
retryCount++;
121111
}
122-
return new Result(resBody, response);
123-
}
124-
125-
private void dbgReq(Request request, String body) {
126-
StringBuilder dump = new StringBuilder();
127-
dump.append("--------- start req ---------\n");
128-
129-
// Request line
130-
dump.append(request.method()).append(" ").append(request.url().encodedPath());
131-
132-
// Add query parameters if present
133-
if (request.url().encodedQuery() != null) {
134-
dump.append("?").append(request.url().encodedQuery());
135-
}
136-
137-
dump.append(" HTTP/1.1\r\n");
138-
139-
// Headers
140-
Headers headers = request.headers();
141-
for (int i = 0; i < headers.size(); i++) {
142-
dump.append(headers.name(i)).append(": ").append(headers.value(i)).append("\r\n");
143-
}
144-
145-
// Empty line between headers and body
146-
dump.append("\r\n");
147-
148-
// Body
149-
dump.append(body);
150-
if (this.debug) {
151-
System.out.println(dump.toString());
152-
}
153-
}
154-
155-
private String dbgRes(Response response) throws IOException {
156-
StringBuilder dump = new StringBuilder();
157-
158-
// Status line with protocol and status code
159-
dump.append(response.protocol()) // Will show HTTP/1.1 【1】【2】
160-
.append(" ")
161-
.append(response.code())
162-
.append(" ")
163-
.append(response.message())
164-
.append("\r\n");
165-
166-
// Headers
167-
Headers headers = response.headers();
168-
for (int i = 0; i < headers.size(); i++) {
169-
dump.append(headers.name(i)).append(": ").append(headers.value(i)).append("\r\n");
170-
}
171-
172-
// Empty line between headers and body
173-
dump.append("\r\n");
174-
175-
// Body - note that response body can only be consumed once 【3】【2】
176-
ResponseBody body = response.body();
177-
String bodyString = "";
178-
if (body != null) {
179-
bodyString = body.string();
180-
dump.append(bodyString);
181-
}
182-
dump.append("\n--------- end req ---------");
183-
if (this.debug) {
184-
System.out.println(dump.toString());
185-
}
186-
return bodyString;
187-
}
188-
189-
@Getter
190-
static class Result {
191-
// Getters
192-
private final String first;
193-
private final Response second;
194-
195-
public Result(String first, Response second) {
196-
this.first = first;
197-
this.second = second;
198-
}
112+
return response;
199113
}
200114
}

0 commit comments

Comments
 (0)