I have a Java class with a main()
method. It contains logic to do some number crunching and analysis. Its scheduled to run once per day and may be manually run again if needed. The routine uses Log4j to log its activities. Running it and checking the log requires a remote login to the host box.
I would like to convert it to a web application, where I can trigger it through a web page and see the output of the log, ideally as it scrolls.
What would be the best way to do this? A Java webapp? A simple generic web based script runner? or any other option I may not be aware of.
Update: A bit more detail on requirements:
Have you considered setting up a Hudson/Jenkins server to run the task? Because it has the features you describe, it IS a java web app, and it would work without modification to your existing project.
You could submit the form via AJAX and use Ajax with Spring MVC to poll for new log entries and add them to a table on your page. Here's some quick sample code for AJAX call to check for new log entry using JQuery and Spring MVC controller method to handle it.
JSP:
$.getJSON("logs.htm", { lastLogId: logId }, function(response) {
$('#myTable tr:last').after('<tr><td>' + response + '</td></tr>');
});
Spring MVC Controller (returns JSON):
@Controller
public class LogController {
@RequestMapping("logs.htm")
public @ResponseBody String getLogs(@RequestAttribute("lastLogId") Integer lastLogId, HttpSession sess) {
LogList logs = sess.getAttribute("logs"); // just an example using user-defined class "LogList"
return logs.getNextLog(lastLogId);
}
}
There are a few pieces I didn't mention here (would need to store log entries to session when log4j logs, etc..), but I hope it's at least helpful to see a way to do this using Spring MVC and AJAX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With