MT-LM

51
Dr.NNCE IT / VII Sem MT Lab - LM 1 IT1404 – MIDDLEWARE TECHNOLOGIES LABORAOTY LABORATORY MANUAL FOR VII SEMESTER B.TECH / IT (FOR PRIVATE CIRCULATION ONLY) ANNA UNIVERSITY , CHENNAI DEPARTMENT OF INFORMATION TECHNOLOGY DR.NAVALAR NEDUNCHEZHIAYN COLLEGE OF ENGINEERING, THOLUDUR-606303, CUDDALORE DIST.

description

Middleware Manual

Transcript of MT-LM

  • Dr.NNCE IT / VII Sem MT Lab - LM

    1

    IITT11440044 MMIIDDDDLLEEWWAARREE TTEECCHHNNOOLLOOGGIIEESS LLAABBOORRAAOOTTYY LLAABBOORRAATTOORRYY MMAANNUUAALL

    FFOORR VVIIII SSEEMMEESSTTEERR BB..TTEECCHH // IITT

    ((FFOORR PPRRIIVVAATTEE CCIIRRCCUULLAATTIIOONN OONNLLYY))

    AANNNNAA UUNNIIVVEERRSSIITTYY ,, CCHHEENNNNAAII

    DEPARTMENT OF INFORMATION TECHNOLOGY

    DR.NAVALAR NEDUNCHEZHIAYN COLLEGE OF ENGINEERING,

    THOLUDUR-606303, CUDDALORE DIST.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    2

    GENERAL INSTRUCTIONS FOR LABORATORY CLASSES

    DOS

    o Without Prior permission do not enter into the Laboratory. o While entering into the LAB students should wear their ID cards. o The Students should come with proper uniform. o Students should sign in the LOGIN REGISTER before entering into the laboratory. o Students should come with observation and record note book to the laboratory. o Students should maintain silence inside the laboratory. o After completing the laboratory exercise, make sure to shutdown the system properly.

    DONTS

    o Students bringing the bags inside the laboratory.. o Students wearing slippers/shoes insides the laboratory. o Students using the computers in an improper way. o Students scribbling on the desk and mishandling the chairs. o Students using mobile phones inside the laboratory. o Students making noise inside the laboratory.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    3

    HARDWARE REQUIREMENTS: Intel Pentium 915 GV 80GB SATA II

    512 MB DDR

    SOFTWARE REQUIREMENTS: J2SDK1.4.1, J2EE, J2SDKEE1.2.1, WEBLOGIC 8.0

    UNIVERSITY PRACTICAL EXAMINATION

    ALLOTMENT OF MARKS

    Internal Assessment = 20 Marks Practical Assessment = 80 Marks

    = 100 Marks .

    INTERNAL ASSESSMENT (20 MARKS) Staff should maintain the assessment Register and the Head of the Department should monitor it.

    SPLIT UP OF INTERNAL MARKS

    Observation Note = 3 Marks Record Note = 7 Marks Model Exam = 5 Marks Attendance = 5 Marks Total = 20 Marks

    UNIVERSITY EXAMINATION The exam will be conducted for 100 marks. Then the marks will be calculated to 80 marks.

    SPLIT UP OF PRACTICAL EXAMINATION MARKS Aim and Algorithm = 20 Marks Program = 40 Marks Output = 20 Marks Result = 10 Marks Viva-voce = 10 Marks

    .. 100 Marks .

  • Dr.NNCE IT / VII Sem MT Lab - LM

    4

    LIST OF EXPERIMENTS

    1. Create a distributed application to download various files from various servers using RMI.

    2. Create a java bean to draw various graphical shapes and display it using or without using BDK.

    3. Develop an Enterprise Java Bean for banking operations. 4. Develop an Enterprise Java Bean for Library operations. 5. Create an Active- X control for file operations. 6. Develop a component for converting the currency values using COM/. NET 7. Develop a component for encryption and decryption using COM/. NET 8. Develop a component for retrieving information from message box using

    DCOM/.NET 9. Develop a middleware component for retrieving Stock Market Exchange

    information using CORBA 10. Develop a middleware component for retrieving Weather Forecast information

    using CORBA. 11. Create an application for converting case conversion using IDL

  • Dr.NNCE IT / VII Sem MT Lab - LM

    5

    CONTENTS

    S.No

    LIST OF EXPERIMENTS Page Number

    1 Downloading various files from various servers using RMI

    6

    2 Draw the various graphical shapes and display it using or without using BDK.

    10

    3 Develop an Enterprise Java Bean for Banking Operations.

    14

    4 Develop an Enterprise Java Bean for Library Operations.

    20

    5 Create an Active- X control for File operations

    25

    6 Develop a component for converting the currency values using COM/. NET

    28

    7 Develop a component for encryption and decryption using COM/. NET

    31

    8 Develop a component for retrieving information from message box using DCOM/. NET

    35

    9 Develop a middleware component for retrieving Stock Market Exchange information using CORBA.

    38

    10 Develop a middleware component for retrieving Weather Forecast information using CORBA.

    42

    11 Create an application for converting case conversion using IDL

    47

  • Dr.NNCE IT / VII Sem MT Lab - LM

    6

    Exercise Number: 1

    Title of the Exercise : Download Files from Various Servers Using RMI Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To create a program to download files from various servers using RMI.

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name JAVA

    b) Procedure: Step no.

    Details of the step

    1 Define the interface. 2 Interface must extend Remote 3 All methods must throw an exception Remote Exception individually 4 Implement the interface. 5 Create a server program. 6 Create a Client Program. 7 Generate stubs and skeletons using rmic tool. 8 Start the server. 9 Start the client. 10 Once the process is over stop the client and server respectively

    c) Program: Part 1: Interface Definition: import java.rmi.*; public interface fileinterface extends Remote { public byte[] downloadfile(String s) throws RemoteException; } Part 2: Interface Implementation: import java.io.*; import java.rmi.*; import java.rmi.server.*; public class fileimplement extends UnicastRemoteObject implements fileinterface { private String name; public fileimplement(String s)throws RemoteException { super(); name=s; } public byte[] downloadfile(String fn) {

  • Dr.NNCE IT / VII Sem MT Lab - LM

    7

    try{ File fi=new File(fn); byte buf[]=new byte[(int)fi.length()]; BufferedInputStream bis=new BufferedInputStream(new FileInputStream(fn)); bis.read(buf,0,buf.length); bis.close(); return(buf); } catch(Exception ee) { System.out.println("Error:"+ee.getMessage()); ee.printStackTrace(); return(null);}}} Part 3: Server Part: import java.rmi.*; import java.io.*; import java.net.*; public class fileserver { public static void main(String args[]) { try{ fileimplement fi=new fileimplement("fileserver"); Naming.rebind("//127.0.0.1/fileserver",fi);} catch(Exception e){ System.out.println(" "+e.getMessage()); e.printStackTrace(); }} } Part 4: Client Part: import java.net.*; import java.rmi.*; import java.io.*; public class fileclient { public static void main(String[] args) { try{ InetAddress addr=InetAddress.getLocalHost(); String address=addr.toString().substring(addr.toString().indexOf("/")+1); String url="rmi://"+ address + "/fileserver"; fileinterface f1=(fileinterface)Naming.lookup(url); byte[] data=f1.downloadfile(args[0]); File ff=new File("f1.txt"); BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(ff.getName())); bos.write(data,0,data.length); bos.flush(); bos.close();} catch(Exception e){

  • Dr.NNCE IT / VII Sem MT Lab - LM

    8

    System.out.println(" "+e.getMessage()); e.printStackTrace(); }}} Part 5 Compile all the files as follows C:\WT\rmi>javac *.java C:\WT\rmi> Part 6 Generate stubs and skeletons as follows C:\WT\rmi>rmic fileimplement C:\WT\rmi> Part 7 Start rmiregistry as given below if registry is properly started, a window will be opened C:\WT\rmi>start rmiregistry C:\WT\rmi> Part 8: Start the server C:\WT\rmi>java fileserver Part 9: Start the client C:\WT\rmi>java fileclient c:\WT\corba\StockMarketClient.java C:\WT\rmi>type f1.txt d) Output: Server: D:\>cd MWT\rmi\server D:\MWT\RMI\Server>set path=%path%;c:\j2sdk1.4.1\bin; D:\MWT\RMI\Server>javac *.java D:\MWT\RMI\Server>rmic fileimplement D:\MWT\RMI\Server>start rmiregistry D:\MWT\RMI\Server>java fileserver Client: C:\Documents and Settings\Admin>d: D:\>cd MWT\rmi\client D:\MWT\RMI\Client>set path=%path%;c:\j2sdk1.4.1\bin; D:\MWT\RMI\Client>javac *.java D:\MWT\RMI\Client>java fileclient d:\MWT\rmi\server\fileserver.java D:\MWT\RMI\Client>type f1.txt import java.rmi.*; import java.io.*; import java.net.*; public class fileserver { public static void main(String args[]) { try{ fileimplement fi=new fileimplement("fileserver"); Naming.rebind("//127.0.0.1/fileserver",fi);} catch(Exception e){ System.out.println(" "+e.getMessage()); e.printStackTrace(); }

  • Dr.NNCE IT / VII Sem MT Lab - LM

    9

    } } D:\MWT\RMI\Client> e) Result:

    Thus the program for the download files from various servers using RMI has been successfully executed and verified.

    QUESTIONS WITH ANSWERS 1. What is meant by RMI?

    Remote Method Invocation (RMI) enables the programmer to create distributed Java technology-based to Java technology-based applications, in which the methods of remote Java objects can be invoked from other Java virtual machines*, possibly on different hosts. RMI uses object serialization to marshal and unmarshal parameters and does not truncate types, supporting true object-oriented polymorphism. 2. What are the types of RMI Applications?

    a. Client b. Server

    3. What are the steps are needed to create Distributed application by using RMI? a. Designing and implementing the components of your distributed application. b.Compiling sources. c. Making classes network accessible. d.Starting the application.

    4. List out the steps for designing and implementing remote interfaces. a. Defining the remote interface. b.Implementing the remote objects. c. Implementing the clients.

    5. What is the use of RMI registry? RMI Registry is used finding references to other remote objects. It is a simple remote object naming service that enables clients to obtain a reference to a remote object by name. 6. Define Compute Engine. The Computing Engine is a remote object on the server that takes tasks from clients, runs the tasks, and returns any results. 7. What are the steps are needed to write a RMI Programming?

    a. Designing a remote Interface. b. Implementing a Remote Interface. c. Declaring the Remote Interfaces Being Implemented. d. Defining the Constructor for the Remote Object. e. Providing Implementations for each remote method

  • Dr.NNCE IT / VII Sem MT Lab - LM

    10

    Exercise Number: 2 Title of the Exercise : Create a JAVA Bean to draw various graphical shapes

    Using BDK or without BDK Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To Create a Java Bean to draw various graphical shapes using BDK or without Using BDK.

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name JAVA

    b) Procedure:

    Step no. Details of the step 1 Start the Process.

    2 Set the classpath for java as given below C:\WT\bean>set path=%path%;c:\j2sdk1.4.1\bin; 3 Write the Source code as given below.4 Save the below file as shapes. java 5 compile the file 6 If BDK is not used then execute the file as 7 Stop the process

    c) Program: import java.awt.*; import java.applet.*; import java.awt.event.*; /**/ public class shapes extends Applet implements ActionListener { List list; Label l1; Font f; public void init() { Panel p1=new Panel(); Color c1=new Color(255,100,230); setForeground(c1); f=new Font("Monospaced",Font.BOLD,20); setFont(f); l1=new Label("D R A W I N G V A R I O U S G R A P H I C A L S H A P E S",Label.CENTER); p1.add(l1);

  • Dr.NNCE IT / VII Sem MT Lab - LM

    11

    add(p1,"NORTH"); Panel p2=new Panel(); list=new List(3,false); list.add("Line"); list.add("Circle"); list.add("Ellipse"); list.add("Arc"); list.add("Polygon"); list.add("Rectangle"); list.add("Rounded Rectangle"); list.add("Filled Circle"); list.add("Filled Ellipse"); list.add("Filled Arc"); list.add("Filled Polygon"); list.add("Filled Rectangle"); list.add("Filled Rounded Rectangle"); p2.add(list); add(p2,"CENTER"); list.addActionListener(this); } public void actionPerformed(ActionEvent ae) { repaint(); } public void paint(Graphics g) { int i; Color c1=new Color(255,120,130); Color c2=new Color(100,255,100); Color c3=new Color(100,100,255); Color c4=new Color(255,120,130); Color c5=new Color(100,255,100); Color c6=new Color(100,100,255); if (list.getSelectedIndex()==0)

    { g.setColor(c1); g.drawLine(150,150,200,250);

    } if (list.getSelectedIndex()==1)

    { g.setColor(c2); g.drawOval(150,150,190,190); } if (list.getSelectedIndex()==2) { g.setColor(c3); g.drawOval(290,100,190,130); } if (list.getSelectedIndex()==3) { g.setColor(c4); g.drawArc(100,140,170,170,0,120); } if (list.getSelectedIndex()==4) { g.setColor(c5); int x[]={130,400,130,300,130};

  • Dr.NNCE IT / VII Sem MT Lab - LM

    12

    int y[]={130,130,300,400,130}; g.drawPolygon(x,y,5); } if (list.getSelectedIndex()==5) { g.setColor(Color.cyan); g.drawRect(100,100,160,150); } if (list.getSelectedIndex()==6) { g.setColor(Color.blue) g.drawRoundRect(190,110,160,150,85,85); } if (list.getSelectedIndex()==7) { g.setColor(c2); g.fillOval(150,150,190,190); } if (list.getSelectedIndex()==8) { g.setColor(c3); g.fillOval(290,100,190,130); } if (list.getSelectedIndex()==9) { g.setColor(c4); g.fillArc(100,140,170,170,0,120); } if (list.getSelectedIndex()==10) { g.setColor(c5); int x[]={130,400,130,300,130}; int y[]={130,130,300,400,130}; g.fillPolygon(x,y,5); } if (list.getSelectedIndex()==11) { g.setColor(Color.cyan); g.fillRect(100,100,160,150); } if (list.getSelectedIndex()==12) { g.setColor(Color.blue); g.fillRoundRect(190,110,160,150,85,85); }}} C:\WT\bean>javac shapes.java C:\WT\bean>appletviewer shapes.java d) Output: D:\>cd MWT D:\MWT>set path=%path%;c:\j2sdk1.4.1\bin; D:\MWT>javac shapes.java D:\MWT>appletviewer shapes.java Warning: Can't read AppletViewer properties file: C:\Documents and Settings\Admi n\.hotjava\properties Using defaults.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    13

    e) Result:

    Thus the program for create a Java Bean to draw various graphical shapes using BDK or without Using BDK has been successfully executed and verified.

    VIVA - QUESTIONS 1. What is meant by Applet?

    An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled browser to view a page that contains an applet, the applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM).

    2. What is meant by AWT?

    The AWT stands for Abstract Window ToolKit and it provides the API to create desktop applications in Java. It is also used to create Applets. The AWT based applications can run on all the Java enabled operating systems. The AWT components are heavyweight components and it uses the underlying OS libararies for creating the UI components.

    3. What is meant by swings?

    The Java Swing is also known as Java Foundation Classes (JFC), which is used to create the UI interface for desktop applications and applets. Swing is lightweight component. It runs faster than AWT. Swing is 100% Pure Java certified.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    14

    Exercise Number: 3 Title of the Exercise : Develop a component using EJB for Banking Operations Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To create a component for banking operations using EJB.

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name JAVA, BEA Weblogic 8.1

    b) Procedure:

    Step no. Details of the step 1 Start the process 2 Set path as C:\WT\atm>set path=%path%;c:\j2sdk1.4.1\bin;

    3 Set class path as C:\WT\atm>set classpath=%classpath%;c:\j2sdkee1.2.1\lib\j2ee.jar;

    4 Compile all the files C:\WT\atm\javac *.java

    5 Select Start->Programs->BEA Wblogic Platform 8.1->Other Development Tools->Weblogic Builder.

    6 Select File >Open->atm ->open 7 A window will be displayed indicating the JNDI name

    8 File->Save File->Archive->Save

    9 After getting the successful message goto start programs->BEA weblogic platform 8.1-> user projects->my domain->start server.

    10

    If the server is in running mode without any exception goto internet explorer Type http://localhost:7001/console A window will be displayed which prompt you for the username and password

    11 If the username and password is correct then the page is displayed. In the page select the link EJB Modules which leads to the next page

    12 To check for the successfulness click the required jar file.[Note:- here the file is atm.jar]

    13 If the process is successful then the following message will be displayed

    14 Select the link Test this EJB. The following message will be displayed if successful

    15 The EJB atm2 has been tested successfully with a JNDI name of atm2 Continue

    16 Before running the client set the path as follows C:\WT\atm>set path=%path%c:\j2sdk1.4.1\bin; C:\WT\atm>set classpath=%classpath%;c:\j2sdkee1.2.1\lib\j2ee.jar;

  • Dr.NNCE IT / VII Sem MT Lab - LM

    15

    C:\WT\atm>set classpath=weblogic.jar;%classpath%;

    17 Start the client C:\WT\atm>java atmclient

    c) Program: Define the home interface import javax.ejb.*; import java.io.Serializable; import java.rmi.*; public interface atmhome extends EJBHome { public atmremote create(int accno,String name,String type,float balance)throws RemoteException,CreateException; } Save the above interface as atmhome.java Define the Remote Interface. import java.io.Serializable; import javax.ejb.*; import java.rmi.*; public interface atmremote extends EJBObject { public float deposit(float amt) throws RemoteException; public float withdraw(float amt) throws RemoteException; } Save the remote interface as atmremote.java Write the implementation. import javax.ejb.*; import java.rmi.*; public class atm implements SessionBean { int acno; String name1; String tt; float bal; public void ejbCreate(int accno,String name,String type,float balance) { acno=accno; name1=name; tt=type; bal=balance;} public float deposit(float amt) { return(bal+amt); } public float withdraw(float amt) { return(bal-amt); }

  • Dr.NNCE IT / VII Sem MT Lab - LM

    16

    public atm() {} public void ejbRemove(){} public void ejbActivate(){} public void ejbPassivate(){} public void setSessionContext(SessionContext sc){} } Save the file as atm.java Write the Client part. import javax.rmi.*; import java.util.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; import java.util.*; import java.io.*; import java.net.*; import javax.naming.NamingException; import java.rmi.RemoteException; import javax.ejb.CreateException; import java.util.Properties; public class atmclient { public static void main(String args[]) throws Exception { float bal=0; String tt=" "; Properties props = new Properties(); props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); props.setProperty(InitialContext.PROVIDER_URL, "t3://localhost:7001"); props.setProperty(InitialContext.SECURITY_PRINCIPAL,""); props.setProperty(InitialContext.SECURITY_CREDENTIALS," "); InitialContext initial = new InitialContext(props); Object objref = initial.lookup("atm2"); atmhome home = (atmhome)PortableRemoteObject.narrow(objref,atmhome.class); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int ch=1; String name; int acc; System.out.println("Enter the Details"); System.out.println("Enter the Account Number:"); acc=Integer.parseInt(br.readLine()); System.out.println("Enter Ur Name:"); name=br.readLine(); while(ch

  • Dr.NNCE IT / VII Sem MT Lab - LM

    17

    { System.out.println("\t\tBANK OPERATIONS"); System.out.println("\t\t***************"); System.out.println(""); System.out.println("\t\t1.DEPOSIT"); System.out.println("\t\t2.WITHDRAW"); System.out.println("\t\t3.DISPLAY"); System.out.println("\t\t4.EXIT"); System.out.println("\t\tENTER UR OPTION:"); ch=Integer.parseInt(br.readLine()); switch(ch) { case 1: System.out.println("Enter the Transaction type;"); tt=br.readLine(); atmremote bb= home.create(acc,name,tt,10000); System.out.println("Entering"); System.out.println("Enter the transaction amt:"); float amt=Float.parseFloat(br.readLine()); bal=bb.deposit(amt); System.out.println("Balance after deposit=" +bal); break; case 2: System.out.println("Enter the Transaction type;"); tt=br.readLine(); bb= home.create(acc,name,tt,bal); System.out.println("Entering"); System.out.println("Enter the transaction amt:"); amt=Float.parseFloat(br.readLine()); bal=bb.withdraw(amt); System.out.println("Balance after withdraw" + bal); break; case 3: System.out.println("Status of the Customer"); System.out.println("Account Number:"+acc); System.out.println("Name of the Customer:"+name); System.out.println("Transaction type:"+tt); System.out.println("Balance"+bal); break; case 4: System.exit(0); } //switch }//while }//main }//class

  • Dr.NNCE IT / VII Sem MT Lab - LM

    18

    d) Output:

    D:\>cd MWT\atm D:\MWT\atm>set path=%path%;c:\j2sdk1.4.1\bin; D:\MWT\atm>set classpath=%classpath%;c:\j2sdkee1.2.1\lib\j2ee.jar; D:\MWT\atm>javac *.java D:\MWT\atm>set classpath=weblogic.jar;%classpath%; D:\MWT\atm>java atmclient Enter the Details Enter the Account Number: 1001 Enter Ur Name: Anbu BANK OPERATIONS *************** 1. DEPOSIT 2. WITHDRAW 3. DISPLAY 4. EXIT ENTER UR OPTION: 1 Enter the Transaction type: Cash Entering Enter the transaction amt: 5000 Balance after deposit=15000.0 BANK OPERATIONS *************** 1. DEPOSIT 2. WITHDRAW 3. DISPLAY 4. EXIT ENTER UR OPTION: 3 Status of the Customer Account Number: 1001 Name of the Customer: Anbu Transaction type: 5000 Balance: 15000.0 BANK OPERATIONS *************** 1. DEPOSIT 2. WITHDRAW 3. DISPLAY 4. EXIT ENTER UR OPTION: 2 Enter the Transaction type: Cash Entering Enter the transaction amt: 3000 Balance after withdraw: 12000.0 BANK OPERATIONS *************** 1. DEPOSIT 2. WITHDRAW 3. DISPLAY

  • Dr.NNCE IT / VII Sem MT Lab - LM

    19

    4. EXIT ENTER UR OPTION: 3 Status of the Customer Account Number: 1001 Name of the Customer: Anbu Transaction type: Cash Balance: 12000.0 BANK OPERATIONS ***************

    1. DEPOSIT 2. WITHDRAW

    3. DISPLAY 4. EXIT

    ENTER UR OPTION: 4 e) Result:

    Thus the program for developing a component using EJB for Banking operation has been successfully executed and verified.

    QUESTIONS WITH ANSWERS 1. State the roles of EJB in eco system.

    The Enterprise Java Beans specification identifies the following roles that are associated with a specific task in the development of distributed applications. The Enterprise Bean Provider is typically an expert in the application domain application Assembler is also a domain expert. Deployer is specialized in the installation of applications. EJB Server Provider is an expert in distributed systems, transactions, and security. A Container is a runtime system for one or multiple enterprise beans. It provides the glue between enterprise beans and the EJB server. System Administrator is concerned with a deployed application.

    2. When do you use EJB? EJBs are a good fit if your application has any of these requirements: Scalability: If you have a growing number of users, EJBs let you distribute your applications components across multiple machines with location transparency to clients. Data integrity: EJBs give you easy to use distributed transactions. Variety of clients: If your application will be accessed by a variety of clients, EJBs can be used for storing the business model, and a variety of clients can be used to access the same information.

    3. List any four exception raised in EJB? System Exception- java.rmi.Remote Exception. Application Exception- java.lang. Exception. EJB specific Exception Create Exception Finder Exception.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    20

    Exercise Number: 4 Title of the Exercise : Develop a Component using EJB for Library Operations Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To create a component for Library Operations using EJB.

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name JAVA, BEA Weblogic 8.1

    b) Procedure:

    Step no.

    Details of the step

    1 Start the process 2 Set path as C:\WT\library>set path=%path%;c:\j2sdk1.4.1\bin; 3 Set class path as C:\WT\library>set classpath=%classpath%;c:\j2sdkee1.2.1\lib\j2ee.jar;

    4 Compile all the files C:\WT\library>javac *.java

    5 Select Start->Programs->BEA Wblogic Platform 8.1->Other Development Tools->Weblogic Builder.

    6 Select File >Open->library ->open 7 A window will be displayed indicating the JNDI name

    8 File->Save File->Archive->Save

    9 After getting the successful message goto start programs->BEA weblogic platform 8.1-> user projects->my domain->start server.

    10 If the server is in running mode without any exception goto internet explorer Type http://localhost:7001/console A window will be displayed which prompt you for the username and password

    11 If the username and password is correct then the page is displayed. In the page select the link EJB Modules which leads to the next page

    12 To check for the successfulness click the required jar file.[Note:- here the file is library.jar]

    13 If the process is successful then the following message will be displayed 14 Select the link Test this EJB. The following message will be displayed if successful 15 The EJB library2 has been tested successfully with a JNDI name of library2 Continue

    16

    Before running the client set the path as follows C:\WT\library>set path=%path%c:\j2sdk1.4.1\bin; C:\WT\library>set classpath=%classpath%;c:\j2sdkee1.2.1\lib\j2ee.jar; C:\WT\library>set classpath=weblogic.jar;%classpath%;

    17 Start the client C:\WT\library>java libraryclient

  • Dr.NNCE IT / VII Sem MT Lab - LM

    21

    c) Program: Define the Home Interface import javax.ejb.*;

    import java.io.Serializable; import java.rmi.*; public interface libraryhome extends EJBHome { public libraryremote create(int id,String title,String author,int nc)throws RemoteException,CreateException; } Save the above file as libraryhome.java Define the Remote Interface import java.io.Serializable; import javax.ejb.*; import java.rmi.*; public interface libraryremote extends EJBObject { public boolean issue(int id,String title,String author,int nc) throws RemoteException; public boolean receive(int id,String title,String author,int nc) throws RemoteException; public int ncpy() throws RemoteException;} Save the above file as libraryremote.java Implement the EJB import javax.ejb.*; import java.rmi.*; public class library implements SessionBean { int bkid; String tit; String auth; int nc1; boolean status=false; public void ejbCreate(int id,String title,String author,int nc) { bkid=id; tit=title; auth=author; nc1=nc; } public int ncpy() { return nc1; } public boolean issue(int id,String tit,String auth,int nc) { if(bkid==id) { nc1--; status=true; } else { status=false; } return(status); } public boolean receive(int id,String tit,String auth,int nc) { if(bkid==id) { nc1++; status=true; } else { status=false; } return(status); } public void ejbRemove(){} public void ejbActivate(){} public void ejbPassivate(){}

  • Dr.NNCE IT / VII Sem MT Lab - LM

    22

    public void setSessionContext(SessionContext sc){} } Save the above file as library.java Write the Client Part import javax.rmi.*; import java.util.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.*; import java.util.*; import java.io.*; import java.net.*; import javax.naming.*; import java.rmi.RemoteException; import javax.ejb.CreateException; import java.util.Properties; public class libraryclient { public static void main(String args[]) throws Exception { Properties props = new Properties(); Props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); props.setProperty(InitialContext.PROVIDER_URL, "t3://localhost:7001"); props.setProperty(InitialContext.SECURITY_PRINCIPAL,""); props.setProperty(InitialContext.SECURITY_CREDENTIALS,""); InitialContext initial = new InitialContext(props); Object objref = initial.lookup("library2"); libraryhome home= libraryhome)PortableRemoteObject.narrow(objref,libraryhome.class); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int ch; String tit,auth; int id,nc; boolean st; System.out.println("Enter the Details"); System.out.println("Enter the Account Number:"); id=Integer.parseInt(br.readLine()); System.out.println("Enter The Book Title:"); tit=br.readLine(); System.out.println("Enter the Author:"); auth=br.readLine(); System.out.println("Enter the no.of copies"); nc=Integer.parseInt(br.readLine()); int temp=nc; do { System.out.println("\t\tLIBRARY OPERATIONS"); System.out.println("\t\t***************"); System.out.println(""); System.out.println("\t\t1.ISSUE"); System.out.println("\t\t2.RECEIVE"); System.out.println("\t\t3.EXIT"); System.out.println("\t\tENTER UR OPTION:"); ch=Integer.parseInt(br.readLine()); libraryremote bb= home.create(id,tit,auth,nc); switch(ch) {

  • Dr.NNCE IT / VII Sem MT Lab - LM

    23

    case 1: System.out.println("Entering"); nc=bb.ncpy(); if(nc>0)

    { if(bb.issue(id,tit,auth,nc))

    { System.out.println("BOOK ID IS:"+id); System.out.println("BOOK TITLE IS:"+tit); System.out.println("BOOK AUTHOR IS:"+auth); System.out.println("NO. OF COPIES :"+bb.ncpy()); nc=bb.ncpy(); System.out.println("Sucess"); break; } } else System.out.println("Book is not available"); break; case 2: System.out.println("Entering"); if(temp>nc) { System.out.println("temp"+temp); if(bb.receive(id,tit,auth,nc)) {

    System.out.println("BOOK ID IS:"+id); System.out.println("BOOK TITLE IS:"+tit); System.out.println("BOOK AUTHOR IS:"+auth); System.out.println("NO. OF COPIES :"+bb.ncpy()); nc=bb.ncpy(); System.out.println("Sucess"); break;

    } } else System.out.println("Invalid Transaction"); break; case 3: System.exit(0); } //switch }while(ch0); }//main }//class d) Output: D:\>cd MWT\library D:\MWT\Library>set path=%path%;c:\j2sdk1.4.1\bin; D:\MWT\Library>set classpath=%classpath%;c:\j2sdkee1.2.1\lib\j2ee.jar; D:\MWT\Library>javac *.java D:\MWT\Library>set classpath=weblogic.jar;%classpath%;

  • Dr.NNCE IT / VII Sem MT Lab - LM

    24

    D:\MWT\Library>java libraryclient Enter the Details Enter the Account Number: 1001 Enter the Book Title: c++ Enter the Author: Balagurusamy Enter the no.of copies: 5 LIBRARY OPERATIONS 1. ISSUE 2.RECEIVE 3.EXIT ENTERS UR OPTION: 1 Entering BOOK ID IS: 1001 BOOK TITLE IS: c++ BOOK AUTHOR IS: Balagurusamy NO. OF COPIES: 4 Sucess ENTER UR OPTION: 2 Entering temp5 BOOK ID IS: 1001 BOOK TITLE IS: c++ BOOK AUTHOR IS: Balagurusamy NO. OF COPIES: 5 Sucess ENTER UR OPTION: 3 e) Result:

    Thus the program for developing a component using EJB for Library operation has been successfully executed and verified.

    QUESTIONS WITH ANSWERS 1. List any four exception raised in EJB?

    System Exception- java.rmi.Remote Exception. Application Exception- java.lang. Exception. EJB specific Exception, Create Exception, Finder Exception.

    2. What do you meant by ACL? A list of which entities are allowed to invoke which objects and methods

    3. What is use of EJBObject? A proxy object on the server side that implements a bean remote interface. The EJBObject receives calls from the skeleton and forwards them to the EJB bean implementation.

    4. Define EJB server. An execution environment for EJB containers. The EJB server provides the container

    with access to network services and any other services it needs to perform its tasks. The EJB 1.0 specification does not define the interface between the server and the container, but the basic relationship is that an EJB server contains one or more EJB containers, and each container can contain one or more beans.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    25

    Exercise Number: 5 Title of the Exercise : Create an ActiveX Control for File Operations Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To Create an Activex Control for File Operations

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name Microsoft Visual Studio .Net

    b) Procedure:

    Step no. Details of the step 1 Start the process. 2 Open Visual Studio.net3 File->New->Project->Visual Basic Projects->Windows Control Library4 Rename the Project as actfileoperation and click ok

    5 drag and drop the following control one Label box, one Rich Text Box, four Button

    6 The following code must be included in their respective Button Click Event

    7 Build solution from the Built Menu PART II

    1 Open Visual Studio.net 2 File->New->Project->VisualBasic Projects->Windows Application 3 Rename the Project as actref and click ok

    4 Tools->Add/Remove Tool Box Item and select the tab .NET Framework Components.

    5 Click the Browse Button and open the actfileoperation.dll from (locate the bin folder) and click ok.

    6 Now the user control (FileControl) will be added to Tool Box. 7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5.

    c) Program: Public Class FileControl Inherits System.Windows.Forms.UserControl Dim fname As String

    //new Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click RichTextBox1.Text = "" End Sub //open

  • Dr.NNCE IT / VII Sem MT Lab - LM

    26

    Private Sub Button2_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim of As New OpenFileDialog If of.ShowDialog = DialogResult.OK Then fname = of.FileName RichTextBox1.LoadFile(fname) End If End Sub //save Private Sub Button3_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim sf As New SaveFileDialog If sf.ShowDialog = DialogResult.OK Then fname = sf.FileName RichTextBox1.SaveFile(fname) End If End Sub //font Private Sub Button4_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim fo As New FontDialog If fo.ShowDialog = DialogResult.OK Then RichTextBox1.Font = fo.Font End If End Sub End Class d) Output:

  • Dr.NNCE IT / VII Sem MT Lab - LM

    27

    e) Result: Thus the program for create an Activex control for file operations has been successfully

    executed and verified.

    QUESTIONS WITH ANSWERS 1. What is the advantage of using .NET?

    1. It is a language and platform independent. 2. It support and maps to all languages. 3. The components are created very easily.

    2. List out the characteristics of .NET.

    . NET framework introduce and completely a new model for the programming and deployment of application. . NET can be expanded.

    3. What are the components of .NET? Lit Box Label Textbox Button Static Edit

    4. Define CLR.

    CLR Common Language Runtime It is a multi language execution environment. It described as the execution engine of .NET. It manages the execution of programs.

    5. List out the goals of CLR.

    It supplies manage code with services such as cross language integration, code access security, object lift time management, resource management, type safety, pre-emptive threading, meta data services and debugging & profiling support.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    28

    Exercise Number: 6

    Title of the Exercise : Develop a Component for Currency Conversion Using

    COM/.NET Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To create a component for currency conversion using com/.net.

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name Microsoft Visual Studio .Net

    b) Procedure:

    Step no. Details of the step PART I CREATE A COMPONENT

    1 Start the process 2 open VS .NET

    3 File-> New-> Project-> visual Basic Project -> class library, rename the class Library as conversion.

    4 Include the following coding in the class Library

    5 Build->Build the solution Note: Register the dll using regsvr32 tool or copy the dll to c:\windows\system32.

    PART II REFERENCING THE COMPONENT 6 Start the process 7 open VS .NET

    8 File-> New-> Project-> visual Basic Project -> Windows Application, rename the Windows Application as currency.

    9 Project -> Add Reference choose the com tab->Browse the dollartorupees.dll and click ok

    10 drag and drop the following controls in the form 2 Label Boxes, 1 Text box, 4 Buttons

    11 Include the coding in each of the Respective Button click Event. 12 Execute the project.

    c) Program: CREATE A COMPONENT Public Class Class1 Public Function dtor(ByVal rup As Double) As Double Dim res As Double res = rup * 47 Return (res) End Function Public Function etor(ByVal rup As Double) As Double Dim res As Double res = rup * 52 Return (res) End Function

  • Dr.NNCE IT / VII Sem MT Lab - LM

    29

    Public Function rtod(ByVal rup As Double) As Double Dim res As Double res = rup / 47 Return (res) End Function Public Function rtoe(ByVal rup As Double) As Double Dim res As Double res = rup / 52 Return (res) End Function End Class REFERENCING THE COMPONENT Imports conversion Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim obj As New convclass Dim ret As Double ret = obj.dtor(CDbl(TextBox1.Text)) MsgBox("The Equivalent Rupees for the given dollar" + ret.ToString()) End Sub Private Sub Button2_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim obj As New convclass Dim ret As Double ret = obj.etor(CDbl(TextBox1.Text)) MsgBox("The Equivalent Rupees for the given euro" + ret.ToString()) End Sub Private Sub Button4_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim obj As New convclass Dim ret As Double ret = obj.rtod(CDbl(TextBox1.Text)) MsgBox("The Equivalent Dollar Amount for the given rupees" + ret.ToString())

    End Sub Private Sub Button3_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim obj As New convclass Dim ret As Double ret = obj.rtoe(CDbl(TextBox1.Text)) MsgBox("The Equivalent Euro Amount for the given rupees" + ret.ToString()) End Sub End Class

  • Dr.NNCE IT / VII Sem MT Lab - LM

    30

    d) Output:

    e) Result:

    Thus the above program is used to develop a component for currency conversion using COM/.Net and it is executed successfully. QUESTIONS WITH ANSWERS 1. What is meant by DLL?

    DLL (dynamic link library) file containing the executable routines of a program. These files give functionality to other programs. They usually need to be installed into the WINDOWS/SYSTEM directory.

    2. What is the advantage of using .NET? 1. It is a language and platform independent. 2. It support and maps to all languages. 3. The components are created very easily.

    3. List out the characteristics of .NET. . NET framework introduce and completely a new model for the programming and deployment of application. . NET can be expanded.

    4. What are the components of .NET? Lit Box >Label >Textbox >Button >Static >Edit

    5. Define CLR. CLR Common Language Runtime >It is a multi language execution environment. It described as the execution engine of .NET. >It manages the execution of programs.

    6. List out the goals of CLR. It supplies manage code with services such as cross language integration, code access

    security, object lift time management, resource management, type safety, pre-emptive threading, meta data services and debugging & profiling support.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    31

    Exercise Number: 7 Title of the Exercise : Develop a Component for Cryptography Using COM/.NET Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To Develop a component for cryptography using COM/.NET

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name Microsoft Visual Studio .Net

    b) Procedure:

    Step no.

    Details of the step

    PART I CREATE A COMPONENT 1 Start the process 2 open VS .NET 3 File-> New-> Project-> visual Basic Project -> class library, rename the class

    Library as encode. 4 Include the following coding in the class Library 5 Build->Build the solution

    Note: Register the dll using regsvr32 tool or copy the dll to c:\windows\system32.PART II REFERENCING THE COMPONENT

    6 Start the process 7 open VS .NET

    8 File-> New-> Project-> visual Basic Project -> Windows Application, rename the Windows Application as decode.

    9 Project -> Add Reference choose the com tab->Browse the encode.dll and click ok

    10 Drag and Drop the following controls in the form 2 Label Boxes, 1 Text box, 3 Buttons

    11 Include the coding in each of the Respective Button click Event. 12 Execute the project.

    c) Program: PART I CREATE A COMPONENT Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long

  • Dr.NNCE IT / VII Sem MT Lab - LM

    32

    Public Function enco(ByVal pa As String) As String pa1 = pa pa = "" For i = 0 To pa1.Length - 1 ct = Convert.ToInt64(Convert.ToChar(pa1.Substring(i, 1))) ct = ct + ct pa = pa + Convert.ToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa pa = "" For i = 0 To pa1.Length - 1 ct = Convert.ToInt64(Convert.ToChar(pa1.Substring(i, 1))) ct = ct / 2 pa = pa + Convert.ToChar(ct) Next Return (pa) End Function End Class PART II REFERENCING THE COMPONENT Imports encode Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.Text = "" End Sub Private Sub ENCRYPT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ENCRYPT.Click Dim obj As New encode.Class1 Dim temp As String temp = TextBox1.Text TextBox1.Text = obj.enco(temp) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim obj As New encode.Class1 Dim temp1 As String temp1 = TextBox1.Text

  • Dr.NNCE IT / VII Sem MT Lab - LM

    33

    TextBox1.Text = obj.deco(temp1) End Sub End Class d) Output:

  • Dr.NNCE IT / VII Sem MT Lab - LM

    34

    e) Result:

    Thus the above program is used to develop a component for cryptography using COM/.Net and it is executed successfully. QUESTIONS WITH ANSWERS 1. What is meant by DLL?

    DLL (dynamic link library) file containing the executable routines of a program. These files give functionality to other programs. They usually need to be installed into the WINDOWS/SYSTEM directory.

    2. What is the advantage of using .NET?

    It is a language and platform independent. It support and maps to all languages. The components are created very easily.

    3. List out the characteristics of .NET.

    . NET framework introduce and completely a new model for the programming and deployment of application. . NET can be expanded.

    4. What are the components of .NET? Lit Box Label Textbox Button Static Edit

    5. Define CLR.

    CLR Common Language Runtime It is a multi language execution environment. It described as the execution engine of .NET. It manages the execution of programs.

    6. List out the goals of CLR.

    It supplies manage code with services such as cross language integration, code access security, object lift time management, resource management, type safety, pre-emptive threading, meta data services and debugging & profiling support.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    35

    Exercise Number: 8

    Title of the Exercise : Develop a component to retrieve Message Box

    Information Using DCOM/.NET Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To create a component to retrieve message box information using DCOM/.NET

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name Microsoft Visual Studio .Net

    b) Procedure: Step no. Details of the step

    PART I 1 Start the process. 2 Open Visual Studio. NET. 3 Goto File->New->Project->ClassLibrary|Empty Library->OK

    4 Goto Solution Explorer->Right Click->Add->Add Component|Add New Item->COM Class-_OK

    5 Add the following codings Save & Build. PART II

    1

    Go To Start->Microsoft Visual.Net 2003->Visual Stufio.Net tools->Command prompt Setting environment for using Microsoft Visual Studio .NET 2003 tools. (If you have another version of Visual Studio or Visual C++ installed and wish to use its tools from the command line, run vcvars32.bat for that version.) C:\Documents and Settings\administrator>sn -k ms.snk Microsoft (R) .NET Framework Strong Name Utility Version 1.1.4322.573 Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. Key pair written to ms.snk C:\Document and Settings\administrator> Copy ms.snk to bin directory (locate the class library)

    2

    start -> settings -> control panel->administrative tools->component services-> computer->my computer->com + Application -> new -> application ->next -> create an empty application-> choose the server Application -> enter the new Application name (mssg) -> next ->choose the interactive user-> next->finish.

    3 expand mssg -> click the components ->right click -> new-> component -> next->install new event classes-> select the class library1.tlb(class library->bin->open->next->finish.

    PART III1 Open Visual studio .net -> file-> new ->Project->Windows Application

  • Dr.NNCE IT / VII Sem MT Lab - LM

    36

    2 Create one label box,one text box and one button in the form. 3 Include the following code in the Button click event 4 execute the project

    c) Program: PART-I Public Function test () As String Dim str = "Hai MiddleWare Technology" Return (str) End Function Public Function create () As String MsgBox(test()) End Function PART-III Imports msg Public Class Form1 Inherits System.Windows.Forms.Form Dim mo As New msg.ComClass1 Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click textbox1.text = mo.test() End Sub End Class d) Output:

  • Dr.NNCE IT / VII Sem MT Lab - LM

    37

    e) Result:

    Thus the above program is used to develop a component to retrieve message box information using DCOM/.Net and it is executed successfully.

    QUESTIONS WITH ANSWERS 1. What do you mean by COM?

    COM is not a programming language but is a set of specification for developing object oriented distributed application. COM components have the following advantages. 1. Language Independent. 2. Supports version compatibility. 3. Provides location transparency.

    2. Define Iunknown. All COM components must (at the very least) implement the standard Iunknown interface, and thus all COM interfaces are derived from IUnknown. The IUnknown interface consists of three methods: AddRef() and Release(), which implement reference counting and controls the lifetime of interfaces; and QueryInterface(), which by specifying an IID allows a caller to retrieve references to the different interfaces the component implements. 3. What are the types of Iunknown methods? AddRef()- Increments the reference count for an interface on an object. Query Interface ()- Retrieves pointer to the supported interfaces on an object. Release()- Decrements the reference count for an interface on an object. 4. What is the use of AddRef method? The purpose of AddRef() is to indicate to the COM object that an additional reference to itself has been affected and hence it is necessary to remain alive as long as this reference is still valid. 5. What is need of Query Interface method? It is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements. 6. What is purpose of using Release ()? The purpose of Release () is to indicate to the COM object that a client (or a part of the client's code) has no further need for it and hence if this reference count has dropped to zero, it may be time to destroy itself.

    7. What is use of CreateInstance()? CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID. 8. What is the use of CoCreateInstance()? The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the object's class factory. CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the object's class factory and then use the class factory's CreateInstance() method to create the COM object. 9. Write a short note on Class Factory. A Class Factory is itself a COM object. It is an object that must expose the IClassFactory or IClassFactory2 (the latter with licensing support) interface. The responsibility of such an object is to create other objects.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    38

    Exercise Number: 9

    Title of the Exercise : Develop a Component for Retrieving Stock Market

    Exchange Information Using CORBA Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To Create a Component for retrieving stock market exchange information using CORBA.

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name JAVA

    b) Procedure: Step no. Details of the step

    1 Define the IDL interface 2 Implement the IDL interface using idlj compiler 3 Create a Client Program 4 Create a Server Program 5 Start orbd. 6 Start the Server. 7 Start the client

    c) Program: Define IDL Interface module simplestocks{ interface StockMarket { float get_price(in string symbol); }; }; Note: Save the above module as simplestocks.idl Compile the saved module using the idlj compiler as follows . C:\WT\corba>idlj simplestocks.idl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed below. C:\WT\corba>idlj fall simplestocks.idl C:\WT\corba>cd simplestocks C:\WT\corba\simplestocks>dir Volume in drive C has no label. Volume Serial Number is 348A-27B7 Directory of C:\suji\corba\simplestocks 02/06/2007 11:38 AM .

  • Dr.NNCE IT / VII Sem MT Lab - LM

    39

    02/06/2007 11:38 AM .. 02/06/2007 11:38 AM 2,071 StockMarketPOA.java 02/07/2007 02:15 PM 2,090 _StockMarketStub.java 02/07/2007 02:15 PM 865 StockMarketHolder.java 02/07/2007 02:15 PM 2,043 StockMarketHelper.java 02/07/2007 02:15 PM 359 StockMarket.java 02/07/2007 02:15 PM 339 StockMarketOperations.java 02/07/2007 02:08 PM 226 StockMarket.class 02/07/2007 02:08 PM 180 StockMarketOperations.class 02/07/2007 02:08 PM 2,818 StockMarketHelper.class 02/07/2007 02:08 PM 2,305 _StockMarketStub.class 02/06/2007 11:44 AM 2,223 StockMarketPOA.class 11 File(s) 15,519 bytes 2 Dir(s) 6,887,636,992 bytes free C:\WT\corba\simplestocks> // Implement the interface import org.omg.CORBA.*; import simplestocks.*; public class StockMarketImpl extends StockMarketPOA{ private ORB orb; public void setORB(ORB v){orb=v;} public float get_price(String symbol) { float price=0; for(int i=0;i

  • Dr.NNCE IT / VII Sem MT Lab - LM

    40

    System.out.println("StockMarket server is ready"); //Thread.currentThread().join(); orb.run();}catch(Exception e){ e.printStackTrace();}}} // Client Program import org.omg.CORBA.*; import org.omg.CosNaming.*; import simplestocks.*; import org.omg.CosNaming.NamingContextPackage.*; public class StockMarketClient{ public static void main(String[] args) { try { ORB orb=ORB.init(args,null); NamingContextExt ncRef=NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService")) //NameComponent path[]={new NameComponent("NASDAQ","")}; StockMarket market=StockMarketHelper.narrow(ncRef.resolve_str("StockMarket")); System.out.println("Price of My company is"+market.get_price("My_COMPANY"));} catch(Exception e){ e.printStackTrace();}}} Compile the above files as C:\WT\corba>javac *.java C:\WT\corba>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost

    C:\WT\corba>start java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost localhost C:\WT\corba> StockMarket server is ready C:\WT\corba>java StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost d) Output: Server

  • Dr.NNCE IT / VII Sem MT Lab - LM

    41

    D:\>cd MWT\corbastock D:\MWT\CorbaStock>set path="c:\j2sdk1.4.1\bin"; D:\MWT\CorbaStock>idlj simplestocks.idl D:\MWT\CorbaStock>idlj -fall simplestocks.idl D:\MWT\CorbaStock>javac *.java D:\MWT\CorbaStock>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost D:\MWT\CorbaStock>java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost localhost StockMarket server is ready Client D:\MWT\CorbaStock>java StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost Price of My Company is: 165.6 D:\MWT\CorbaStock> e) Result:

    Thus the above program is used to develop a component for retrieving stock market exchange information using CORBA and it is executed successfully.

    QUESTIONS WITH ANSWERS 1. Differentiate Between RMI and CORBA. RMI is completely Java based, where CORBA is language independent. There are many adapters for CORBA, and programs can call processes written in any language that has a CORBA interface. CORBA has many more features documented in the specification than just process communication. RMI is easier to implement if you already know Java - it looks just the same as calling a process locally - but it's limited to only calling other Java applications. 2. List out the characteristics of CORBA. CORBA IDL Dynamic invocation Portable object adapter Interoperability COM/ CORBA Bridging Multiple Programming Mapping.

    3. What is the advantage of using CORBA? Language Independence OS Independence Freedom from Technologies Strong data typing High tune ability Freedom from data transfer details Compression

    4. What is the use of ORB? It provides a mechanism for communication between client request and server response. It is responsible for finding object implementation, deliver, request of object and retrieving and responding to caller. 5. Define DII.

    DII stands for Dynamic Innovation Interface. 6. What is the use of ORB Interface?

    It is use to converts object reference to string and string to object reference. 7. What is the use of IDL Compiler?

    It is used to transformation between IDL definition and target programming language. 8. What do you meant by GIOP? The GIOP stands for General Inter-ORB Protocol. It is a high level standard protocol for communication between ORBs.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    42

    Exercise Number: 10

    Title of the Exercise : Develop a Component for Retrieving Weather Forecast

    Information Using CORBA Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To Create a Component for retrieving stock market exchange information using CORBA

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name JAVA

    b) Procedure:

    Step no. Details of the step 1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd. 6 Start the Server. 7 Start the client

    c) Program: Define IDL Interface module weather{ interface forecast { float get_min(); float get_max();};}; Note: Save the above module as weather.idl Compile the saved module using the idlj compiler as follows . C:\WT\weather>idlj weather.idl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed below. C:\WT\weather>idlj fall weather.idl C:\WT\weather>cd weather C:\WT\weather\weather>dir Volume in drive C has no label. Volume Serial Number is 348A-27B7 Directory of C:\WT\weather\weather 03/14/2007 02:52 PM .

  • Dr.NNCE IT / VII Sem MT Lab - LM

    43

    03/14/2007 02:52 PM .. 03/14/2007 02:55 PM 2,240 forecastPOA.java 03/14/2007 02:55 PM 2,729 _forecastStub.java 03/14/2007 02:55 PM 796 forecastHolder.java 03/14/2007 02:55 PM 1,926 forecastHelper.java 03/14/2007 02:55 PM 330 forecast.java 03/14/2007 02:55 PM 319 forecastOperations.java 03/15/2007 10:42 AM 2,144 forecastPOA.class 03/15/2007 10:42 AM 167 forecastOperations.class 03/15/2007 10:42 AM 207 forecast.class 03/15/2007 10:42 AM 2,724 forecastHelper.class 03/15/2007 10:42 AM 2,403 _forecastStub.class 11 File(s) 15,985 bytes 2 Dir(s) 1,726,103,552 bytes free C:\WT\weather\weather> // Implement the interface import org.omg.CORBA.*; import weather.*; import java.util.*; public class weatherimpl extends forecastPOA { private ORB orb; int r[]=new int[10]; float s[]=new float[10]; Random rr=new Random(); public void setORB(ORB v){orb=v;} public float get_min() { for(int i=0;i

  • Dr.NNCE IT / VII Sem MT Lab - LM

    44

    for(int i=1;i

  • Dr.NNCE IT / VII Sem MT Lab - LM

    45

    ORB orb=ORB.init(args,null); NamingContextExt ncRef=NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService")); forecast fr=forecastHelper.narrow(ncRef.resolve_str("forecast")); System.out.println("\t\t\tW E A T H E R F O R E C A S T"); System.out.println("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println(); System.out.println("\tDATE TIME CITY HIGHEST LOWEST "); System.out.println("\t TEMPERATURE TEMPERATURE"); for(int i=0;ijavac *.java C:\WT\weather>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost

    C:\WT\corba>start java weatherserver -ORBInitialPort 1050 -ORBInitialHost localhost C:\WT\weather> weather server is ready C:\WT\corba>java weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost C:\WT\weather>java weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost d) Output: Server D:\>cd MWT\corbaweather D:\MWT\CorbaWeather>set path="c:\j2sdk1.4.1\bin"; D:\MWT\CorbaWeather>javac *.java D:\MWT\CorbaWeather>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost D:\MWT\CorbaWeather>java weatherserver -ORBInitialPort 1050 -ORBInitialHost localhost Weather server is ready Client

  • Dr.NNCE IT / VII Sem MT Lab - LM

    46

    D:\MWT\CorbaWeather>set path="c:\j2sdk1.4.1\bin"; D:\MWT\CorbaWeather>java weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost W E A T H E R F O R E C A S T ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DATE TIME CITY HIGHEST LOWEST TEMPERATURE TEMPERATURE 442011 11 Chennai 17.0 7.0 442011 11 Trichy 16.0 9.0 442011 11 Madurai 17.0 8.0 442011 11 Coimbatore 16.0 7.0 442011 11 Salem 17.0 7.0 D:\MWT\CorbaWeather> e) Result:

    Thus the above program is used to develop a component for retrieving weather forecast information using CORBA and it is executed successfully.

    QUESTIONS WITH ANSWERS 1. List out the types of Adapter.

    Basic Object Adapter Portable Object Adapter Library Object Adapter Object Oriented Data base Adapter

    2. List out the types of Activation Polices in BOA. Shared Server Unshared server Server-per-method Persistent server

    3. What do you meant by socket? Socket is an object; it used to communicate between client and server.

    4. What is the use of object handles? Object handles are used to reference object instances in a programming language context.

    In C++ - The handles are called Object reference. 5. Define Naming service. It is an application that runs as a background process on a remote server at well-known end points. This service is responsible for maintaining a look up table for all of the services running in the distributed computer. 6. Define Marshalling. It refers to the process of translating input parameters to a format that can be transmitted across a network. 7. Define unmarshalling.

    It is the reverse of marshalling this process converts a data into output parameters.

  • Dr.NNCE IT / VII Sem MT Lab - LM

    47

    Exercise Number: 11 Title of the Exercise : Develop a Component for Case Conversion Date of the Exercise :

    OBJECTIVE (AIM) OF THE EXPERIMENT To create a component for currency conversion using com/.net.

    FACILITIES REQUIRED AND PROCEDURE a) Facilities Required:

    S.No. Facilities required Quantity 1 System 1 2 O/S Windows XP 3 S/W name JAVA

    b) Procedure: Step no. Details of the step

    1 Set class path and path for the directory 2 Type the program separately for client and server 3 Initialize the CORBA by starting server 4 Initialize IDL 5 Switch statement for option to perform conversion 6 Start the Server. 7 Start the client

    c) Program: //change.idl interface change { string changelowercase(in string a); string changeuppercase(in string b); }; //casesever.java import java.io.*; import org.omg.CORBA.*; import org.omg.PortableServer.*; public class caseserver extends changePOA { private String s; public String changeuppercase(String a) { return (a.toUpperCase()); } public String changelowercase(String a) { return (a.toLowerCase()); }

  • Dr.NNCE IT / VII Sem MT Lab - LM

    48

    public static void main(String args[]) { try { ORB orb=ORB.init(args,null); caseserver cobj=new caseserver(); POA poa=POAHelper.narrow(orb.resolve_initial_references("RootPOA")); poa.the_POAManager().activate(); org.omg.CORBA.Object obj=poa.servant_to_reference(cobj); System.out.println(orb.object_to_string(obj)); orb.run(); } catch(Exception e) {} } } //caseclient.java import java.io.*; import org.omg.CORBA.*; public class caseclient { public static void main(String args[]){ try{ ORB orb=ORB.init(args,null); org.omg.CORBA.Object obj=orb.string_to_object(args[0]); change cca=changeHelper.narrow(obj); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); if(cca==null){ System.out.println("Incorrect IOR..."); System.exit(1);} String opt="yes"; String s; do { System.out.println("Enter Your Choice: "); System.out.println("1.TO UPPERCASE"); System.out.println("2.TO lowercase"); System.out.println("3.EXIT"); System.out.println("OPTION: "); int i=Integer.parseInt(br.readLine()); switch(i) { case 1: System.out.println(" ENTER THE STRING: "); s=br.readLine(); System.out.println("CASE CHANGED STRING IS: "+cca.changeuppercase(s)); break; case 2:

  • Dr.NNCE IT / VII Sem MT Lab - LM

    49

    System.out.println(" ENTER THE STRING: "); s=br.readLine(); System.out.println("CASE CHANGED STRING IS: "+cca.changelowercase(s)); break; case 3: System.out.println(" EXITING... "); System.exit(1); }System.out.println(" DO U WANT TO CONTINUE:.. yes/no"); opt=br.readLine(); } while(opt.equals("yes"));} catch(Exception e) {} }} d) Output SERVER C:\>cd j2sdk1.4.1\bin\cc C:\j2sdk1.4.1\bin\cc>set path=c:\j2sdk1.4.1\bin C:\j2sdk1.4.1\bin\cc>set classpath=.;c:\j2sdk1.4.1\bin C:\j2sdk1.4.1\bin\cc>idlj -fall change.idl C:\j2sdk1.4.1\bin\cc>javac caseserver.java C:\j2sdk1.4.1\bin\cc>java caseserver IOR:000000000000000e49444c3a636f696e743a312e3000000000000001000000000000006c000102000000000d3139322e3136382e302e31360000043800000021afabcb0000000020b06e01b600000001000000000000000000000004000000000a0000000000000100000001000000200000000000010001000000020501000100010020000101090000000100010100 (Copy the IOR and paste in notepad) C:\j2sdk1.4.1\bin\cc>java caseserver >out2 //out.bat (copy it in a single line) java coinclient IOR:000000000000000e49444c3a636f696e743a312e3000000000000001000000000000006c000102000000000d3139322e3136382e302e31360000043800000021afabcb0000000020b06e01b600000001000000000000000000000004000000000a0000000000000100000001000000200000000000010001000000020501000100010020000101090000000100010100 CLIENT C:\>cd j2sdk1.4.1\bin\cc C:\j2sdk1.4.1\bin\cc>set path=c:\j2sdk1.4.1\bin C:\j2sdk1.4.1\bin\cc>set classpath=.;c:\j2sdk1.4.1\bin C:\j2sdk1.4.1\bin\cc>javac caseclient.java C:\j2sdk1.4.1\bin\cc>out2.bat C:\j2sdk1.4.1\bin\cc>java caseclient IOR:000000000000000f49444c3a6368616e67653a3 12e30000000000001000000000000006c000102000000000d3139322e3136382e302e31360000043700000021afabcb0000000020ab59024b00000001000000000000000000000004000000000a0

  • Dr.NNCE IT / VII Sem MT Lab - LM

    50

    000000000000100000001000000200000000000010001000000020501000100010020000101090000000100010100 Enter Your Choice: 1.TO UPPERCASE 2.TO lowercase 3.EXIT OPTION: 1 ENTER THE STRING: Infotech CASE CHANGED STRING IS: INFOTECH Enter Your Choice: 1.TO UPPERCASE 2.TO lowercase 3.EXIT OPTION:3 EXITING C:\j2sdk1.4.1\bin\cc> e) Result

    Thus the creation of a component for currency conversion using com/.net was done QUESTIONS WITH ANSWERS 1. What is IDL Interface?

    The IDL interface defines the exposed details of distributed objects. Each IDL interface

    defines a new object type. The operation signatures are the essence of the interface. These are the

    entry points for service requests. IDL interface is that it specifies a software boundary between a

    service implementation and its clients.

    2. What is CORBA? CORBA stands for Common Object Request Broker Architecture which is a Middleware

    between Client and Server in Distributed Architecture. CORBA provides language

    independence by defining object interface in a language-independent manner

  • Dr.NNCE IT / VII Sem MT Lab - LM

    51

    IT1404 - MIDDLEWARE TECHNOLOGIES LABORATORY

    MODEL QUESTION SET

    1. Write a Program in java to download files from various servers using RMI. 2. Write a program in java bean to draw the following shapes.

    i. Line ii. Filled Arc

    iii. Ellipse iv. Circle v. Polygon

    3. Write a program in java bean to draw the following shapes. i. Filled Circle

    ii. Filled Ellipse iii. Filled Polygon iv. Arc v. Rounded Rectangle

    4. Develop an Enterprise Java Bean for Banking operations.

    5. Develop an Enterprise Java Bean for Library operations.

    6. Create an ActiveX control for File operations

    7. Develop a component for Currency Conversion using COM / .NET

    8. Develop a component for Encryption and decryption using COM / .NET

    9. Develop a component for retrieving information from message box using DCOM / .NET

    10. Develop a component for retrieving Stock Market Exchange information using CORBA.

    11. Develop a component for retrieving Weather Forecast information using CORBA.