I have a requirement to invoke unix shell script, however, I understand that having the runtime.exec() in EJB is not recommended, how about in serlvet? Or any other better alternatively?
Many thanks!
Amos
-
runtime.exec() in EJB Or Serlvet? (1 messages)
- Posted by: Amos Ang
- Posted on: February 20 2003 02:04 EST
Threaded Messages (1)
- runtime.exec() in EJB Or Serlvet? by Tomas Inger on February 20 2003 10:10 EST
-
runtime.exec() in EJB Or Serlvet?[ Go to top ]
- Posted by: Tomas Inger
- Posted on: February 20 2003 10:10 EST
- in response to Amos Ang
Hi!
If it is a requirement, you have to do it although it is not recommended in the specs. That's life sometimes!
My recommendation on implementation is:
- Define an interface with a method doWhatIWantToDo().
- Implement MyOperatingSystemImplementation, a class implementing the interface. Let this implemenation call exec(...).
- Define "implementing class" as a property. (In the DD or somewhere else depending on how you define properties in the project.)
- Make a small factory using the "implementing class" information to return an object working on the operating system you have.
With this solution, you can add new implementations (for other operating systems) without changing the existing code. But most of all, it is clear to persons working with the code in the future that this implementations is a little dirty!
And if someone blames you for a "dirty" solution using OS calls, you can always say that you know and have made a good encapsulation of it.
/Tomas