Skip to content

Commit 9957e5c

Browse files
committed
Fixed clients
1 parent d8ac801 commit 9957e5c

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

src/main/java/com/exceptionless/exceptionlessclient/submission/DefaultSubmissionClient.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
import org.slf4j.LoggerFactory;
1414

1515
import java.net.URI;
16+
import java.net.URLEncoder;
1617
import java.net.http.HttpClient;
1718
import java.net.http.HttpHeaders;
1819
import java.net.http.HttpRequest;
1920
import java.net.http.HttpResponse;
21+
import java.nio.charset.StandardCharsets;
2022
import java.time.Duration;
2123
import java.util.List;
2224
import java.util.OptionalLong;
25+
import java.util.stream.Collectors;
2326

2427
public class DefaultSubmissionClient implements SubmissionClientIF {
2528
private static final Logger LOG = LoggerFactory.getLogger(DefaultSubmissionClient.class);
@@ -50,7 +53,7 @@ public SubmissionResponse postEvents(List<Event> events) {
5053
String.format(
5154
"%s/api/v2/events?access_token=%s",
5255
configuration.getServerUrl(), configuration.getApiKey()),
53-
events);
56+
events.stream().map(SubmissionMapper::toRequest).collect(Collectors.toList()));
5457
}
5558

5659
@Override
@@ -59,7 +62,7 @@ public SubmissionResponse postUserDescription(String referenceId, UserDescriptio
5962
String.format(
6063
"%s/api/v2/events/by-ref/%s/user-description?access_token=%s",
6164
configuration.getServerUrl(), referenceId, configuration.getApiKey()),
62-
description);
65+
SubmissionMapper.toRequest(description));
6366
}
6467

6568
private SubmissionResponse postSubmission(String url, Object data) {
@@ -79,7 +82,10 @@ private SubmissionResponse postSubmission(String url, Object data) {
7982
HttpResponse<String> response =
8083
httpClient.send(request, HttpResponse.BodyHandlers.ofString());
8184

82-
updateSettingsFromHeaders(response.headers());
85+
if (response.statusCode() == 200) {
86+
updateSettingsFromHeaders(response.headers());
87+
}
88+
8389
return SubmissionResponse.builder()
8490
.statusCode(response.statusCode())
8591
.message(response.body())
@@ -106,7 +112,7 @@ public void sendHeartBeat(String sessionIdOrUserId, boolean closeSession) {
106112
String.format(
107113
"%s/api/v2/events/session/heartbeat?id=%s&close=%s&access_token=%s",
108114
configuration.getHeartbeatServerUrl(),
109-
sessionIdOrUserId,
115+
URLEncoder.encode(sessionIdOrUserId, StandardCharsets.UTF_8),
110116
closeSession,
111117
configuration.getApiKey()));
112118
HttpRequest request =
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.exceptionless.exceptionlessclient.submission;
2+
3+
import lombok.Builder;
4+
import lombok.Value;
5+
6+
import java.time.LocalDate;
7+
import java.util.Map;
8+
import java.util.Set;
9+
10+
@Value
11+
@Builder
12+
public class EventRequest {
13+
String type;
14+
String source;
15+
LocalDate date;
16+
Set<String> tags;
17+
String message;
18+
String geo;
19+
String referenceId;
20+
long value;
21+
Long count;
22+
Map<String, Object> data;
23+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.exceptionless.exceptionlessclient.submission;
2+
3+
import com.exceptionless.exceptionlessclient.models.Event;
4+
import com.exceptionless.exceptionlessclient.models.UserDescription;
5+
6+
public final class SubmissionMapper {
7+
private SubmissionMapper() {}
8+
9+
public static UserDescriptionRequest toRequest(UserDescription userDescription) {
10+
return UserDescriptionRequest.builder()
11+
.description(userDescription.getDescription())
12+
.emailAddress(userDescription.getEmailAddress())
13+
.data(userDescription.getData())
14+
.build();
15+
}
16+
17+
public static EventRequest toRequest(Event event) {
18+
return EventRequest.builder()
19+
.type(event.getType())
20+
.source(event.getSource())
21+
.date(event.getDate())
22+
.tags(event.getTags())
23+
.message(event.getMessage())
24+
.geo(event.getGeo())
25+
.referenceId(event.getReferenceId())
26+
.value(event.getValue())
27+
.count(event.getCount())
28+
.data(event.getData())
29+
.build();
30+
}
31+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.exceptionless.exceptionlessclient.submission;
2+
3+
import lombok.Builder;
4+
import lombok.Value;
5+
6+
import java.util.Map;
7+
8+
@Value
9+
@Builder
10+
public class UserDescriptionRequest {
11+
String emailAddress;
12+
String description;
13+
Map<String, Object> data;
14+
}

0 commit comments

Comments
 (0)