28
28
import java .net .URL ;
29
29
import java .security .interfaces .RSAPublicKey ;
30
30
31
-
31
+ /**
32
+ * ApiClient for managing global http client and object mapper
33
+ */
32
34
public class ApiClient {
33
35
private final String basePath ;
34
36
private final HttpRequestFactory httpRequestFactory ;
35
37
private final ObjectMapper objectMapper ;
36
38
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 ;
39
41
40
42
private static final String defaultBasePath = "https://api.xero.com/api.xro/2.0" ;
41
43
@@ -53,10 +55,18 @@ private static ObjectMapper createDefaultObjectMapper() {
53
55
return objectMapper ;
54
56
}
55
57
58
+ /** method for initiazing object instance with default properties */
56
59
public ApiClient () {
57
60
this (null , null , null , null ,null );
58
61
}
59
62
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
+ */
60
70
public ApiClient (
61
71
String basePath ,
62
72
HttpTransport transport ,
@@ -74,46 +84,77 @@ public ApiClient(
74
84
this .objectMapper = (objectMapper == null ? createDefaultObjectMapper () : objectMapper );
75
85
}
76
86
87
+ /** method for retrieving the httpRequestFactory property
88
+ * @return HttpRequestFactory
89
+ */
77
90
public HttpRequestFactory getHttpRequestFactory () {
78
91
return httpRequestFactory ;
79
92
}
80
93
94
+ /** method for retrieving the connectionTimeout property
95
+ * @return int
96
+ */
81
97
public int getConnectionTimeout () {
82
98
return connectionTimeout ;
83
99
}
84
100
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
+ */
85
104
public void setConnectionTimeout (int connectionTimeout ) {
86
105
this .connectionTimeout = connectionTimeout ;
87
106
}
88
107
108
+ /** method for retrieving the readTimeout property
109
+ * @return int
110
+ */
89
111
public int getReadTimeout () {
90
112
return readTimeout ;
91
113
}
92
114
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
+ */
93
118
public void setReadTimeout (int readTimeout ) {
94
119
this .readTimeout = readTimeout ;
95
120
}
96
121
122
+ /** method for retrieving the httpTransport property
123
+ * @return HttpTransport
124
+ */
97
125
public HttpTransport getHttpTransport () {
98
126
return httpTransport ;
99
127
}
100
128
129
+ /** method for setting the httpTransport property
130
+ * @param transport HttpTransport required for creating the httpRequestFactory
131
+ */
101
132
public void setHttpTransport (HttpTransport transport ) {
102
133
this .httpTransport = transport ;
103
134
}
104
135
136
+ /** method for retrieving the basePath property
137
+ * @return String
138
+ */
105
139
public String getBasePath () {
106
140
return basePath ;
107
141
}
108
142
143
+ /** method for retrieving the objectMapper property
144
+ * @return ObjectMapper
145
+ */
109
146
public ObjectMapper getObjectMapper () {
110
147
return objectMapper ;
111
148
}
112
149
150
+ /** method for managing objects to be serialized */
113
151
public class JacksonJsonHttpContent extends AbstractHttpContent {
114
152
/* A POJO that can be serialized with a com.fasterxml Jackson ObjectMapper */
115
153
private final Object data ;
116
154
155
+ /** method for taking native object and serializing into JSON data for use by http client
156
+ * @param data Object
157
+ */
117
158
public JacksonJsonHttpContent (Object data ) {
118
159
super (Json .MEDIA_TYPE );
119
160
this .data = data ;
@@ -125,11 +166,19 @@ public void writeTo(OutputStream out) throws IOException {
125
166
}
126
167
}
127
168
128
- // Builder pattern to get API instances for this client.
169
+ /** Builder pattern to get API instances for this client.
170
+ * @return AccountingApi
171
+ */
129
172
public AccountingApi accountingApi () {
130
173
return new AccountingApi (this );
131
174
}
132
175
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
+ */
133
182
public DecodedJWT verify (String accessToken ) throws MalformedURLException , JwkException {
134
183
135
184
DecodedJWT unverifiedJWT = JWT .decode (accessToken );
0 commit comments