BAEL-3559: Change server response to mimic an echo server
This commit is contained in:
parent
8bdf6f8d34
commit
c6acca6714
|
@ -1,33 +1,58 @@
|
||||||
package com.baeldung.web.controller;
|
package com.baeldung.web.controller;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class MultipartFileUploadStubController {
|
public class MultipartFileUploadStubController {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(MultipartFileUploadStubController.class);
|
|
||||||
|
|
||||||
@PostMapping("/stub/multipart")
|
@PostMapping("/stub/multipart")
|
||||||
@ResponseStatus(HttpStatus.OK)
|
public ResponseEntity<UploadResultResource> uploadFile(MultipartFile file, String text, String text1, String text2, MultipartFile upstream) {
|
||||||
public void uploadFile(MultipartFile file, String text, String text1, String text2, MultipartFile upstream) {
|
UploadResultResource result = new UploadResultResource(file, text, text1, text2, upstream);
|
||||||
logger.info("Uploaded file: " + format(file));
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
logger.info(" - text: [" + format(text) + "]");
|
}
|
||||||
logger.info(" - text1: [" + format(text1) + "]");
|
|
||||||
logger.info(" - text2: [" + format(text2) + "]");
|
public static class UploadResultResource {
|
||||||
logger.info(" - upstream: [" + format(upstream) + "]");
|
|
||||||
|
private final String file;
|
||||||
|
private final String text;
|
||||||
|
private final String text1;
|
||||||
|
private final String text2;
|
||||||
|
private final String upstream;
|
||||||
|
|
||||||
|
public UploadResultResource(MultipartFile file, String text, String text1, String text2, MultipartFile upstream) {
|
||||||
|
this.file = format(file);
|
||||||
|
this.text = text;
|
||||||
|
this.text1 = text1;
|
||||||
|
this.text2 = text2;
|
||||||
|
this.upstream = format(upstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String format(MultipartFile file) {
|
private static String format(MultipartFile file) {
|
||||||
return file == null ? "<null>" : file.getOriginalFilename() + " (size: " + file.getSize() + " bytes)";
|
return file == null ? null : file.getOriginalFilename() + " (size: " + file.getSize() + " bytes)";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String format(String str) {
|
public String getFile() {
|
||||||
return str == null ? "<null>" : str;
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText1() {
|
||||||
|
return text1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText2() {
|
||||||
|
return text2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUpstream() {
|
||||||
|
return upstream;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue