11package com .exceptionless .exceptionlessclient .submission ;
22
3- import com .exceptionless .exceptionlessclient .configuration .Configuration ;
3+ import com .exceptionless .exceptionlessclient .configuration .ValueProvider ;
44import com .exceptionless .exceptionlessclient .models .Event ;
55import com .exceptionless .exceptionlessclient .models .UserDescription ;
66import com .exceptionless .exceptionlessclient .settings .SettingsManager ;
@@ -21,35 +21,49 @@ public class DefaultSubmissionClient implements SubmissionClientIF {
2121 private static final String CONFIGURATION_VERSION_HEADER = "x-exceptionless-configversion" ;
2222 private static final String RATE_LIMITING_HEADER = "x-ratelimit-remaining" ;
2323
24- private final Configuration configuration ;
2524 private final SettingsManager settingsManager ;
26- private final OkHttpClient httpClient ;
25+ private final OkHttpClient defaultHttpClient ;
26+ private final ValueProvider <Integer > submissionClientTimeoutInMillis ;
27+ private final ValueProvider <String > serverUrl ;
28+ private final ValueProvider <String > apiKey ;
29+ private final ValueProvider <String > heartbeatServerUrl ;
2730
2831 @ Builder
29- public DefaultSubmissionClient (Configuration configuration , SettingsManager settingsManager ) {
30- this .configuration = configuration ;
31- this .settingsManager = settingsManager ;
32- this .httpClient =
33- new OkHttpClient ()
34- .newBuilder ()
35- .connectTimeout (Duration .ofMillis (configuration .getSubmissionClientTimeoutInMillis ()))
36- .build ();
32+ public DefaultSubmissionClient (
33+ SettingsManager settingsManager ,
34+ ValueProvider <Integer > submissionClientTimeoutInMillis ,
35+ ValueProvider <String > serverUrl ,
36+ ValueProvider <String > apiKey ,
37+ ValueProvider <String > heartbeatServerUrl ) {
38+ this (
39+ new OkHttpClient ().newBuilder ().build (),
40+ settingsManager ,
41+ submissionClientTimeoutInMillis ,
42+ serverUrl ,
43+ apiKey ,
44+ heartbeatServerUrl );
3745 }
3846
3947 @ VisibleForTesting
4048 DefaultSubmissionClient (
41- Configuration configuration , SettingsManager settingsManager , OkHttpClient httpClient ) {
42- this .configuration = configuration ;
49+ OkHttpClient defaultHttpClient ,
50+ SettingsManager settingsManager ,
51+ ValueProvider <Integer > submissionClientTimeoutInMillis ,
52+ ValueProvider <String > serverUrl ,
53+ ValueProvider <String > apiKey ,
54+ ValueProvider <String > heartbeatServerUrl ) {
4355 this .settingsManager = settingsManager ;
44- this .httpClient = httpClient ;
56+ this .defaultHttpClient = defaultHttpClient ;
57+ this .submissionClientTimeoutInMillis = submissionClientTimeoutInMillis ;
58+ this .serverUrl = serverUrl ;
59+ this .apiKey = apiKey ;
60+ this .heartbeatServerUrl = heartbeatServerUrl ;
4561 }
4662
4763 @ Override
4864 public SubmissionResponse postEvents (List <Event > events ) {
4965 return postSubmission (
50- String .format (
51- "%s/api/v2/events?access_token=%s" ,
52- configuration .getServerUrl (), configuration .getApiKey ()),
66+ String .format ("%s/api/v2/events?access_token=%s" , serverUrl .get (), apiKey .get ()),
5367 events .stream ().map (SubmissionMapper ::toRequest ).collect (Collectors .toList ()));
5468 }
5569
@@ -58,7 +72,7 @@ public SubmissionResponse postUserDescription(String referenceId, UserDescriptio
5872 return postSubmission (
5973 String .format (
6074 "%s/api/v2/events/by-ref/%s/user-description?access_token=%s" ,
61- configuration . getServerUrl (), referenceId , configuration . getApiKey ()),
75+ serverUrl . get (), referenceId , apiKey . get ()),
6276 SubmissionMapper .toRequest (description ));
6377 }
6478
@@ -71,7 +85,13 @@ private SubmissionResponse postSubmission(String url, Object data) {
7185 .post (RequestBody .create (requestJSON , MediaType .parse ("application/json" )))
7286 .build ();
7387
74- Response response = httpClient .newCall (request ).execute ();
88+ Response response =
89+ defaultHttpClient
90+ .newBuilder ()
91+ .connectTimeout (Duration .ofMillis (submissionClientTimeoutInMillis .get ()))
92+ .build ()
93+ .newCall (request )
94+ .execute ();
7595
7696 if (response .isSuccessful ()) {
7797 updateSettingsFromHeaders (response );
@@ -109,14 +129,20 @@ public void sendHeartBeat(String sessionIdOrUserId, boolean closeSession) {
109129 .url (
110130 String .format (
111131 "%s/api/v2/events/session/heartbeat?id=%s&close=%s&access_token=%s" ,
112- configuration . getHeartbeatServerUrl (),
132+ heartbeatServerUrl . get (),
113133 URLEncoder .encode (sessionIdOrUserId , StandardCharsets .UTF_8 ),
114134 closeSession ,
115- configuration . getApiKey ()))
135+ apiKey . get ()))
116136 .get ()
117137 .build ();
118138
119- Response response = httpClient .newCall (request ).execute ();
139+ Response response =
140+ defaultHttpClient
141+ .newBuilder ()
142+ .connectTimeout (Duration .ofMillis (submissionClientTimeoutInMillis .get ()))
143+ .build ()
144+ .newCall (request )
145+ .execute ();
120146
121147 if (!response .isSuccessful ()) {
122148 log .error (
0 commit comments