• Post Reply Bookmark Topic Watch Topic
  • New Topic

Building a Web Frontend for a Command-Line-Based Software with JSF  RSS feed

 
Antonio Modesto Amaral Sousa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I'm a computer science student and I'm just starting with JSF and Web Development in general. In fact I have more experience with network and systems administration, though I'm a Java developer also. I need to develop a graduation project for college and I have to finish it until the end of this year. The goal of this software is to provide a web interface which must be able to manage the Quagga routing daemon. For those who don't know Quagga, the only interface it provides the user is its built-in cli. My project must convert web events to commands and vice-versa. I'm having some difficult to figure out how I'm going to maintain quagga's configuration state synchronized with JSF's managed beans. The example below shows the commands one must run on quagga's cli in order to add a BGP neighbor:




In order to represent this piece of information in my project, I was thinking about mapping this to a class:



This is just a example class so you could get my line of thought. With this I would parse the information from Quagga's configuration and map this to classes in my software. I think it's a lot easier to do with database-based software, the problem with this project is that it's not completely database oriented. The information must be fetched from the network, parsed, converted to classes and then they would be available to JSF as managed beans. Any alteration to this classes must be converted to quagga cli commands which must be executed through the network again (telnet). As I have no experience with JSF, I'm a little confused about the best way to do this.

Sorry if I didn't get you guys to understand my problem clearly. I hope you can give me any suggestion about this.

Regards.
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Antonio!

JSF is a framework whose best functionality lies within the realm of editable HTML forms. It is a non-exclusive framework, so for tasks that are not forms-related, it is often better to use native JSPs or servlets.

Your biggest constraint is probably not going to be JSF, it's going to be HTTP. HTTP is not an asynchronous protocol nor does it permit multiple responses to a single request, and that can make things awkward when you need to do something that either takes a long time or produces multiple outputs at different times.

Action methods in backing beans can invoke any sort of backend service they like within these constraints. So if a JSF backing bean wished to make an internal HTTP request(s) to another web application(s) to obtain information to populate or update itself, it can do so - constrained, again by the fact that the backing bean is not running under an independent task, and can therefore only execute when processing an incoming JSF request/response cycle. Nor are action methods limited to just HTTP internal requests. You can also make JMS requests or other non-HTTP services, and that includes telnet or ssh invocations of remote command-line processes or Runtime.exec()-style local program actions, as long as the results come back in a short period of time.
 
Antonio Modesto Amaral Sousa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Tim,

Thanks for replying.


As I wrote in the first post, in order for a backing bean to be populated, it would be necessary to execute a remote command on a linux/freebsd box with quagga running and get the result. This command must be executed through a ssh tunnel for security reasons. Based on what you told me, I assume that it's not possible to persist this connection while someone is managing a device with the web interface, is it? I imagine that this would be the basic flow:

User access a router configuration in the web interface -> JSF tries to access a managed bean which represents the configuration > The Managed bean executes the remote command in order to fetch the configuration > The response is parsed and inserted into the bean > JSF Displays the result

If the user makes any changes in the forms and submit them, those changes must be converted into a batch of commands and then they must be executed on the remote machine through a ssh tunnel.

I assume that the time to run the command and get the result is not too long, just a couple of seconds depending on the network latency.


Regards.
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as the bean is simply used as an intermediary to execute commands on request from the web client and return the results, you are OK. But a bean doesn't run under a task of its own, so it can't sit and poll the ssh connection or park itself and wait for an extended period of time. In fact, the J2EE spec expressly forbids that sort of behavior, JSF or not.
 
Antonio Modesto Amaral Sousa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,


I've got it. But what would happen if it takes a little longer than I expect? The user would have to sit waiting for the response or it would be denied by some internal mechanism? In order for this to work, I have to write some helper code to handle the creation of the ssh tunnel, then the telnet connection would take place in order to execute the commands, this code should be called by the managed bean. I've also thought about using RMI, do you think it would be better?
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a command takes too long, the user's browser window is stuck waiting for a reply (other browsers/windows not affected). If it takes a REALLY long time, the user request will time out and the response will be lost. In cases like that, the best way of handling that is to create a special component at startup that runs under an independent thread(s) and have the web request send messages and inquiries to it.

The actual ssh command can do everything very simply if you just want to execute one remote command. For example:



Would list my home directory on machine "remotemachine". For added convenience, I could store a cert that would allow SSH to not demand a password (it would use the previously-stored cert for authentication).

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!