Issue
I have this method that needs a valid return response but I couldn't figure it out on how can I implement it.
@Override
public List<ReportLogsDataEntity> generateHtmlSummaryReport()
throws Exception {
HtmlTag rootElem = new HtmlParentElement("<html>");
rootElem.setStartTag("<html>");
rootElem.setEndTag("</html>");
HtmlTag headElem = new HtmlParentElement("<head>");
headElem.setStartTag("<head>");
headElem.setEndTag("</head>");
// CSS STYLE FOR TABLE
HtmlTag styleElem = new HtmlParentElement("<style>");
styleElem.setStartTag("<style> table {\n"
+ " border-collapse: collapse;\n" + " width: 50%;\n" + "}\n"
+ "\n" + "th {background-color:#D98880;}\n" + "\n" + "th, td {\n"
+ " font-family: Verdana;\n"
+ " font-size: 15px;\n" + " padding: 8px;\n"
+ " text-align: center;\n" + " border-bottom: 1px solid #ddd;\n"
+ "}\n" + "\n" + "tr:hover {background-color:#f5f5f5;}\n");
styleElem.setEndTag("</style>");
HtmlTag bodyElem = new HtmlParentElement("<body>");
bodyElem.setStartTag("<body>");
bodyElem.setEndTag("</body>");
HtmlTag tableElem = new HtmlParentElement("<table>");
tableElem.setStartTag("<center><table>");
tableElem.setEndTag("</table></center>");
HtmlTag tHeader = addTableHeader();
List<HtmlTag> tDataSummaryLogs = addSummaryLogs();
tableElem.addChildTag(tHeader);
// SETTING THE TABLE TO BE USED TO POPULATE
// WITH SUMMARY LOGS DATA
tDataSummaryLogs.forEach(tableElem::addChildTag);
// CONSTRUCTING THE WHOLE HTML ELEMENTS
headElem.addChildTag(styleElem);
bodyElem.addChildTag(tableElem);
rootElem.addChildTag(headElem);
rootElem.addChildTag(bodyElem);
log.info(rootElem.generateHtml());
writeToHTMLFile(rootElem.generateHtml());
return null;
}
I am quite lost on how can I implement or way to change the return null
into a return ResponseEntity
? Or any valid return in this method? Or like a response when generateHtmlSummaryReport()
has been successful? Any help or insights is appreciated.
Solution
Added response in form of ResponseEntity
@Override
public ResponseEntity<String> generateHtmlSummaryReport()
throws Exception {
........//your code
return new ResponseEntity<>("Hello World!", HttpStatus.OK);
}
or if you want to add headers and body to your response then do this
return ResponseEntity.ok()
.header("Custom-Header", "foo")
.body("Custom header set");
Answered By - anish sharma