@@ -229,7 +229,7 @@ public String put(
229
229
help = "The path to the resource." ,
230
230
unspecifiedDefaultValue = "" ) PathOrRel path ,
231
231
@ CliOption (key = "data" ,
232
- mandatory = true ,
232
+ mandatory = false ,
233
233
help = "The JSON data to use as the resource." ) String data ,
234
234
@ CliOption (key = "from" ,
235
235
mandatory = false ,
@@ -307,9 +307,13 @@ public String execute(final HttpMethod method,
307
307
final boolean follow ,
308
308
final String outputPath ) {
309
309
final StringBuilder buffer = new StringBuilder ();
310
+ MediaType contentType = configCmds .getHeaders ().getContentType ();
311
+ if (contentType == null ) {
312
+ contentType = MediaType .APPLICATION_JSON ;
313
+ }
310
314
311
315
ResponseErrorHandler origErrHandler = restTemplate .getErrorHandler ();
312
- RequestHelper helper = (null == data ? new RequestHelper () : new RequestHelper (data , MediaType . APPLICATION_JSON ));
316
+ RequestHelper helper = (null == data ? new RequestHelper () : new RequestHelper (data , contentType ));
313
317
ResponseEntity <String > response ;
314
318
try {
315
319
restTemplate .setErrorHandler (new ResponseErrorHandler () {
@@ -380,14 +384,16 @@ private String readFileOrFiles(final HttpMethod method,
380
384
final String fromPath ,
381
385
final boolean follow ,
382
386
final String outputPath ) throws IOException {
383
- final AtomicInteger numItems = new AtomicInteger ( 0 ) ;
387
+ String output = "" ;
384
388
385
389
File fromFile = new File (fromPath );
386
390
if (!fromFile .exists ()) {
387
391
throw new IllegalArgumentException ("Path " + fromPath + " not found." );
388
392
}
389
393
390
394
if (fromFile .isDirectory ()) {
395
+ final AtomicInteger numItems = new AtomicInteger (0 );
396
+
391
397
FilenameFilter jsonFilter = new FilenameFilter () {
392
398
@ Override public boolean accept (File file , String s ) {
393
399
return s .endsWith (".json" );
@@ -405,19 +411,22 @@ private String readFileOrFiles(final HttpMethod method,
405
411
406
412
numItems .incrementAndGet ();
407
413
}
414
+
415
+ output = numItems .get () + " files uploaded to the server using " + method ;
408
416
} else {
409
417
Object body = readFile (fromFile );
410
- String response = execute (HttpMethod . POST ,
418
+ String response = execute (method ,
411
419
body ,
412
420
follow ,
413
421
outputPath );
414
422
if (LOG .isDebugEnabled ()) {
415
423
LOG .debug (response );
416
424
}
417
- numItems .incrementAndGet ();
425
+
426
+ output = response ;
418
427
}
419
428
420
- return numItems . get () + " files uploaded to the server using " + method ;
429
+ return output ;
421
430
}
422
431
423
432
private Object readFile (File file ) throws IOException {
@@ -607,5 +616,4 @@ private class SslAwareClientHttpRequestFactory extends SimpleClientHttpRequestFa
607
616
super .prepareConnection (connection , httpMethod );
608
617
}
609
618
}
610
-
611
619
}
0 commit comments