39
VISVESVARAYA TECHNOLOGICAL UNIVERSITY BELAGAVI - 590 018 Report On Distributed Computing Laboratory (14SCN26) Submitted in partial fulfillment of the requirements for the award of the degree of Master of Technology in Computer Network Engineering of Visvesvaraya Technological University, Belagavi Submitted by Your Name USN:

14SCN26 DC Lab Manual

Embed Size (px)

DESCRIPTION

VTU M.Tech in CNE DC Lab Manual

Citation preview

14SCN26Distributed Computing LaboratoryVISVESVARAYA TECHNOLOGICAL UNIVERSITYBELAGAVI - 590 018

Report On

Distributed Computing Laboratory (14SCN26)

Submitted in partial fulfillment of the requirements for the award of the degree of Master of Technology in Computer Network Engineering of Visvesvaraya Technological University, Belagavi

Submitted byYour NameUSN:

2014-15

VISVESVARAYA TECHNOLOGICAL UNIVERSITYBELAGAVI - 590 018

CERTIFICATE

Certified that the Distributed Computing Laboratory work (14SCN26) has been successfully completed by Your name bearing USN: a bonafide student of College Institute of Technology in partial fulfillment of the requirements for the second semester in Master of Technology in Computer Network Engineering of Visvesvaraya Technological University, Belagavi during academic year 2014-2015. It is certified that all corrections/suggestions indicated for internal assessment have been incorporated in the report deposited in the departmental library. The laboratory report has been approved as it satisfies the academic requirements in respect of laboratory work for the said degree.

Examiners: 1) 2) ACKNOWLEDGEMENT

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. HalliUSN: 1RN14SCN06

Experiments1. 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.

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(d1250000){ it=d1-250000; it=it*0.1;}else if(d1>500000 && d1 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) -> FinishTaxjsp.jsp program page is opened and then write a below xml program within the body of the program

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: public Double tax(double a) { double t=0; if (a>0 && a250000 && a500000 && a1000000) t=(a-1000000)*0.3+125000; return t; }Step 4: Right click on enterpriseapplication1.war -> new -> servlet -> give class name as: (taxservlet) and package as: (sessionbeans) -> next -> select the add information to deployment descriptor (web.xml) check box -> finish.The taxservlet.java program page is appears. Right click inside public class taxservlet extends HttpServlet{ -> right click -> insert code -> double click on call enterprise bean -> call enterprise bean is appears -> extend the enterpriseapplication1.ejb (by click on + symbol) -> click on taxbean -> OK.In taxservlet.java program add the write following code inside the body:double a=Double.parseDouble.(request.getParameter(t1));Out.println(tax= +taxbean.tax(a) + );Step 5: Right click on enterpriseapplication1 click on deploy click on runWeb 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:

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 test).Step 3: Go to Services Choose Databases and select jdbc:desty:// Click connects.Step 4: Start the Glassfish server.Step 5: From the ejb module (eg: test-ejb),create an entity class. Give itService as a class name and package is persist. Check create persistence unit, click next, and choose jdbc/sample for the data source finish.Step 6: The following file is opened. After declaring name and salary highlight these two lines Right click Insert code Choose Getter and Setter. Change the generated value to IDENTITY from Auto and tick the encapsulate option.itService (program)package persist;import java.io.Serializable;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;@Entitypublic class itService implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; private int salary; public Long getId() { return id; } public void setId(Long id) { 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; } public double calculateTax(){ double t=0; if(this.salary>=0&&this.salary250000&&this.salary500000&&this.salary1000000) t=(this.salary-1000000)*0.3+125000; return t; }} Step 7: Select New option EJB Session Bean for entity class Select and Add all the classes Next Choose Local finish.Step 8: The itService facade is created.Step 9: Select test-war index. jsp index.jsp (program)

Tax calculation name salary TODO write content

Step 10: test-war New Servlet package name is p1 , within public class Right click Insert code call enterprise bean ok (paste the code of Servlet. Java)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"))); itServiceFacade.create(obj); try (PrintWriter out = response.getWriter()) { out.println(""); out.println(""); out.println(""); out.println("Tax calculation"); out.println(""); out.println(""); out.println("congrats user " + request.getParameter("name") + " is created successfully"); out.println("your salary is " + request.getParameter("salary") + " "); out.println("tax is " + obj.calculateTax() + ""); out.println(""); out.println(""); } } @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"; }// }Output:

Program 4: Design and implement an offline database communication system using JMS (Java Message Service) to service the client request.Procedure:Step 1: In the services section, go to server section in that start glassfish server. Then go view domain admin console.Step 2: In admin console click on jms resources go to connection factories, click new and name the JNDI name [jms/tConnection Factory] and set the resource type as [javax.jms.ConnectionFactory].Step 3: Click on destination resource name the JNDI name [jms/tQueue] and set the physical destination name tQueue and set the resource type as java.jms.Queue and click ok.Step 4: Open the new project in Net Beans.Step 5: Go for Java EE in that enterprise application and name the project as jms and click next to finish.Step 6: Right click on jms.ejb and select message driven bean and name it as TMDB and name the package as mdbs. Set the server destination as jms/tQueue and click next to finish.Step 7: Write the below codepackage mdbs;import javax.annotation.Resource;import javax.ejb.ActivationConfigProperty;import javax.ejb.MessageDriven;import javax.ejb.MessageDrivenContext;import javax.jms.JMSException;import javax.jms.Message;import javax.jms.MessageListener;import javax.jms.TextMessage;@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jms/tQueue"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")} public class TMDB implements MessageListener { public TMDB() { } @Resource private MessageDrivenContext mdc; @Override public void onMessage(Message message) { TextMessage msg = null; try { if (message instanceof TextMessage) { msg = (TextMessage) message; System.out.println("A Message received in TMDB: " + msg.getText()); } else { System.out.println("Message of wrong type: " +message.getClass().getName()); } } catch (JMSException e) { e.printStackTrace(); mdc.setRollbackOnly(); } catch (Throwable te) { te.printStackTrace(); } } }Step 8: Right click on jms.war and go to new to get jsp. Name the jsp as newjsp and click finish and add the below lines.

=0 && incomeAmount250000 && incomeAmount500000 && incomeAmount1000000) tax=(incomeAmount-1000000)*0.3+125000; return tax; }}

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 :

SOAP Client PartStep 1: Open New Project from file menu.Choose JavaEE from the categories tab and select EJB module from the Project and click Next.Step 2: Give Project Name and click Next.Step 3: Select the server and click Finish.Step 4:From the source package folder right click and select Web Service Client.Step5: Enter the WebService name and enter package name as com.soappackageclient and enter finish.Step 6: Right Click on source package and select new, in that select Entity Class.Step 7:Give the class name and package as com.soappackageclient ,then Click next.Step 8: Select data source as jdbc/sample and finish. Step 9: Write the client program.SOAP Client Program:package com.soappackageclient;import java.io.Serializable;import java.util.Scanner;import javax.persistence.Entity;import javax.persistence.GeneratedValue;import javax.persistence.GenerationType;import javax.persistence.Id;@Entitypublic 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) { 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: ABCEnter Income: 789456Tax: 82891.2

M.Tech in CNE 2014-1529