Skip to content

Commit 81ea962

Browse files
committed
New default timeouts and fix javadoc errors
Specific Rate Limit exceptions added ApiClient - updated connectionTimeout and readTimeout default to 180000 milliseconds (3 min). You can override and set as high as 5 min. Added missing comments to reduce the number of warning during build of JavaDocs
1 parent c1a47cc commit 81ea962

File tree

475 files changed

+48946
-1076
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

475 files changed

+48946
-1076
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<artifactId>xero-java</artifactId>
66
<packaging>jar</packaging>
77
<name>xero-java</name>
8-
<version>4.7.2</version>
8+
<version>4.8.0</version>
99
<url>https://github.com/XeroAPI/Xero-Java</url>
1010
<description>This is the official Java SDK for Xero API</description>
1111
<licenses>

src/main/java/com/xero/api/ApiClient.java

+53-4
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
import java.net.URL;
2929
import java.security.interfaces.RSAPublicKey;
3030

31-
31+
/**
32+
* ApiClient for managing global http client and object mapper
33+
*/
3234
public class ApiClient {
3335
private final String basePath;
3436
private final HttpRequestFactory httpRequestFactory;
3537
private final ObjectMapper objectMapper;
3638
private HttpTransport httpTransport = new NetHttpTransport();
37-
private int connectionTimeout = 20000;
38-
private int readTimeout = 20000;
39+
private int connectionTimeout = 180000;
40+
private int readTimeout = 180000;
3941

4042
private static final String defaultBasePath = "https://api.xero.com/api.xro/2.0";
4143

@@ -53,10 +55,18 @@ private static ObjectMapper createDefaultObjectMapper() {
5355
return objectMapper;
5456
}
5557

58+
/** method for initiazing object instance with default properties */
5659
public ApiClient() {
5760
this(null, null, null, null,null);
5861
}
5962

63+
/** ApiClient method for initiazing object instance with custom properties
64+
* @param basePath String that defines the base path for each API request
65+
* @param transport HttpTransport required for creating the httpRequestFactory
66+
* @param initializer HttpRequestInitializer for additional configuration during creation of httpRequestFactory
67+
* @param objectMapper ObjectMapper object used to serialize and deserialize using model classes.
68+
* @param reqFactory HttpRequestFactory is the thread-safe light-weight HTTP request factory layer on top of the HTTP transport
69+
*/
6070
public ApiClient(
6171
String basePath,
6272
HttpTransport transport,
@@ -74,46 +84,77 @@ public ApiClient(
7484
this.objectMapper = (objectMapper == null ? createDefaultObjectMapper() : objectMapper);
7585
}
7686

87+
/** method for retrieving the httpRequestFactory property
88+
* @return HttpRequestFactory
89+
*/
7790
public HttpRequestFactory getHttpRequestFactory() {
7891
return httpRequestFactory;
7992
}
8093

94+
/** method for retrieving the connectionTimeout property
95+
* @return int
96+
*/
8197
public int getConnectionTimeout() {
8298
return connectionTimeout;
8399
}
84100

101+
/** method for setting the connectionTimeout property
102+
* @param connectionTimeout int defines in milliseconds the time allowed making the initial connection to the server.
103+
*/
85104
public void setConnectionTimeout(int connectionTimeout) {
86105
this.connectionTimeout = connectionTimeout;
87106
}
88107

108+
/** method for retrieving the readTimeout property
109+
* @return int
110+
*/
89111
public int getReadTimeout() {
90112
return readTimeout;
91113
}
92114

115+
/** method for setting the readTimeout property
116+
* @param readTimeout int defines in milliseconds the time allowed to complete reading data from the server.
117+
*/
93118
public void setReadTimeout(int readTimeout) {
94119
this.readTimeout = readTimeout;
95120
}
96121

122+
/** method for retrieving the httpTransport property
123+
* @return HttpTransport
124+
*/
97125
public HttpTransport getHttpTransport() {
98126
return httpTransport;
99127
}
100128

129+
/** method for setting the httpTransport property
130+
* @param transport HttpTransport required for creating the httpRequestFactory
131+
*/
101132
public void setHttpTransport(HttpTransport transport) {
102133
this.httpTransport = transport;
103134
}
104135

136+
/** method for retrieving the basePath property
137+
* @return String
138+
*/
105139
public String getBasePath() {
106140
return basePath;
107141
}
108142

143+
/** method for retrieving the objectMapper property
144+
* @return ObjectMapper
145+
*/
109146
public ObjectMapper getObjectMapper() {
110147
return objectMapper;
111148
}
112149

150+
/** method for managing objects to be serialized */
113151
public class JacksonJsonHttpContent extends AbstractHttpContent {
114152
/* A POJO that can be serialized with a com.fasterxml Jackson ObjectMapper */
115153
private final Object data;
116154

155+
/** method for taking native object and serializing into JSON data for use by http client
156+
* @param data Object
157+
*/
117158
public JacksonJsonHttpContent(Object data) {
118159
super(Json.MEDIA_TYPE);
119160
this.data = data;
@@ -125,11 +166,19 @@ public void writeTo(OutputStream out) throws IOException {
125166
}
126167
}
127168

128-
// Builder pattern to get API instances for this client.
169+
/** Builder pattern to get API instances for this client.
170+
* @return AccountingApi
171+
*/
129172
public AccountingApi accountingApi() {
130173
return new AccountingApi(this);
131174
}
132175

176+
/** method for verifying an access token using RSA256 Algorithm
177+
* @param accessToken String the JWT token used to access the API
178+
* @return DecodedJWT
179+
* @exception MalformedURLException Thrown to indicate that a malformed URL has occurred.
180+
* @exception JwkException thrown to indicate a problem while verifying a JWT
181+
*/
133182
public DecodedJWT verify(String accessToken) throws MalformedURLException, JwkException {
134183

135184
DecodedJWT unverifiedJWT = JWT.decode(accessToken);

src/main/java/com/xero/api/RFC3339DateFormat.java

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.text.FieldPosition;
1919
import java.util.Date;
2020

21+
/** RFC3339DateFormat method for serializing date into milliseconds */
2122
public class RFC3339DateFormat extends ISO8601DateFormat {
2223

2324
// Same as ISO8601DateFormat but serializing milliseconds.

src/main/java/com/xero/api/StringUtil.java

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.threeten.bp.OffsetDateTime;
2323
import org.threeten.bp.ZoneOffset;
2424

25+
/** StringUtil has helper methods for String and Date conversions */
2526
public class StringUtil {
2627
/**
2728
* Check if the given array contains the given value (with case-insensitive
@@ -72,6 +73,11 @@ public static String join(String[] array, String separator) {
7273
return out.toString();
7374
}
7475

76+
/** Convert string to date
77+
* @param date String is a date in MS DateFormat
78+
* @return LocalDate a standard date
79+
* @exception IOException thown if string pattern matching and formatting fails
80+
*/
7581
public LocalDate convertStringToDate(String date)
7682
throws IOException {
7783
LocalDate formattedDate;
@@ -91,6 +97,11 @@ public LocalDate convertStringToDate(String date)
9197
return formattedDate;
9298
}
9399

100+
/** Convert string to datetime
101+
* @param date String is a date in MS DateFormat
102+
* @return OffsetDateTime an offset date time set to UTC
103+
* @exception IOException thown if string pattern matching and formatting fails
104+
*/
94105
public OffsetDateTime convertStringToOffsetDateTime(String date)
95106
throws IOException {
96107
OffsetDateTime formattedDate;
@@ -110,6 +121,11 @@ public OffsetDateTime convertStringToOffsetDateTime(String date)
110121
return formattedDate;
111122
}
112123

124+
/** Convert string to datetime
125+
* @param date String is a date in MS DateFormat
126+
* @return LocalDateTime an local date time
127+
* @exception IOException thown if string pattern matching and formatting fails
128+
*/
113129
public LocalDateTime convertStringToLocalDateTime(String date)
114130
throws IOException {
115131
LocalDateTime formattedDate;

src/main/java/com/xero/api/XeroApiException.java

+36-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.HashMap;
66
import java.util.Map;
77

8+
/** Legacy XeroApiException general exception class for returning exception details */
89
public class XeroApiException extends XeroException {
910

1011
private static final long serialVersionUID = 1L;
@@ -13,18 +14,29 @@ public class XeroApiException extends XeroException {
1314
private Map<String, String> messageMap = new HashMap<String, String>();
1415
private Error error;
1516

16-
// LEGACY ERROR HANDLER
17+
/** Init Xero API Exception
18+
* @param responseCode int of the status code returned by the API
19+
*/
1720
public XeroApiException(int responseCode) {
1821
super(responseCode + " response.");
1922
this.responseCode = responseCode;
2023
}
2124

25+
/** Init Xero API Exception
26+
* @param responseCode int of the status code returned by the API
27+
* @param message String details about the exception
28+
* @param e Exception the original exception thrown
29+
*/
2230
public XeroApiException(int responseCode, String message, Exception e) {
2331
super(responseCode + " response: " + message, e);
2432
this.responseCode = responseCode;
2533
this.message = message;
2634
}
2735

36+
/** Init Xero API Exception
37+
* @param responseCode int of the status code returned by the API
38+
* @param map Map&lt;String, String&gt; array of details about the exception
39+
*/
2840
public XeroApiException(int responseCode, Map<String, String> map) {
2941
super(responseCode + "response");
3042
this.responseCode = responseCode;
@@ -38,31 +50,54 @@ public XeroApiException(int responseCode, Map<String, String> map) {
3850
this.messageMap = map;
3951
}
4052

53+
/** Init Xero API Exception
54+
* @param responseCode int of the status code returned by the API
55+
* @param error Error details about the exception
56+
* @param e Exception the original exception thrown
57+
*/
4158
public XeroApiException(int responseCode, Error error, Exception e) {
4259
super(responseCode + " response: none", e);
4360
this.responseCode = responseCode;
4461
this.error = error;
4562
}
4663

64+
/** Init Xero API Exception
65+
* @param responseCode int of the status code returned by the API
66+
* @param message String details about the exception
67+
* @param error Error details about the exception
68+
* @param e Exception the original exception thrown
69+
*/
4770
public XeroApiException(int responseCode, String message, Error error, Exception e) {
4871
super(responseCode + " response: " + message, e);
4972
this.responseCode = responseCode;
5073
this.message = message;
5174
this.error = error;
5275
}
5376

77+
/** Init Xero API Exception
78+
* @return int of the status code returned by the API
79+
*/
5480
public int getResponseCode() {
5581
return responseCode;
5682
}
5783

84+
/** Init Xero API Exception
85+
* @return String with the details about the exception
86+
*/
5887
public String getMessage() {
5988
return message;
6089
}
6190

91+
/** Init Xero API Exception
92+
* @return Map&lt;String, String&gt; array of messages about the exception
93+
*/
6294
public Map<String, String> getMessages() {
6395
return messageMap;
6496
}
6597

98+
/** Init Xero API Exception
99+
* @return Error object with information about the exception
100+
*/
66101
public Error getError() {
67102
return error;
68103
}

0 commit comments

Comments
 (0)