Skip to content

Commit 1cca991

Browse files
committed
Merge branch 'master' of github.com:SpringSource/rest-shell
2 parents bb5f853 + 557ff1b commit 1cca991

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/main/java/org/springframework/data/rest/shell/commands/HttpCommands.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public String put(
229229
help = "The path to the resource.",
230230
unspecifiedDefaultValue = "") PathOrRel path,
231231
@CliOption(key = "data",
232-
mandatory = true,
232+
mandatory = false,
233233
help = "The JSON data to use as the resource.") String data,
234234
@CliOption(key = "from",
235235
mandatory = false,
@@ -307,9 +307,13 @@ public String execute(final HttpMethod method,
307307
final boolean follow,
308308
final String outputPath) {
309309
final StringBuilder buffer = new StringBuilder();
310+
MediaType contentType = configCmds.getHeaders().getContentType();
311+
if(contentType == null) {
312+
contentType = MediaType.APPLICATION_JSON;
313+
}
310314

311315
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));
313317
ResponseEntity<String> response;
314318
try {
315319
restTemplate.setErrorHandler(new ResponseErrorHandler() {
@@ -380,14 +384,16 @@ private String readFileOrFiles(final HttpMethod method,
380384
final String fromPath,
381385
final boolean follow,
382386
final String outputPath) throws IOException {
383-
final AtomicInteger numItems = new AtomicInteger(0);
387+
String output = "";
384388

385389
File fromFile = new File(fromPath);
386390
if(!fromFile.exists()) {
387391
throw new IllegalArgumentException("Path " + fromPath + " not found.");
388392
}
389393

390394
if(fromFile.isDirectory()) {
395+
final AtomicInteger numItems = new AtomicInteger(0);
396+
391397
FilenameFilter jsonFilter = new FilenameFilter() {
392398
@Override public boolean accept(File file, String s) {
393399
return s.endsWith(".json");
@@ -405,19 +411,22 @@ private String readFileOrFiles(final HttpMethod method,
405411

406412
numItems.incrementAndGet();
407413
}
414+
415+
output = numItems.get() + " files uploaded to the server using " + method;
408416
} else {
409417
Object body = readFile(fromFile);
410-
String response = execute(HttpMethod.POST,
418+
String response = execute(method,
411419
body,
412420
follow,
413421
outputPath);
414422
if(LOG.isDebugEnabled()) {
415423
LOG.debug(response);
416424
}
417-
numItems.incrementAndGet();
425+
426+
output = response;
418427
}
419428

420-
return numItems.get() + " files uploaded to the server using " + method;
429+
return output;
421430
}
422431

423432
private Object readFile(File file) throws IOException {
@@ -607,5 +616,4 @@ private class SslAwareClientHttpRequestFactory extends SimpleClientHttpRequestFa
607616
super.prepareConnection(connection, httpMethod);
608617
}
609618
}
610-
611619
}

src/main/java/org/springframework/data/rest/shell/formatter/XmlFormatter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public Collection<String> getSupportedList() {
2626
public String format(String nonFormattedString) {
2727
try {
2828
Transformer serializer = SAXTransformerFactory.newInstance().newTransformer();
29+
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
2930
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
3031
serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
3132
Source xmlSource = new SAXSource(new InputSource(new ByteArrayInputStream(nonFormattedString.getBytes())));

0 commit comments

Comments
 (0)