Solved

Executing a unix shell script from an EJB

Posted on 2006-06-09
4
965 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best Automatic build tool 3 96
Encrypt the Oracle database 5 73
HP Virtual Connect firmware upgrade ? 5 117
ESXi 6.x and Host Profiles 5 108
Convert websphere application server default chained Certificates from 1024 to 2048 keysize or higher size and also you can change signatureAlgorithm . Please make sure Websphere Application Server fixpack 7.0.0.23 or Above. The following steps a…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

823 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