Skip to content

Commit 57e4814

Browse files
authored
Merge pull request #23 from exceptionless/testing
Testing
2 parents c3e274a + 1965c12 commit 57e4814

File tree

11 files changed

+114
-17
lines changed

11 files changed

+114
-17
lines changed

pom.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.exceptionless</groupId>
88
<artifactId>exceptionless-client</artifactId>
9-
<version>1.0</version>
9+
<version>1.0-beta1</version>
1010

1111
<dependencies>
1212
<dependency>
@@ -34,6 +34,11 @@
3434
<artifactId>slf4j-api</artifactId>
3535
<version>1.7.30</version>
3636
</dependency>
37+
<dependency>
38+
<groupId>com.fasterxml.jackson.datatype</groupId>
39+
<artifactId>jackson-datatype-jsr310</artifactId>
40+
<version>2.10.0</version>
41+
</dependency>
3742
<!--Test Dependencies-->
3843
<dependency>
3944
<groupId>org.junit.jupiter</groupId>
@@ -79,6 +84,17 @@
7984
</annotationProcessorPaths>
8085
</configuration>
8186
</plugin>
87+
<!--2.22.0 is required for Junit 5 tests-->
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-surefire-plugin</artifactId>
91+
<version>2.22.0</version>
92+
<configuration>
93+
<argLine>
94+
--illegal-access=permit
95+
</argLine>
96+
</configuration>
97+
</plugin>
8298
</plugins>
8399
</build>
84100
</project>

samples/example-app/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.exceptionless</groupId>
88
<artifactId>example-app</artifactId>
9-
<version>1.0</version>
9+
<version>1.0-beta1</version>
1010

1111
<dependencies>
1212
<dependency>

src/main/java/com/exceptionless/exceptionlessclient/configuration/Configuration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public Configuration(
3838
updateSettingsWhenIdleInterval == null ? 12000L : updateSettingsWhenIdleInterval;
3939
this.submissionBatchSize = submissionBatchSize == null ? 50 : submissionBatchSize;
4040
this.submissionClientTimeoutInMillis =
41-
submissionClientTimeoutInMillis == null ? 100 : submissionClientTimeoutInMillis;
41+
submissionClientTimeoutInMillis == null ? 500 : submissionClientTimeoutInMillis;
4242
this.settingsClientTimeoutInMillis =
43-
settingsClientTimeoutInMillis == null ? 100 : settingsClientTimeoutInMillis;
43+
settingsClientTimeoutInMillis == null ? 500 : settingsClientTimeoutInMillis;
4444
this.propertyChangeSupport = new PropertyChangeSupport(this);
4545
}
4646

src/main/java/com/exceptionless/exceptionlessclient/settings/DefaultSettingsClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public SettingsResponse getSettings(long version) {
4242
HttpRequest.newBuilder()
4343
.uri(uri)
4444
.GET()
45-
.header("X-Exceptionless-Client", Configuration.USER_AGENT)
45+
.header("User-Agent", Configuration.USER_AGENT)
4646
.timeout(Duration.ofMillis(configuration.getSettingsClientTimeoutInMillis()))
4747
.build();
4848

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

Lines changed: 11 additions & 5 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) {
@@ -72,14 +75,17 @@ private SubmissionResponse postSubmission(String url, Object data) {
7275
.uri(uri)
7376
.POST(HttpRequest.BodyPublishers.ofString(requestJSON))
7477
.header("Content-Type", "application/json")
75-
.header("X-Exceptionless-Client", Configuration.USER_AGENT)
78+
.header("User-Agent", Configuration.USER_AGENT)
7679
.timeout(Duration.ofMillis(configuration.getSubmissionClientTimeoutInMillis()))
7780
.build();
7881

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+
}

src/main/java/com/exceptionless/exceptionlessclient/utils/Utils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.exceptionless.exceptionlessclient.utils;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.SerializationFeature;
5+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
46
import org.slf4j.Logger;
57
import org.slf4j.LoggerFactory;
68

@@ -9,7 +11,12 @@
911
import java.util.*;
1012

1113
public final class Utils {
12-
public static final ObjectMapper JSON_MAPPER = new ObjectMapper();
14+
public static final ObjectMapper JSON_MAPPER;
15+
static {
16+
JSON_MAPPER = new ObjectMapper();
17+
JSON_MAPPER.registerModule(new JavaTimeModule());
18+
JSON_MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
19+
}
1320

1421
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
1522

src/test/java/com/exceptionless/exceptionlessclient/settings/DefaultSettingsClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public void itCanHandleASuccessfulResponse() throws IOException, InterruptedExce
4848
httpRequest.method().equals("GET")
4949
&& httpRequest.timeout().isPresent()
5050
&& httpRequest.timeout().get().equals(Duration.ofMillis(10))
51-
&& httpRequest.headers().firstValue("X-Exceptionless-Client").isPresent()
51+
&& httpRequest.headers().firstValue("User-Agent").isPresent()
5252
&& httpRequest
5353
.headers()
54-
.firstValue("X-Exceptionless-Client")
54+
.firstValue("User-Agent")
5555
.get()
5656
.equals("exceptionless-java")
5757
&& httpRequest

0 commit comments

Comments
 (0)