7

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:

  1. Ability to launch the program from a web page
  2. Ability to see the scrolling output from Log4j
  3. If I leave the page and come back again, it should let me know that the last run is still running and show the log. I don't need to have the ability to run multiple instances in parallel.
Danish
  • 3,708
  • 5
  • 29
  • 48
  • 2
    Do you have experience with any java web framework? – Arnaud Gourlay Apr 11 '12 at 15:01
  • Um, a simple Swing application won't do? – Peter C Apr 11 '12 at 15:01
  • @Shagaan - Yes, my java web framework of choice is Spring MVC – Danish Apr 11 '12 at 15:03
  • @alpha123 - I'd like it to be web, so I can launch and view it from any device, PC/Phone/Tablet – Danish Apr 11 '12 at 15:04
  • @Danish I see. Java web apps are notoriously heavyweight though -- especially with something like Spring. Also, if you want it to display the log output in real-time, you'd probably have to use something like Comet. Not a lot of fun in Java. – Peter C Apr 11 '12 at 15:08
  • @alpha123 - I know what you mean about java webapps. Hence, I mentioned that it doesn't have to be a "Java" based webapp. Any web based solution would be good. – Danish Apr 11 '12 at 15:12
  • @Danish OK. You could probably roll something to do this in Scala with Lift (which has great Comet support) in a pretty short amount of time, but I really think the best idea is the Hudson/Jenkins server. – Peter C Apr 11 '12 at 17:04

3 Answers3

5

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.

Kevin
  • 24,871
  • 19
  • 102
  • 158
  • As an added bonus, you can use Jenkins to build your Java source code and test it as well. – Bernard Apr 11 '12 at 15:09
  • and if you have additional jobs in the future, you can add them without modification. And, if you work in a team environment, people may already be familiar with Jenkins. And you get bug fixes (and possibly plugins) for free. And... – Kevin Apr 11 '12 at 15:11
  • This looks pretty cool! I will certainly give this a shot. Is it possible to deploy this on the Windows Azure Cloud? – Danish Apr 11 '12 at 15:21
  • I haven't done it, but it's just a java webapp. So if you can install java, tomcat, and deploy a war I assume it's possible. If you want to checkout & build your code it would need access to your svn/git repo. – Kevin Apr 11 '12 at 15:25
1

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.

stephen.hanson
  • 9,014
  • 2
  • 47
  • 53
0

you may try calling web-service from jsp / jsf

vkantiya
  • 1,343
  • 1
  • 8
  • 20
  • I'm sorry I wasn't clear on my requirements. I've update my question to reflect them. I guess this would work, but I would like to see a scrolling log. Also, process may run longer than the HTTP timeout. – Danish Apr 11 '12 at 15:14
  • I guess web-service is still an option in your case. isn't it ? – vkantiya Apr 11 '12 at 15:19
  • 1
    you could do scrolling log with some kind of comet/long polling solution. – Kevin Apr 11 '12 at 15:26
  • It definitely is! I've developed a couple of site using Spring MVC. If I am to go that route, I am not a 100% sure how to fulfill all my requirements. Hence, I would need someone to help me with that before I can go this route. – Danish Apr 11 '12 at 15:33