@@ -151,7 +151,7 @@ private ApiClient(Builder builder) {
151
151
bodyLogger = new BodyLogger (mapper , 1024 , debugTruncateBytes );
152
152
}
153
153
154
- private static <I > void setQuery (Request in , I entity ) {
154
+ public static <I > void setQuery (Request in , I entity ) {
155
155
if (entity == null ) {
156
156
return ;
157
157
}
@@ -161,140 +161,33 @@ private static <I> void setQuery(Request in, I entity) {
161
161
}
162
162
}
163
163
164
- private static <I > void setHeaders (Request in , Map <String , String > headers ) {
165
- if (headers == null ) {
166
- return ;
167
- }
168
- for (Map .Entry <String , String > e : headers .entrySet ()) {
169
- in .withHeader (e .getKey (), e .getValue ());
170
- }
171
- }
172
-
173
- public <I , O > Collection <O > getCollection (
174
- String path , I in , Class <O > element , Map <String , String > headers ) {
164
+ public <O > Collection <O > getCollection (Request req , Class <O > element ) {
175
165
return withJavaType (
176
- path ,
177
- in ,
178
- mapper .getTypeFactory ().constructCollectionType (Collection .class , element ),
179
- headers );
166
+ req , mapper .getTypeFactory ().constructCollectionType (Collection .class , element ));
180
167
}
181
168
182
- public < I > Map <String , String > getStringMap (String path , I in , Map < String , String > headers ) {
169
+ public Map <String , String > getStringMap (Request req ) {
183
170
return withJavaType (
184
- path ,
185
- in ,
186
- mapper .getTypeFactory ().constructMapType (Map .class , String .class , String .class ),
187
- headers );
171
+ req , mapper .getTypeFactory ().constructMapType (Map .class , String .class , String .class ));
188
172
}
189
173
190
- protected <I , O > O withJavaType (
191
- String path , I in , JavaType javaType , Map <String , String > headers ) {
174
+ protected <I , O > O withJavaType (Request request , JavaType javaType ) {
192
175
try {
193
- Request request = prepareRequest ("GET" , path , in , headers );
194
176
Response response = getResponse (request );
195
177
return deserialize (response .getBody (), javaType );
196
178
} catch (IOException e ) {
197
179
throw new DatabricksException ("IO error: " + e .getMessage (), e );
198
180
}
199
181
}
200
182
201
- public <O > O HEAD (String path , Class <O > target , Map <String , String > headers ) {
202
- return HEAD (path , null , target , headers );
203
- }
204
-
205
- public <I , O > O HEAD (String path , I in , Class <O > target , Map <String , String > headers ) {
206
- try {
207
- return execute (prepareRequest ("HEAD" , path , in , headers ), target );
208
- } catch (IOException e ) {
209
- throw new DatabricksException ("IO error: " + e .getMessage (), e );
210
- }
211
- }
212
-
213
- public <O > O GET (String path , Class <O > target , Map <String , String > headers ) {
214
- return GET (path , null , target , headers );
215
- }
216
-
217
- public <I , O > O GET (String path , I in , Class <O > target , Map <String , String > headers ) {
218
- try {
219
- return execute (prepareRequest ("GET" , path , in , headers ), target );
220
- } catch (IOException e ) {
221
- throw new DatabricksException ("IO error: " + e .getMessage (), e );
222
- }
223
- }
224
-
225
- public <O > O POST (String path , Class <O > target , Map <String , String > headers ) {
226
- try {
227
- return execute (prepareRequest ("POST" , path , null , headers ), target );
228
- } catch (IOException e ) {
229
- throw new DatabricksException ("IO error: " + e .getMessage (), e );
230
- }
231
- }
232
-
233
- public <I , O > O POST (String path , I in , Class <O > target , Map <String , String > headers ) {
234
- try {
235
- return execute (prepareRequest ("POST" , path , in , headers ), target );
236
- } catch (IOException e ) {
237
- throw new DatabricksException ("IO error: " + e .getMessage (), e );
238
- }
239
- }
240
-
241
- public <I , O > O PUT (String path , I in , Class <O > target , Map <String , String > headers ) {
242
- try {
243
- return execute (prepareRequest ("PUT" , path , in , headers ), target );
244
- } catch (IOException e ) {
245
- throw new DatabricksException ("IO error: " + e .getMessage (), e );
246
- }
247
- }
248
-
249
- public <I , O > O PATCH (String path , I in , Class <O > target , Map <String , String > headers ) {
250
- try {
251
- return execute (prepareRequest ("PATCH" , path , in , headers ), target );
252
- } catch (IOException e ) {
253
- throw new DatabricksException ("IO error: " + e .getMessage (), e );
254
- }
255
- }
256
-
257
- public <I , O > O DELETE (String path , I in , Class <O > target , Map <String , String > headers ) {
258
- try {
259
- return execute (prepareRequest ("DELETE" , path , in , headers ), target );
260
- } catch (IOException e ) {
261
- throw new DatabricksException ("IO error: " + e .getMessage (), e );
262
- }
263
- }
264
-
265
- private boolean hasBody (String method ) {
266
- return !method .equals ("GET" ) && !method .equals ("DELETE" ) && !method .equals ("HEAD" );
267
- }
268
-
269
- private <I > Request prepareBaseRequest (String method , String path , I in )
270
- throws JsonProcessingException {
271
- if (in == null || !hasBody (method )) {
272
- return new Request (method , path );
273
- } else if (InputStream .class .isAssignableFrom (in .getClass ())) {
274
- InputStream body = (InputStream ) in ;
275
- return new Request (method , path , body );
276
- } else {
277
- String body = (in instanceof String ) ? (String ) in : serialize (in );
278
- return new Request (method , path , body );
279
- }
280
- }
281
-
282
- private <I > Request prepareRequest (String method , String path , I in , Map <String , String > headers )
283
- throws JsonProcessingException {
284
- Request req = prepareBaseRequest (method , path , in );
285
- setQuery (req , in );
286
- setHeaders (req , headers );
287
- return req ;
288
- }
289
-
290
183
/**
291
184
* Executes HTTP request with retries and converts it to proper POJO
292
185
*
293
186
* @param in Commons HTTP request
294
187
* @param target Expected pojo type
295
188
* @return POJO of requested type
296
189
*/
297
- private <T > T execute (Request in , Class <T > target ) throws IOException {
190
+ public <T > T execute (Request in , Class <T > target ) throws IOException {
298
191
Response out = getResponse (in );
299
192
if (target == Void .class ) {
300
193
return null ;
@@ -533,7 +426,7 @@ public <T> void deserialize(Response response, T object) throws IOException {
533
426
}
534
427
}
535
428
536
- private String serialize (Object body ) throws JsonProcessingException {
429
+ public String serialize (Object body ) throws JsonProcessingException {
537
430
if (body == null ) {
538
431
return null ;
539
432
}
0 commit comments