@@ -59,10 +59,12 @@ public abstract class EasyPostResource {
59
59
new ArrayList <>(Arrays .asList ("getCreatedAt" , "getUpdatedAt" , "getFees" ));
60
60
private static final int DEFAULT_CONNECT_TIMEOUT_MILLISECONDS = 30000 ;
61
61
private static final int DEFAULT_READ_TIMEOUT_MILLISECONDS = 60000 ;
62
- private static final double APP_ENGINE_DEFAULT_TIMEOUT_SECONDS = 20.0 ;
62
+ private static final double DEFAULT_APP_ENGINE_TIMEOUT_SECONDS = 20.0 ;
63
63
private static final String DNS_CACHE_TTL_PROPERTY_NAME = "networkaddress.cache.ttl" ;
64
- // Set this property to override your environment's default URLStreamHandler.
65
64
private static final String CUSTOM_URL_STREAM_HANDLER_PROPERTY_NAME = "com.easypost.net.customURLStreamHandler" ;
65
+ private static int connectTimeoutMilliseconds = DEFAULT_CONNECT_TIMEOUT_MILLISECONDS ;
66
+ private static int readTimeoutMilliseconds = DEFAULT_READ_TIMEOUT_MILLISECONDS ;
67
+ private static double appEngineTimeoutSeconds = DEFAULT_APP_ENGINE_TIMEOUT_SECONDS ;
66
68
private Date createdAt ;
67
69
private Date updatedAt ;
68
70
private ArrayList <Fee > fees ;
@@ -150,13 +152,13 @@ private static javax.net.ssl.HttpsURLConnection createEasyPostConnection(final S
150
152
easypostURL = new URL (url );
151
153
}
152
154
javax .net .ssl .HttpsURLConnection conn = (javax .net .ssl .HttpsURLConnection ) easypostURL .openConnection ();
153
- conn .setConnectTimeout (DEFAULT_CONNECT_TIMEOUT_MILLISECONDS );
155
+ conn .setConnectTimeout (getConnectTimeoutMilliseconds () );
154
156
155
157
int readTimeout ;
156
158
if (EasyPost .readTimeout != 0 ) {
157
159
readTimeout = EasyPost .readTimeout ;
158
160
} else {
159
- readTimeout = DEFAULT_READ_TIMEOUT_MILLISECONDS ;
161
+ readTimeout = getReadTimeoutMilliseconds () ;
160
162
}
161
163
conn .setReadTimeout (readTimeout );
162
164
@@ -470,7 +472,7 @@ private static EasyPostResponse makeAppEngineRequest(final RequestMethod method,
470
472
471
473
// Heroku times out after 30s, so leave some time for the API to return a response
472
474
fetchOptionsClass .getDeclaredMethod ("setDeadline" , java .lang .Double .class )
473
- .invoke (fetchOptions , APP_ENGINE_DEFAULT_TIMEOUT_SECONDS );
475
+ .invoke (fetchOptions , getAppEngineTimeoutSeconds () );
474
476
475
477
Class <?> requestClass = Class .forName ("com.google.appengine.api.urlfetch.HTTPRequest" );
476
478
@@ -525,6 +527,60 @@ private static EasyPostResponse makeAppEngineRequest(final RequestMethod method,
525
527
}
526
528
}
527
529
530
+ /**
531
+ * Get the timeout in milliseconds for connecting to the API.
532
+ *
533
+ * @return the timeout in milliseconds
534
+ */
535
+ public static int getConnectTimeoutMilliseconds () {
536
+ return connectTimeoutMilliseconds ;
537
+ }
538
+
539
+ /**
540
+ * Set the timeout in milliseconds for connecting to the API.
541
+ *
542
+ * @param milliseconds the timeout in milliseconds
543
+ */
544
+ public static void setConnectTimeoutMilliseconds (int milliseconds ) {
545
+ connectTimeoutMilliseconds = milliseconds ;
546
+ }
547
+
548
+ /**
549
+ * Get the timeout in milliseconds for reading API responses.
550
+ *
551
+ * @return the timeout in milliseconds
552
+ */
553
+ public static int getReadTimeoutMilliseconds () {
554
+ return readTimeoutMilliseconds ;
555
+ }
556
+
557
+ /**
558
+ * Set the timeout in milliseconds for reading API responses.
559
+ *
560
+ * @param milliseconds the timeout in milliseconds
561
+ */
562
+ public static void setReadTimeoutMilliseconds (int milliseconds ) {
563
+ readTimeoutMilliseconds = milliseconds ;
564
+ }
565
+
566
+ /**
567
+ * Get the timeout in milliseconds for App Engine API requests.
568
+ *
569
+ * @return the timeout in milliseconds
570
+ */
571
+ public static double getAppEngineTimeoutSeconds () {
572
+ return appEngineTimeoutSeconds ;
573
+ }
574
+
575
+ /**
576
+ * Set the timeout in seconds for App Engine API requests.
577
+ *
578
+ * @param seconds the timeout in seconds
579
+ */
580
+ public static void setAppEngineTimeoutSeconds (double seconds ) {
581
+ appEngineTimeoutSeconds = seconds ;
582
+ }
583
+
528
584
/**
529
585
* Returns a string representation of the object.
530
586
*/
@@ -703,7 +759,6 @@ protected enum RequestMethod {
703
759
PUT
704
760
}
705
761
706
- // represents Errors returned as JSON
707
762
private static class ErrorContainer {
708
763
private EasyPostResource .Error error ;
709
764
}
0 commit comments