Solved

Executing a unix shell script from an EJB

Posted on 2006-06-09
4
953 Views
Last Modified: 2012-06-27
Hello,

I'm just starting with J2EE, so I hope you will bear with a very ignorant question. I have a legacy website which I would like to reimplement using some sort of MVC pattern.  The site runs ksh scripts, and reads the resulting files, and the new site must do the same.

Can an EJB make calls out to the shell?  How do I  go about this? (I.e. is there anything special that I should know for it to work within J2EE?)

Many thanks!

Roger Pearse
0
Comment
Question by:roger_pearse
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
anumalas earned 500 total points
ID: 17017080
Hi Roger

We can not call your shell scripts from your EJB. If it is manditory for your requirement you can Use struts frame work for your site. This Frame work will follow MVC 2 Design pattern and from Action class you can call Shell script like bellow

Process someAppProcess; //Handle to the process
try
{
someAppProcess = Runtime.getRuntime().exec("/usr/business/scripts/urscript.sh");
}
catch(java.io.IOException e)
{
//Handle an IOException here.
return;
}


after getting script results put those results as per your wish. Some best practices are hold results in collection object, prepare DTO and pass it to the middle tier, means pass that DTO to Any session bean (EJB) from that middle tier you can communicate with the database.

Hope you have clear understading about MVC. If you are not willing to use Struts frame work you can write that code in ur Servlet also.

Hope this will help you and all the best for your site improvements :)
0
 

Author Comment

by:roger_pearse
ID: 17024596
Many thanks for this.  What is a DTO?  (I think that I understand the MVC pattern, so your comment is helpful).
0
 
LVL 19

Expert Comment

by:ramazanyich
ID: 17029563
if you are using JBOSS then it comes with BSH deployer. Check http://wiki.jboss.org/wiki/Wiki.jsp?page=BSHDeployer
and check beanshell documentation: http://www.beanshell.org/docs.html
0
 
LVL 3

Expert Comment

by:anumalas
ID: 17029773
Hi Roger

DTO means Data Transfer Object. This is used to transfer data from one tier to another tier. i.e., Presentation Tier to Business Tier or Middle tier. Instead of sending each and every varible or filed value to server we will prepare one DTO and send it to Business tier. That will reduce network usage and improves performance of your application
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now