I wrote an endpoint that should download the excel file and read its contents. But, to my surprise, the very first recorder that I set at this endpoint does not print. This basically means that this endpoint does not call.
Mycontroller.java
@RestController
@RequestMapping(value = "/abc/xyz")
@Validated
@Api(basePath = "/abc/xyz", value = "/abc/xyz", produces = "application/json")
public class MyController extends BaseController {
@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = { "multipart/form-data" }, produces = "application/json")
@ApiOperation(value = "MyController.upload", notes = "Read File")
@ApiResponses(value = { @ApiResponse(message = "OK", code = 200, response = ResponseEntity.class),
@ApiResponse(message = "Forbidden", code = 403, response = ResponseEntity.class),
@ApiResponse(message = "Internal Server Error", code = 500, response = ResponseEntity.class) })
public List<XlsPojo> upload(@RequestParam("file") MultipartFile file) {
logger.debug("### Calling Upload:");
List<XlsPojo> pojos = new ArrayList<XlsPojo>();
if (!file.isEmpty()) {
logger.debug("### file: ");
try {
@SuppressWarnings("resource")
Workbook workbook = new XSSFWorkbook(file.getInputStream());
Sheet datatypeSheet = workbook.getSheetAt(1);
Iterator<Row> iterator = datatypeSheet.iterator();
while (iterator.hasNext()) {
Row currentRow = iterator.next();
if (currentRow.getRowNum() > 0) {
XlsPojo record = XlsPojo.getXlsRecords(currentRow);
System.out.println("### record: " + record);
pojos.add(record);
}
}
} catch (Exception e) {
System.out.println("Exception " + e);
}
}
return pojos;
}
}
build.gradle
compile group: 'org.apache.poi', name:'poi-ooxml', version:'3.15'
Am I missing something in the code snippet above?
Environment:
- Ubuntu 16.04
- Spring Download
- Swagger for documenting REST APIs
- Gradle to create a project.
source
share