Professional Documents
Culture Documents
14SCN26 DC Lab Manual
14SCN26 DC Lab Manual
14SCN26 DC Lab Manual
Report
On
Submitted by
Your Name
USN:
M.Tech in CNE
2014-15
14SCN26
2014-15
M.Tech in CNE
2014-15
14SCN26
CERTIFICATE
Certified that the Distributed Computing Laboratory work (14SCN26) has been
successfully completed by Your name bearing USN:
a bonafide student of
Examiners:
1)
2)
ACKNOWLEDGEMENT
M.Tech in CNE
2014-15
14SCN26
I take the immense pleasure in acknowledging the people responsible for guiding and encouraging
towards the successful completion of the Distributed Computing Lab work.
I would like to profoundly thank Management of RNS Institute of Technology for
providing such a healthy environment to carry out this laboratory.
I would like to thank our beloved Director Dr. H. N. Shivashankar for his support towards
carrying out this laboratory.
I would like to express my thanks to our Principal Dr. M. K. Venkatesha for his
encouragement that motivated me to carry out this laboratory.
I wish to express my gratitude and sincere thanks to Dr. M. V. Sudhamani, Professor and
Head of the Department, Information Science and Engineering, for providing a good working
environment and for her constant support and encouragement.
I would like to thank staff in-charge Mr. R. Rajkumar, Assistant Professor, Department of
Information Science and Engineering for his constant support and guidance to carry out the
Distributed Computing Laboratory and also all other teaching and non-teaching staffs of Information
Science & Engineering who have directly or indirectly helped me to carry out this laboratory.
And lastly I would hereby acknowledge and thank my parents who have been a source of
inspiration and also instrumental in carrying out this laboratory.
MohammadParvez A. Halli
USN: 1RN14SCN06
Experiments
M.Tech in CNE
2014-15
14SCN26
1. Design and implement client server application using RMI (Remote Method Invocation) to
invoke a service to calculate the income tax.
2. Design and implement EJB (Entity Java Beans) session bean business logic to calculate
income tax and invoke the service using stub, i.e., client side proxy object.
3. Design and implement an EJB entity bean to persist the client submitted data into an enterprise
information system.
4. Design and implement an offline database communication system using JMS (Java Message
Service) to service the client request.
5. Design and implement the client code to call the Micro soft service like free service from
UDDI (Universal Description Discovery Protocol).
6. Design and implement business logic and bind it as service using SOAP (Simple Object Access
Protocol), also implement client to call service.
M.Tech in CNE
2014-15
14SCN26
Program 1: Design and implement client server application using RMI (Remote
Method Invocation) to invoke a service to calculate the income tax.
Procedure:
Step1: Open the Notepad
The first file TaxServerIntf.java defines the remote interface: it includes one method that
accepts one arguemnt and returns their tax. Write this below code in the file.
import java.rmi.*;
public interface TaxServerIntf extends Remote {
double add(double d1) throws RemoteException;
}
The second source file TaxServerImpl.java implements the remote interface. Write this below
code in the file.
import java.rmi.*;
import java.rmi.server.*;
public class TaxServerImpl extends UnicastRemoteObject
implements TaxServerIntf {
public TaxServerImpl() throws RemoteException {
}
public double Tax(double d1) throws RemoteException {
double it;
it=0;
if(d1<500000 && d1>250000)
{
it=d1-250000;
it=it*0.1;
}
else if(d1>500000 && d1<1000000)
{
it=d1-500000;
it=it*0.2+25000;
}
return it;
}
The third source file TaxServer.java contains the main program for the server machine. Its
primary function is to update the RMI registry on that machine. Write this below code in the
file.
import java.net.*;
import java.rmi.*;
M.Tech in CNE
2014-15
14SCN26
The fourth source file AddClient.java implements the client side of this distributed
application. Write this below code in the file.
import java.rmi.*;
public class TaxClient {
public static void main(String args[]) {
try {
String TaxServerURL = "rmi://" + args[0] + "/TaxServer";
TaxServerIntf taxServerIntf = (TaxServerIntf)Naming.lookup(taxServerURL);
System.out.println("The salary is : " + args[1]);
double d1 = Double.valueOf(args[1]).doubleValue();
System.out.println("The tax is: " + TaxServerIntf.tax(d1, d2));
}
catch(Exception e) {
System.out.println("Exception: " + e);
}
}
}
javac *.java
M.Tech in CNE
2014-15
14SCN26
Creating two other command prompt windows each for client & server.
Output:
M.Tech in CNE
2014-15
14SCN26
M.Tech in CNE
2014-15
14SCN26
Program 2: Design and implement EJB (Entity Java Beans) session bean business logic
to calculate income tax and invoke the service using stub, i.e., client side proxy object.
Procedure:
Step 1: Start the Net Beans
Go to file -> new project -> java EE -> enterprise application -> click on next -> give the
project name (Ex: enterpriseapplication1) -> next ->finish.
Enterpriseapplication1 tag is appearing in the right side of the net beans pop up window.
Step 2: Right click on the enterpriseapplication1. War -> right click -> new -> jsp -> give File Name
as (for Ex: taxjsp) -> Finish
Taxjsp.jsp program page is opened and then write a below xml program within the body of the
program
<body>
<form action="taxservlet" method="post">
<input type="text" name="t1"/>
<input type="submit" value="ok"/>
</form>
</body>
Step3: Right Click on enterpriseapplication1.ejb -> new -> other -> enterprise java beans
->
session bean -> next -> give the ejb name as (ex: taxbean) and give the package name as session
bean -> stateless check box is defaultly selected and click on local check box
->
finish.
taxbean.java program page is appears and move the cursor inside the
public class tax implements taxLocal
{ -> right click -> insert code -> add business method.
Add business method window is opened.
In name filed type: tax -> click on browser -> find type window is appear -> in the type name field
give: double -> and select Double (java.lang) -> ok -> click on ADD -> write parameters as: a ->
type: double -> ok.
Write a below program:
M.Tech in CNE
2014-15
10
14SCN26
click on deploy
click on run
Web page is opened and select the URL and right click the right arrow in the keyboard, cursor is
moved at the end of URL and type taxjsp.jsp. The output is shown.
Output:
M.Tech in CNE
2014-15
11
14SCN26
M.Tech in CNE
2014-15
12
14SCN26
Program 3: Design and implement an EJB entity bean to persist the client submitted
data into an enterprise information system.
Procedure:
Step 1: Open NetBeans IDE
choose project
Select New
ChooseJavaEE
Select
Enterprise application.
Step 2: Give a name to the project and finish (ex: name
Step 3: Go to Services
test).
Click connects.
finish.
Step 6: The following file is opened. After declaring name and salary
Right click
Insert code
2014-15
13
14SCN26
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof itService)) {
return false;
}
itService other = (itService) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "persist.itService[ id=" + id + " ]";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
M.Tech in CNE
2014-15
14
14SCN26
}
public double calculateTax(){
double t=0;
if(this.salary>=0&&this.salary<=250000)
t=0;
else if(this.salary>250000&&this.salary<=500000)
t=(this.salary-250000)*0.1;
else if(this.salary>500000&&this.salary<=1000000)
t=(this.salary-500000)*0.2+25000;
else if(this.salary>1000000)
t=(this.salary-1000000)*0.3+125000;
return t;
}
}
Step 7: Select New
classes
option
EJB
finish.
2014-15
15
14SCN26
New
Servlet
Right click
Servlet.java (program)
package p1;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import persist.itService;
import persist.itServiceFacadeLocal;
@WebServlet(name = "Servlet", urlPatterns = {"/Servlet"})
public class Servlet extends HttpServlet {
@EJB
private itServiceFacadeLocal itServiceFacade;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
itService obj= new itService();
obj.setName(request.getParameter("name"));
String name= request.getParameter("name");
obj.setSalary(Integer.parseInt(request.getParameter("salary")));
M.Tech in CNE
2014-15
16
14SCN26
itServiceFacade.create(obj);
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Tax calculation</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>congrats user " + request.getParameter("name") + " is created
successfully</h1>");
out.println("<h1>your salary is " + request.getParameter("salary") + " </h1>");
out.println("<h1>tax is " + obj.calculateTax() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
Output:
M.Tech in CNE
2014-15
17
14SCN26
M.Tech in CNE
2014-15
18
14SCN26
M.Tech in CNE
2014-15
19
14SCN26
"destinationType",
propertyValue
"javax.jms.Queue")
}
public class TMDB implements MessageListener {
public TMDB() {
}
@Resource
M.Tech in CNE
2014-15
20
14SCN26
2014-15
21
14SCN26
name the package as ise. Click next to finish. Add the lines shown below.
try{
Context ctx = new InitialContext();
ConnectionFactory connectionFactory =
(ConnectionFactory)ctx.lookup("jms/tConnectionFactory");
Queue
queue = (Queue)ctx.lookup("jms/tQueue");
2014-15
22
14SCN26
M.Tech in CNE
2014-15
23
14SCN26
M.Tech in CNE
2014-15
24
14SCN26
Program 5: Design and implement the client code to call the Microsoft service like free
service from UDDI (Universal Description Discovery Protocol).
UDDI (Universal Description, Discovery, and Integration) is an XML-based registry for businesses
worldwide to list themselves on the Internet. The UDDI specification utilizes World Wide Web
Consortium (W3C) and Internet Engineering Task Force (IETF) standards such as XML, HTTP, and
Domain Name System (DNS) protocols. It has also adopted early versions of the proposed Simple
Object Access Protocol (SOAP) messaging guidelines for cross platform programming.
Procedure:
Server Side:
Step 1: Open New Project from the File menu.
Step 2: Choose Java Web from the categories tab and select Web application from the Project and
click Next.
Step 3: Give Project Name and click next
Step 4: Select the server and click Finish
Step 5: From the source package folder right click and select Web Service.
Step 6: Enter the Web Service Name as "taxcl" and enter package name as pkg and enter finish
Step 7: select design icon then click on "addoperation", in add operation select one number as in
double. Once the method is created, write the logic to calculate tax.
Step 8: Right click on webservice file and then select "Test Web Service".
Client Side:
Step 1: Open New Project from the File menu..
Step 2: Choose Java Web from the categories tab and select Web application from the Project and
click Next
Step 3: Give Project Name and click next
Step 4: Select the server and click Finish
Step 5: From the source package folder right click and select Web Service Client.
Step 6: Select project (taxcl) from Brower web Service.
Step 7: Select jsp page by right click on web page
Step 8: In jsp page, select Webservice client report (call web service operation) by right click on the
page and type below code above try block.
String d = request.getParameter("sala");
double aa = Double.parseDouble(d);
Step 9: First build and deploy the server, then build the client and run the client.
Output:
M.Tech in CNE
2014-15
25
14SCN26
M.Tech in CNE
2014-15
26
14SCN26
Program 6: Design and implement business logic and bind it as service using SOAP
(Simple Object Access Protocol), also implement client to call service.
Procedure:
2014-15
27
14SCN26
}
Step 7: Deploy the server program.
Step 8: Click on Web Service, Right click on SoapWebService and click on Test Web Service.
Step 9: Server program has been done.
Output :
2014-15
28
14SCN26
import java.io.Serializable;
import java.util.Scanner;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class EjbSoapClient implements Serializable {
@Id
private Long id;
static class TaxInformation{
String name;
String income;
}
/*static TaxInformation getInformationFromConsole(){
Scanner scanIn=new Scanner(System.in);
System.out.println("enter your full name");
String name=scanIn.nextLine();
System.out.println("enter your tax");
String income=scanIn.nextLine();
System.out.println();
scanIn.close();
return new TaxInformation(name,income);
}*/
public static void main(String[] args){
Scanner scanIn=new Scanner(System.in);
System.out.println("enter your full name");
String name=scanIn.nextLine();
System.out.println("enter your tax");
String income=scanIn.nextLine();
//TaxInformation info=getInformationFromConsole();
double tax=calculateTax(name, income);
System.out.println("your tax"+tax);
}
private static double calculateTax(String name, String income)
M.Tech in CNE
2014-15
29
14SCN26
{
com.soappackageclient.SoapWebService_Service service1=new
com.soappackageclient.SoapWebService_Service();
System.out.println("webservice client seeking information");
double d=Double.parseDouble(income);
double data=service1.getSoapWebServicePort().calcualteIncomeTax(d);
System.out.println("webserviceclient receving infromation"+data);
return data;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Step 11: Build the Program.
Step 12:Run the jsp file EjbSoapClient.jsp.
Output :
Please enter the name: ABC
Enter Income: 789456
Tax: 82891.2
M.Tech in CNE
2014-15
30
14SCN26
M.Tech in CNE
2014-15
31