Skip to content

Commit a406f9f

Browse files
committed
When posting, use the contentType specified in the shell and fall back to JSON if not specified.
1 parent 32fa761 commit a406f9f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {
@@ -607,5 +611,4 @@ private class SslAwareClientHttpRequestFactory extends SimpleClientHttpRequestFa
607611
super.prepareConnection(connection, httpMethod);
608612
}
609613
}
610-
611614
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +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, "true");
29+
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
3030
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
3131
serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
3232
Source xmlSource = new SAXSource(new InputSource(new ByteArrayInputStream(nonFormattedString.getBytes())));

0 commit comments

Comments
 (0)