1313import org .slf4j .LoggerFactory ;
1414
1515import java .net .URI ;
16+ import java .net .URLEncoder ;
1617import java .net .http .HttpClient ;
1718import java .net .http .HttpHeaders ;
1819import java .net .http .HttpRequest ;
1920import java .net .http .HttpResponse ;
21+ import java .nio .charset .StandardCharsets ;
2022import java .time .Duration ;
2123import java .util .List ;
2224import java .util .OptionalLong ;
25+ import java .util .stream .Collectors ;
2326
2427public 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 =
0 commit comments