files cse manual vii it1404 - middleware technologies laboratory.doc

49
SUDHARSAN ENGINEERING COLLEGE SATHIYAMANGALAM – 622 501 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING LAB MANUAL NAME :G.DINESH KUMAR DESIGNATION :ASST. PROFESSOR / CSE SUBJECT CODE :IT1404 SUBJECT NAME :MIDDLEWARE TECHNOLOGY LAB YEAR/SEM : IV/07

Upload: lalith-kartikeya

Post on 28-Dec-2015

97 views

Category:

Documents


1 download

DESCRIPTION

Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.docFiles CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

TRANSCRIPT

Page 1: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM ndash 622 501

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

LAB MANUAL

NAME GDINESH KUMAR

DESIGNATION ASST PROFESSOR CSE

SUBJECT CODE IT1404

SUBJECT NAME MIDDLEWARE TECHNOLOGY LAB

YEARSEM IV07

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 DCOMNET

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

2

ExNo 1

DOWNLOAD FILES FROM VARIOUS SERVERS USING RMI

AIM To Create a program to download files from various servers using RMI

DESCRIPTION1 Define the interface2 Interface must extend Remote3 All methods must throw an exception RemoteException individually4 Implement the interface5 Create a server program6 Create a Client Program7 Generate stubs and skeletons using rmic tool8 Start the server9 Start the client10 Once the process is over stop the client and server respectively

PROGRAM

Part 1 Interface Defintion

import javarmipublic interface fileinterface extends Remote public byte[] downloadfile(String s) throws RemoteException

Part 2 Interface Implementationimport javaioimport javarmiimport javarmiserverpublic class fileimplement extends UnicastRemoteObject implements fileinterface private String name public fileimplement(String s)throws RemoteException super() name=s public byte[] downloadfile(String fn) try File fi=new File(fn) byte buf[]=new byte[(int)filength()] BufferedInputStream bis=new BufferedInputStream(new FileInputStream(fn))

3

bisread(buf0buflength) bisclose() return(buf) catch(Exception ee) Systemoutprintln(Error+eegetMessage()) eeprintStackTrace() return(null)

Part 3 Server Part

import javarmiimport javaioimport javanetpublic class fileserverpublic static void main(String args[])tryfileimplement fi=new fileimplement(fileserver)Namingrebind(127001fileserverfi)catch(Exception e)Systemoutprintln( +egetMessage())eprintStackTrace()

Part 4 Client Part

import javanetimport javarmiimport javaiopublic class fileclient public static void main(String[] args) try InetAddress addr=InetAddressgetLocalHost() String address=addrtoString()substring(addrtoString()indexOf()+1) String url=rmi+ address + fileserver fileinterface f1=(fileinterface)Naminglookup(url) byte[] data=f1downloadfile(args[0]) File ff=new File(f1txt) BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(ffgetName())) boswrite(data0datalength) bosflush()

4

bosclose() catch(Exception e) Systemoutprintln( +egetMessage()) eprintStackTrace()

Part ndash5 Compile all the files as follows

Csowmirmigtjavac javaCsowmirmigtPart ndash 6 Generate stubs and skeletons as follows Csowmirmigtrmic fileimplementCsowmirmigtPart ndash 7 Start rmiregistry as given below If registry is properly started a window will be opened

Csowmirmigtstart rmiregistryCsowmirmigtPart ndash 8 Start the serverCsowmirmigtjava fileserverPart ndash 9 Start the clientCsowmirmigtjava fileclient cdevicorbaStockMarketClientjavaCsowmirmigttype f1txt

RESULT

Thus the RMI Program was created and executed successfully

5

Ex No 2

CREATE A JAVA BEAN TO DRAW VARIOUS GRAPHICAL SHAPES USING BDK OR WITHOUT BDK

AIM To Create a Java Bean to draw various graphical shapes using BDK or without Using BDK

DESCRIPTION

1 Start the Process2 Set the classpath for java as given below

Cdevibeangtset path=pathcj2sdk141bin

3 Write the Source code as given below

PROGRAM

import javaawtimport javaappletimport javaawteventltapplet code=shapes width=400 height=400gtltappletgtpublic class shapes extends Applet implements ActionListener List list Label l1 Font f public void init() Panel p1=new Panel() Color c1=new Color(255100230) setForeground(c1)

f=new Font(MonospacedFontBOLD20) 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 SLabelCENTER) p1add(l1) add(p1NORTH)

Panel p2=new Panel() list=new List(3false) listadd(Line)

6

listadd(Circle) listadd(Ellipse) listadd(Arc) listadd(Polygon) listadd(Rectangle) listadd(Rounded Rectangle) listadd(Filled Circle) listadd(Filled Ellipse) listadd(Filled Arc) listadd(Filled Polygon) listadd(Filled Rectangle) listadd(Filled Rounded Rectangle) p2add(list) add(p2CENTER) listaddActionListener(this) public void actionPerformed(ActionEvent ae) repaint() public void paint(Graphics g) int i Color c1=new Color(255120130) Color c2=new Color(100255100) Color c3=new Color(100100255) Color c4=new Color(255120130) Color c5=new Color(100255100) Color c6=new Color(100100255) if (listgetSelectedIndex()==0) gsetColor(c1) gdrawLine(150150200250) if (listgetSelectedIndex()==1) gsetColor(c2) gdrawOval(150150190190) if (listgetSelectedIndex()==2) gsetColor(c3) gdrawOval(290100190130) if (listgetSelectedIndex()==3) gsetColor(c4) gdrawArc(1001401701700120) if (listgetSelectedIndex()==4) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gdrawPolygon(xy5) if (listgetSelectedIndex()==5) gsetColor(Colorcyan) gdrawRect(100100160150) if (listgetSelectedIndex()==6) gsetColor(Colorblue) gdrawRoundRect(1901101601508585)

7

if (listgetSelectedIndex()==7) gsetColor(c2) gfillOval(150150190190) if (listgetSelectedIndex()==8) gsetColor(c3) gfillOval(290100190130) if (listgetSelectedIndex()==9) gsetColor(c4) gfillArc(1001401701700120) if (listgetSelectedIndex()==10) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gfillPolygon(xy5) if (listgetSelectedIndex()==11) gsetColor(Colorcyan) gfillRect(100100160150)

if (listgetSelectedIndex()==12) gsetColor(Colorblue) gfillRoundRect(1901101601508585)

4 Save the above file as shapes java5 compile the file as

Cdevibeangtjavac shapesjavaCdevibeangt

6 If BDK is not used then execute the file as Cdevibeangtappletviewer shapesjava

7 Stop the process

RESULT

Thus the java jean was created and executed successfully

8

Ex No3 Date

DEVELOP A COMPONENT USING EJB FOR BANKING OPERATIONS

AIM To create a component for banking operations using EJB

DESCRIPTION

1 Start the process 2 Set path as Cdeviatmgtset path=pathcj2sdk141bin3 Set class path as Cdeviatmgtset classpath=classpathcj2sdkee121libj2eejar

SOURCE CODE

4 Define the home interface

import javaxejbimport javaioSerializableimport javarmipublic interface atmhome extends EJBHome public atmremote create(int accnoString nameString typefloat balance)throws RemoteExceptionCreateExceptionSave the above interface as atmhomejava

5 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface atmremote extends EJBObject public float deposit(float amt) throws RemoteException public float withdraw(float amt) throws RemoteException Save the remote interface as atmremotejava

6 Write the implementation

import javaxejbimport javarmipublic class atm implements SessionBean

9

int acno String name1 String tt float bal public void ejbCreate(int accnoString nameString typefloat 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) public atm() public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the file as atmjava

7 Write the Client part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiPortableRemoteObjectimport javautilimport javaioimport javanetimport javaxnamingNamingExceptionimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class atmclient public static void main(String args[]) throws Exception

10

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 2: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

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 DCOMNET

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

2

ExNo 1

DOWNLOAD FILES FROM VARIOUS SERVERS USING RMI

AIM To Create a program to download files from various servers using RMI

DESCRIPTION1 Define the interface2 Interface must extend Remote3 All methods must throw an exception RemoteException individually4 Implement the interface5 Create a server program6 Create a Client Program7 Generate stubs and skeletons using rmic tool8 Start the server9 Start the client10 Once the process is over stop the client and server respectively

PROGRAM

Part 1 Interface Defintion

import javarmipublic interface fileinterface extends Remote public byte[] downloadfile(String s) throws RemoteException

Part 2 Interface Implementationimport javaioimport javarmiimport javarmiserverpublic class fileimplement extends UnicastRemoteObject implements fileinterface private String name public fileimplement(String s)throws RemoteException super() name=s public byte[] downloadfile(String fn) try File fi=new File(fn) byte buf[]=new byte[(int)filength()] BufferedInputStream bis=new BufferedInputStream(new FileInputStream(fn))

3

bisread(buf0buflength) bisclose() return(buf) catch(Exception ee) Systemoutprintln(Error+eegetMessage()) eeprintStackTrace() return(null)

Part 3 Server Part

import javarmiimport javaioimport javanetpublic class fileserverpublic static void main(String args[])tryfileimplement fi=new fileimplement(fileserver)Namingrebind(127001fileserverfi)catch(Exception e)Systemoutprintln( +egetMessage())eprintStackTrace()

Part 4 Client Part

import javanetimport javarmiimport javaiopublic class fileclient public static void main(String[] args) try InetAddress addr=InetAddressgetLocalHost() String address=addrtoString()substring(addrtoString()indexOf()+1) String url=rmi+ address + fileserver fileinterface f1=(fileinterface)Naminglookup(url) byte[] data=f1downloadfile(args[0]) File ff=new File(f1txt) BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(ffgetName())) boswrite(data0datalength) bosflush()

4

bosclose() catch(Exception e) Systemoutprintln( +egetMessage()) eprintStackTrace()

Part ndash5 Compile all the files as follows

Csowmirmigtjavac javaCsowmirmigtPart ndash 6 Generate stubs and skeletons as follows Csowmirmigtrmic fileimplementCsowmirmigtPart ndash 7 Start rmiregistry as given below If registry is properly started a window will be opened

Csowmirmigtstart rmiregistryCsowmirmigtPart ndash 8 Start the serverCsowmirmigtjava fileserverPart ndash 9 Start the clientCsowmirmigtjava fileclient cdevicorbaStockMarketClientjavaCsowmirmigttype f1txt

RESULT

Thus the RMI Program was created and executed successfully

5

Ex No 2

CREATE A JAVA BEAN TO DRAW VARIOUS GRAPHICAL SHAPES USING BDK OR WITHOUT BDK

AIM To Create a Java Bean to draw various graphical shapes using BDK or without Using BDK

DESCRIPTION

1 Start the Process2 Set the classpath for java as given below

Cdevibeangtset path=pathcj2sdk141bin

3 Write the Source code as given below

PROGRAM

import javaawtimport javaappletimport javaawteventltapplet code=shapes width=400 height=400gtltappletgtpublic class shapes extends Applet implements ActionListener List list Label l1 Font f public void init() Panel p1=new Panel() Color c1=new Color(255100230) setForeground(c1)

f=new Font(MonospacedFontBOLD20) 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 SLabelCENTER) p1add(l1) add(p1NORTH)

Panel p2=new Panel() list=new List(3false) listadd(Line)

6

listadd(Circle) listadd(Ellipse) listadd(Arc) listadd(Polygon) listadd(Rectangle) listadd(Rounded Rectangle) listadd(Filled Circle) listadd(Filled Ellipse) listadd(Filled Arc) listadd(Filled Polygon) listadd(Filled Rectangle) listadd(Filled Rounded Rectangle) p2add(list) add(p2CENTER) listaddActionListener(this) public void actionPerformed(ActionEvent ae) repaint() public void paint(Graphics g) int i Color c1=new Color(255120130) Color c2=new Color(100255100) Color c3=new Color(100100255) Color c4=new Color(255120130) Color c5=new Color(100255100) Color c6=new Color(100100255) if (listgetSelectedIndex()==0) gsetColor(c1) gdrawLine(150150200250) if (listgetSelectedIndex()==1) gsetColor(c2) gdrawOval(150150190190) if (listgetSelectedIndex()==2) gsetColor(c3) gdrawOval(290100190130) if (listgetSelectedIndex()==3) gsetColor(c4) gdrawArc(1001401701700120) if (listgetSelectedIndex()==4) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gdrawPolygon(xy5) if (listgetSelectedIndex()==5) gsetColor(Colorcyan) gdrawRect(100100160150) if (listgetSelectedIndex()==6) gsetColor(Colorblue) gdrawRoundRect(1901101601508585)

7

if (listgetSelectedIndex()==7) gsetColor(c2) gfillOval(150150190190) if (listgetSelectedIndex()==8) gsetColor(c3) gfillOval(290100190130) if (listgetSelectedIndex()==9) gsetColor(c4) gfillArc(1001401701700120) if (listgetSelectedIndex()==10) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gfillPolygon(xy5) if (listgetSelectedIndex()==11) gsetColor(Colorcyan) gfillRect(100100160150)

if (listgetSelectedIndex()==12) gsetColor(Colorblue) gfillRoundRect(1901101601508585)

4 Save the above file as shapes java5 compile the file as

Cdevibeangtjavac shapesjavaCdevibeangt

6 If BDK is not used then execute the file as Cdevibeangtappletviewer shapesjava

7 Stop the process

RESULT

Thus the java jean was created and executed successfully

8

Ex No3 Date

DEVELOP A COMPONENT USING EJB FOR BANKING OPERATIONS

AIM To create a component for banking operations using EJB

DESCRIPTION

1 Start the process 2 Set path as Cdeviatmgtset path=pathcj2sdk141bin3 Set class path as Cdeviatmgtset classpath=classpathcj2sdkee121libj2eejar

SOURCE CODE

4 Define the home interface

import javaxejbimport javaioSerializableimport javarmipublic interface atmhome extends EJBHome public atmremote create(int accnoString nameString typefloat balance)throws RemoteExceptionCreateExceptionSave the above interface as atmhomejava

5 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface atmremote extends EJBObject public float deposit(float amt) throws RemoteException public float withdraw(float amt) throws RemoteException Save the remote interface as atmremotejava

6 Write the implementation

import javaxejbimport javarmipublic class atm implements SessionBean

9

int acno String name1 String tt float bal public void ejbCreate(int accnoString nameString typefloat 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) public atm() public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the file as atmjava

7 Write the Client part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiPortableRemoteObjectimport javautilimport javaioimport javanetimport javaxnamingNamingExceptionimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class atmclient public static void main(String args[]) throws Exception

10

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 3: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

ExNo 1

DOWNLOAD FILES FROM VARIOUS SERVERS USING RMI

AIM To Create a program to download files from various servers using RMI

DESCRIPTION1 Define the interface2 Interface must extend Remote3 All methods must throw an exception RemoteException individually4 Implement the interface5 Create a server program6 Create a Client Program7 Generate stubs and skeletons using rmic tool8 Start the server9 Start the client10 Once the process is over stop the client and server respectively

PROGRAM

Part 1 Interface Defintion

import javarmipublic interface fileinterface extends Remote public byte[] downloadfile(String s) throws RemoteException

Part 2 Interface Implementationimport javaioimport javarmiimport javarmiserverpublic class fileimplement extends UnicastRemoteObject implements fileinterface private String name public fileimplement(String s)throws RemoteException super() name=s public byte[] downloadfile(String fn) try File fi=new File(fn) byte buf[]=new byte[(int)filength()] BufferedInputStream bis=new BufferedInputStream(new FileInputStream(fn))

3

bisread(buf0buflength) bisclose() return(buf) catch(Exception ee) Systemoutprintln(Error+eegetMessage()) eeprintStackTrace() return(null)

Part 3 Server Part

import javarmiimport javaioimport javanetpublic class fileserverpublic static void main(String args[])tryfileimplement fi=new fileimplement(fileserver)Namingrebind(127001fileserverfi)catch(Exception e)Systemoutprintln( +egetMessage())eprintStackTrace()

Part 4 Client Part

import javanetimport javarmiimport javaiopublic class fileclient public static void main(String[] args) try InetAddress addr=InetAddressgetLocalHost() String address=addrtoString()substring(addrtoString()indexOf()+1) String url=rmi+ address + fileserver fileinterface f1=(fileinterface)Naminglookup(url) byte[] data=f1downloadfile(args[0]) File ff=new File(f1txt) BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(ffgetName())) boswrite(data0datalength) bosflush()

4

bosclose() catch(Exception e) Systemoutprintln( +egetMessage()) eprintStackTrace()

Part ndash5 Compile all the files as follows

Csowmirmigtjavac javaCsowmirmigtPart ndash 6 Generate stubs and skeletons as follows Csowmirmigtrmic fileimplementCsowmirmigtPart ndash 7 Start rmiregistry as given below If registry is properly started a window will be opened

Csowmirmigtstart rmiregistryCsowmirmigtPart ndash 8 Start the serverCsowmirmigtjava fileserverPart ndash 9 Start the clientCsowmirmigtjava fileclient cdevicorbaStockMarketClientjavaCsowmirmigttype f1txt

RESULT

Thus the RMI Program was created and executed successfully

5

Ex No 2

CREATE A JAVA BEAN TO DRAW VARIOUS GRAPHICAL SHAPES USING BDK OR WITHOUT BDK

AIM To Create a Java Bean to draw various graphical shapes using BDK or without Using BDK

DESCRIPTION

1 Start the Process2 Set the classpath for java as given below

Cdevibeangtset path=pathcj2sdk141bin

3 Write the Source code as given below

PROGRAM

import javaawtimport javaappletimport javaawteventltapplet code=shapes width=400 height=400gtltappletgtpublic class shapes extends Applet implements ActionListener List list Label l1 Font f public void init() Panel p1=new Panel() Color c1=new Color(255100230) setForeground(c1)

f=new Font(MonospacedFontBOLD20) 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 SLabelCENTER) p1add(l1) add(p1NORTH)

Panel p2=new Panel() list=new List(3false) listadd(Line)

6

listadd(Circle) listadd(Ellipse) listadd(Arc) listadd(Polygon) listadd(Rectangle) listadd(Rounded Rectangle) listadd(Filled Circle) listadd(Filled Ellipse) listadd(Filled Arc) listadd(Filled Polygon) listadd(Filled Rectangle) listadd(Filled Rounded Rectangle) p2add(list) add(p2CENTER) listaddActionListener(this) public void actionPerformed(ActionEvent ae) repaint() public void paint(Graphics g) int i Color c1=new Color(255120130) Color c2=new Color(100255100) Color c3=new Color(100100255) Color c4=new Color(255120130) Color c5=new Color(100255100) Color c6=new Color(100100255) if (listgetSelectedIndex()==0) gsetColor(c1) gdrawLine(150150200250) if (listgetSelectedIndex()==1) gsetColor(c2) gdrawOval(150150190190) if (listgetSelectedIndex()==2) gsetColor(c3) gdrawOval(290100190130) if (listgetSelectedIndex()==3) gsetColor(c4) gdrawArc(1001401701700120) if (listgetSelectedIndex()==4) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gdrawPolygon(xy5) if (listgetSelectedIndex()==5) gsetColor(Colorcyan) gdrawRect(100100160150) if (listgetSelectedIndex()==6) gsetColor(Colorblue) gdrawRoundRect(1901101601508585)

7

if (listgetSelectedIndex()==7) gsetColor(c2) gfillOval(150150190190) if (listgetSelectedIndex()==8) gsetColor(c3) gfillOval(290100190130) if (listgetSelectedIndex()==9) gsetColor(c4) gfillArc(1001401701700120) if (listgetSelectedIndex()==10) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gfillPolygon(xy5) if (listgetSelectedIndex()==11) gsetColor(Colorcyan) gfillRect(100100160150)

if (listgetSelectedIndex()==12) gsetColor(Colorblue) gfillRoundRect(1901101601508585)

4 Save the above file as shapes java5 compile the file as

Cdevibeangtjavac shapesjavaCdevibeangt

6 If BDK is not used then execute the file as Cdevibeangtappletviewer shapesjava

7 Stop the process

RESULT

Thus the java jean was created and executed successfully

8

Ex No3 Date

DEVELOP A COMPONENT USING EJB FOR BANKING OPERATIONS

AIM To create a component for banking operations using EJB

DESCRIPTION

1 Start the process 2 Set path as Cdeviatmgtset path=pathcj2sdk141bin3 Set class path as Cdeviatmgtset classpath=classpathcj2sdkee121libj2eejar

SOURCE CODE

4 Define the home interface

import javaxejbimport javaioSerializableimport javarmipublic interface atmhome extends EJBHome public atmremote create(int accnoString nameString typefloat balance)throws RemoteExceptionCreateExceptionSave the above interface as atmhomejava

5 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface atmremote extends EJBObject public float deposit(float amt) throws RemoteException public float withdraw(float amt) throws RemoteException Save the remote interface as atmremotejava

6 Write the implementation

import javaxejbimport javarmipublic class atm implements SessionBean

9

int acno String name1 String tt float bal public void ejbCreate(int accnoString nameString typefloat 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) public atm() public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the file as atmjava

7 Write the Client part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiPortableRemoteObjectimport javautilimport javaioimport javanetimport javaxnamingNamingExceptionimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class atmclient public static void main(String args[]) throws Exception

10

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 4: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

bisread(buf0buflength) bisclose() return(buf) catch(Exception ee) Systemoutprintln(Error+eegetMessage()) eeprintStackTrace() return(null)

Part 3 Server Part

import javarmiimport javaioimport javanetpublic class fileserverpublic static void main(String args[])tryfileimplement fi=new fileimplement(fileserver)Namingrebind(127001fileserverfi)catch(Exception e)Systemoutprintln( +egetMessage())eprintStackTrace()

Part 4 Client Part

import javanetimport javarmiimport javaiopublic class fileclient public static void main(String[] args) try InetAddress addr=InetAddressgetLocalHost() String address=addrtoString()substring(addrtoString()indexOf()+1) String url=rmi+ address + fileserver fileinterface f1=(fileinterface)Naminglookup(url) byte[] data=f1downloadfile(args[0]) File ff=new File(f1txt) BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(ffgetName())) boswrite(data0datalength) bosflush()

4

bosclose() catch(Exception e) Systemoutprintln( +egetMessage()) eprintStackTrace()

Part ndash5 Compile all the files as follows

Csowmirmigtjavac javaCsowmirmigtPart ndash 6 Generate stubs and skeletons as follows Csowmirmigtrmic fileimplementCsowmirmigtPart ndash 7 Start rmiregistry as given below If registry is properly started a window will be opened

Csowmirmigtstart rmiregistryCsowmirmigtPart ndash 8 Start the serverCsowmirmigtjava fileserverPart ndash 9 Start the clientCsowmirmigtjava fileclient cdevicorbaStockMarketClientjavaCsowmirmigttype f1txt

RESULT

Thus the RMI Program was created and executed successfully

5

Ex No 2

CREATE A JAVA BEAN TO DRAW VARIOUS GRAPHICAL SHAPES USING BDK OR WITHOUT BDK

AIM To Create a Java Bean to draw various graphical shapes using BDK or without Using BDK

DESCRIPTION

1 Start the Process2 Set the classpath for java as given below

Cdevibeangtset path=pathcj2sdk141bin

3 Write the Source code as given below

PROGRAM

import javaawtimport javaappletimport javaawteventltapplet code=shapes width=400 height=400gtltappletgtpublic class shapes extends Applet implements ActionListener List list Label l1 Font f public void init() Panel p1=new Panel() Color c1=new Color(255100230) setForeground(c1)

f=new Font(MonospacedFontBOLD20) 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 SLabelCENTER) p1add(l1) add(p1NORTH)

Panel p2=new Panel() list=new List(3false) listadd(Line)

6

listadd(Circle) listadd(Ellipse) listadd(Arc) listadd(Polygon) listadd(Rectangle) listadd(Rounded Rectangle) listadd(Filled Circle) listadd(Filled Ellipse) listadd(Filled Arc) listadd(Filled Polygon) listadd(Filled Rectangle) listadd(Filled Rounded Rectangle) p2add(list) add(p2CENTER) listaddActionListener(this) public void actionPerformed(ActionEvent ae) repaint() public void paint(Graphics g) int i Color c1=new Color(255120130) Color c2=new Color(100255100) Color c3=new Color(100100255) Color c4=new Color(255120130) Color c5=new Color(100255100) Color c6=new Color(100100255) if (listgetSelectedIndex()==0) gsetColor(c1) gdrawLine(150150200250) if (listgetSelectedIndex()==1) gsetColor(c2) gdrawOval(150150190190) if (listgetSelectedIndex()==2) gsetColor(c3) gdrawOval(290100190130) if (listgetSelectedIndex()==3) gsetColor(c4) gdrawArc(1001401701700120) if (listgetSelectedIndex()==4) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gdrawPolygon(xy5) if (listgetSelectedIndex()==5) gsetColor(Colorcyan) gdrawRect(100100160150) if (listgetSelectedIndex()==6) gsetColor(Colorblue) gdrawRoundRect(1901101601508585)

7

if (listgetSelectedIndex()==7) gsetColor(c2) gfillOval(150150190190) if (listgetSelectedIndex()==8) gsetColor(c3) gfillOval(290100190130) if (listgetSelectedIndex()==9) gsetColor(c4) gfillArc(1001401701700120) if (listgetSelectedIndex()==10) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gfillPolygon(xy5) if (listgetSelectedIndex()==11) gsetColor(Colorcyan) gfillRect(100100160150)

if (listgetSelectedIndex()==12) gsetColor(Colorblue) gfillRoundRect(1901101601508585)

4 Save the above file as shapes java5 compile the file as

Cdevibeangtjavac shapesjavaCdevibeangt

6 If BDK is not used then execute the file as Cdevibeangtappletviewer shapesjava

7 Stop the process

RESULT

Thus the java jean was created and executed successfully

8

Ex No3 Date

DEVELOP A COMPONENT USING EJB FOR BANKING OPERATIONS

AIM To create a component for banking operations using EJB

DESCRIPTION

1 Start the process 2 Set path as Cdeviatmgtset path=pathcj2sdk141bin3 Set class path as Cdeviatmgtset classpath=classpathcj2sdkee121libj2eejar

SOURCE CODE

4 Define the home interface

import javaxejbimport javaioSerializableimport javarmipublic interface atmhome extends EJBHome public atmremote create(int accnoString nameString typefloat balance)throws RemoteExceptionCreateExceptionSave the above interface as atmhomejava

5 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface atmremote extends EJBObject public float deposit(float amt) throws RemoteException public float withdraw(float amt) throws RemoteException Save the remote interface as atmremotejava

6 Write the implementation

import javaxejbimport javarmipublic class atm implements SessionBean

9

int acno String name1 String tt float bal public void ejbCreate(int accnoString nameString typefloat 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) public atm() public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the file as atmjava

7 Write the Client part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiPortableRemoteObjectimport javautilimport javaioimport javanetimport javaxnamingNamingExceptionimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class atmclient public static void main(String args[]) throws Exception

10

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 5: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

bosclose() catch(Exception e) Systemoutprintln( +egetMessage()) eprintStackTrace()

Part ndash5 Compile all the files as follows

Csowmirmigtjavac javaCsowmirmigtPart ndash 6 Generate stubs and skeletons as follows Csowmirmigtrmic fileimplementCsowmirmigtPart ndash 7 Start rmiregistry as given below If registry is properly started a window will be opened

Csowmirmigtstart rmiregistryCsowmirmigtPart ndash 8 Start the serverCsowmirmigtjava fileserverPart ndash 9 Start the clientCsowmirmigtjava fileclient cdevicorbaStockMarketClientjavaCsowmirmigttype f1txt

RESULT

Thus the RMI Program was created and executed successfully

5

Ex No 2

CREATE A JAVA BEAN TO DRAW VARIOUS GRAPHICAL SHAPES USING BDK OR WITHOUT BDK

AIM To Create a Java Bean to draw various graphical shapes using BDK or without Using BDK

DESCRIPTION

1 Start the Process2 Set the classpath for java as given below

Cdevibeangtset path=pathcj2sdk141bin

3 Write the Source code as given below

PROGRAM

import javaawtimport javaappletimport javaawteventltapplet code=shapes width=400 height=400gtltappletgtpublic class shapes extends Applet implements ActionListener List list Label l1 Font f public void init() Panel p1=new Panel() Color c1=new Color(255100230) setForeground(c1)

f=new Font(MonospacedFontBOLD20) 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 SLabelCENTER) p1add(l1) add(p1NORTH)

Panel p2=new Panel() list=new List(3false) listadd(Line)

6

listadd(Circle) listadd(Ellipse) listadd(Arc) listadd(Polygon) listadd(Rectangle) listadd(Rounded Rectangle) listadd(Filled Circle) listadd(Filled Ellipse) listadd(Filled Arc) listadd(Filled Polygon) listadd(Filled Rectangle) listadd(Filled Rounded Rectangle) p2add(list) add(p2CENTER) listaddActionListener(this) public void actionPerformed(ActionEvent ae) repaint() public void paint(Graphics g) int i Color c1=new Color(255120130) Color c2=new Color(100255100) Color c3=new Color(100100255) Color c4=new Color(255120130) Color c5=new Color(100255100) Color c6=new Color(100100255) if (listgetSelectedIndex()==0) gsetColor(c1) gdrawLine(150150200250) if (listgetSelectedIndex()==1) gsetColor(c2) gdrawOval(150150190190) if (listgetSelectedIndex()==2) gsetColor(c3) gdrawOval(290100190130) if (listgetSelectedIndex()==3) gsetColor(c4) gdrawArc(1001401701700120) if (listgetSelectedIndex()==4) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gdrawPolygon(xy5) if (listgetSelectedIndex()==5) gsetColor(Colorcyan) gdrawRect(100100160150) if (listgetSelectedIndex()==6) gsetColor(Colorblue) gdrawRoundRect(1901101601508585)

7

if (listgetSelectedIndex()==7) gsetColor(c2) gfillOval(150150190190) if (listgetSelectedIndex()==8) gsetColor(c3) gfillOval(290100190130) if (listgetSelectedIndex()==9) gsetColor(c4) gfillArc(1001401701700120) if (listgetSelectedIndex()==10) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gfillPolygon(xy5) if (listgetSelectedIndex()==11) gsetColor(Colorcyan) gfillRect(100100160150)

if (listgetSelectedIndex()==12) gsetColor(Colorblue) gfillRoundRect(1901101601508585)

4 Save the above file as shapes java5 compile the file as

Cdevibeangtjavac shapesjavaCdevibeangt

6 If BDK is not used then execute the file as Cdevibeangtappletviewer shapesjava

7 Stop the process

RESULT

Thus the java jean was created and executed successfully

8

Ex No3 Date

DEVELOP A COMPONENT USING EJB FOR BANKING OPERATIONS

AIM To create a component for banking operations using EJB

DESCRIPTION

1 Start the process 2 Set path as Cdeviatmgtset path=pathcj2sdk141bin3 Set class path as Cdeviatmgtset classpath=classpathcj2sdkee121libj2eejar

SOURCE CODE

4 Define the home interface

import javaxejbimport javaioSerializableimport javarmipublic interface atmhome extends EJBHome public atmremote create(int accnoString nameString typefloat balance)throws RemoteExceptionCreateExceptionSave the above interface as atmhomejava

5 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface atmremote extends EJBObject public float deposit(float amt) throws RemoteException public float withdraw(float amt) throws RemoteException Save the remote interface as atmremotejava

6 Write the implementation

import javaxejbimport javarmipublic class atm implements SessionBean

9

int acno String name1 String tt float bal public void ejbCreate(int accnoString nameString typefloat 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) public atm() public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the file as atmjava

7 Write the Client part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiPortableRemoteObjectimport javautilimport javaioimport javanetimport javaxnamingNamingExceptionimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class atmclient public static void main(String args[]) throws Exception

10

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 6: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Ex No 2

CREATE A JAVA BEAN TO DRAW VARIOUS GRAPHICAL SHAPES USING BDK OR WITHOUT BDK

AIM To Create a Java Bean to draw various graphical shapes using BDK or without Using BDK

DESCRIPTION

1 Start the Process2 Set the classpath for java as given below

Cdevibeangtset path=pathcj2sdk141bin

3 Write the Source code as given below

PROGRAM

import javaawtimport javaappletimport javaawteventltapplet code=shapes width=400 height=400gtltappletgtpublic class shapes extends Applet implements ActionListener List list Label l1 Font f public void init() Panel p1=new Panel() Color c1=new Color(255100230) setForeground(c1)

f=new Font(MonospacedFontBOLD20) 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 SLabelCENTER) p1add(l1) add(p1NORTH)

Panel p2=new Panel() list=new List(3false) listadd(Line)

6

listadd(Circle) listadd(Ellipse) listadd(Arc) listadd(Polygon) listadd(Rectangle) listadd(Rounded Rectangle) listadd(Filled Circle) listadd(Filled Ellipse) listadd(Filled Arc) listadd(Filled Polygon) listadd(Filled Rectangle) listadd(Filled Rounded Rectangle) p2add(list) add(p2CENTER) listaddActionListener(this) public void actionPerformed(ActionEvent ae) repaint() public void paint(Graphics g) int i Color c1=new Color(255120130) Color c2=new Color(100255100) Color c3=new Color(100100255) Color c4=new Color(255120130) Color c5=new Color(100255100) Color c6=new Color(100100255) if (listgetSelectedIndex()==0) gsetColor(c1) gdrawLine(150150200250) if (listgetSelectedIndex()==1) gsetColor(c2) gdrawOval(150150190190) if (listgetSelectedIndex()==2) gsetColor(c3) gdrawOval(290100190130) if (listgetSelectedIndex()==3) gsetColor(c4) gdrawArc(1001401701700120) if (listgetSelectedIndex()==4) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gdrawPolygon(xy5) if (listgetSelectedIndex()==5) gsetColor(Colorcyan) gdrawRect(100100160150) if (listgetSelectedIndex()==6) gsetColor(Colorblue) gdrawRoundRect(1901101601508585)

7

if (listgetSelectedIndex()==7) gsetColor(c2) gfillOval(150150190190) if (listgetSelectedIndex()==8) gsetColor(c3) gfillOval(290100190130) if (listgetSelectedIndex()==9) gsetColor(c4) gfillArc(1001401701700120) if (listgetSelectedIndex()==10) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gfillPolygon(xy5) if (listgetSelectedIndex()==11) gsetColor(Colorcyan) gfillRect(100100160150)

if (listgetSelectedIndex()==12) gsetColor(Colorblue) gfillRoundRect(1901101601508585)

4 Save the above file as shapes java5 compile the file as

Cdevibeangtjavac shapesjavaCdevibeangt

6 If BDK is not used then execute the file as Cdevibeangtappletviewer shapesjava

7 Stop the process

RESULT

Thus the java jean was created and executed successfully

8

Ex No3 Date

DEVELOP A COMPONENT USING EJB FOR BANKING OPERATIONS

AIM To create a component for banking operations using EJB

DESCRIPTION

1 Start the process 2 Set path as Cdeviatmgtset path=pathcj2sdk141bin3 Set class path as Cdeviatmgtset classpath=classpathcj2sdkee121libj2eejar

SOURCE CODE

4 Define the home interface

import javaxejbimport javaioSerializableimport javarmipublic interface atmhome extends EJBHome public atmremote create(int accnoString nameString typefloat balance)throws RemoteExceptionCreateExceptionSave the above interface as atmhomejava

5 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface atmremote extends EJBObject public float deposit(float amt) throws RemoteException public float withdraw(float amt) throws RemoteException Save the remote interface as atmremotejava

6 Write the implementation

import javaxejbimport javarmipublic class atm implements SessionBean

9

int acno String name1 String tt float bal public void ejbCreate(int accnoString nameString typefloat 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) public atm() public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the file as atmjava

7 Write the Client part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiPortableRemoteObjectimport javautilimport javaioimport javanetimport javaxnamingNamingExceptionimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class atmclient public static void main(String args[]) throws Exception

10

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 7: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

listadd(Circle) listadd(Ellipse) listadd(Arc) listadd(Polygon) listadd(Rectangle) listadd(Rounded Rectangle) listadd(Filled Circle) listadd(Filled Ellipse) listadd(Filled Arc) listadd(Filled Polygon) listadd(Filled Rectangle) listadd(Filled Rounded Rectangle) p2add(list) add(p2CENTER) listaddActionListener(this) public void actionPerformed(ActionEvent ae) repaint() public void paint(Graphics g) int i Color c1=new Color(255120130) Color c2=new Color(100255100) Color c3=new Color(100100255) Color c4=new Color(255120130) Color c5=new Color(100255100) Color c6=new Color(100100255) if (listgetSelectedIndex()==0) gsetColor(c1) gdrawLine(150150200250) if (listgetSelectedIndex()==1) gsetColor(c2) gdrawOval(150150190190) if (listgetSelectedIndex()==2) gsetColor(c3) gdrawOval(290100190130) if (listgetSelectedIndex()==3) gsetColor(c4) gdrawArc(1001401701700120) if (listgetSelectedIndex()==4) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gdrawPolygon(xy5) if (listgetSelectedIndex()==5) gsetColor(Colorcyan) gdrawRect(100100160150) if (listgetSelectedIndex()==6) gsetColor(Colorblue) gdrawRoundRect(1901101601508585)

7

if (listgetSelectedIndex()==7) gsetColor(c2) gfillOval(150150190190) if (listgetSelectedIndex()==8) gsetColor(c3) gfillOval(290100190130) if (listgetSelectedIndex()==9) gsetColor(c4) gfillArc(1001401701700120) if (listgetSelectedIndex()==10) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gfillPolygon(xy5) if (listgetSelectedIndex()==11) gsetColor(Colorcyan) gfillRect(100100160150)

if (listgetSelectedIndex()==12) gsetColor(Colorblue) gfillRoundRect(1901101601508585)

4 Save the above file as shapes java5 compile the file as

Cdevibeangtjavac shapesjavaCdevibeangt

6 If BDK is not used then execute the file as Cdevibeangtappletviewer shapesjava

7 Stop the process

RESULT

Thus the java jean was created and executed successfully

8

Ex No3 Date

DEVELOP A COMPONENT USING EJB FOR BANKING OPERATIONS

AIM To create a component for banking operations using EJB

DESCRIPTION

1 Start the process 2 Set path as Cdeviatmgtset path=pathcj2sdk141bin3 Set class path as Cdeviatmgtset classpath=classpathcj2sdkee121libj2eejar

SOURCE CODE

4 Define the home interface

import javaxejbimport javaioSerializableimport javarmipublic interface atmhome extends EJBHome public atmremote create(int accnoString nameString typefloat balance)throws RemoteExceptionCreateExceptionSave the above interface as atmhomejava

5 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface atmremote extends EJBObject public float deposit(float amt) throws RemoteException public float withdraw(float amt) throws RemoteException Save the remote interface as atmremotejava

6 Write the implementation

import javaxejbimport javarmipublic class atm implements SessionBean

9

int acno String name1 String tt float bal public void ejbCreate(int accnoString nameString typefloat 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) public atm() public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the file as atmjava

7 Write the Client part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiPortableRemoteObjectimport javautilimport javaioimport javanetimport javaxnamingNamingExceptionimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class atmclient public static void main(String args[]) throws Exception

10

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 8: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

if (listgetSelectedIndex()==7) gsetColor(c2) gfillOval(150150190190) if (listgetSelectedIndex()==8) gsetColor(c3) gfillOval(290100190130) if (listgetSelectedIndex()==9) gsetColor(c4) gfillArc(1001401701700120) if (listgetSelectedIndex()==10) gsetColor(c5) int x[]=130400130300130 int y[]=130130300400130 gfillPolygon(xy5) if (listgetSelectedIndex()==11) gsetColor(Colorcyan) gfillRect(100100160150)

if (listgetSelectedIndex()==12) gsetColor(Colorblue) gfillRoundRect(1901101601508585)

4 Save the above file as shapes java5 compile the file as

Cdevibeangtjavac shapesjavaCdevibeangt

6 If BDK is not used then execute the file as Cdevibeangtappletviewer shapesjava

7 Stop the process

RESULT

Thus the java jean was created and executed successfully

8

Ex No3 Date

DEVELOP A COMPONENT USING EJB FOR BANKING OPERATIONS

AIM To create a component for banking operations using EJB

DESCRIPTION

1 Start the process 2 Set path as Cdeviatmgtset path=pathcj2sdk141bin3 Set class path as Cdeviatmgtset classpath=classpathcj2sdkee121libj2eejar

SOURCE CODE

4 Define the home interface

import javaxejbimport javaioSerializableimport javarmipublic interface atmhome extends EJBHome public atmremote create(int accnoString nameString typefloat balance)throws RemoteExceptionCreateExceptionSave the above interface as atmhomejava

5 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface atmremote extends EJBObject public float deposit(float amt) throws RemoteException public float withdraw(float amt) throws RemoteException Save the remote interface as atmremotejava

6 Write the implementation

import javaxejbimport javarmipublic class atm implements SessionBean

9

int acno String name1 String tt float bal public void ejbCreate(int accnoString nameString typefloat 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) public atm() public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the file as atmjava

7 Write the Client part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiPortableRemoteObjectimport javautilimport javaioimport javanetimport javaxnamingNamingExceptionimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class atmclient public static void main(String args[]) throws Exception

10

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 9: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Ex No3 Date

DEVELOP A COMPONENT USING EJB FOR BANKING OPERATIONS

AIM To create a component for banking operations using EJB

DESCRIPTION

1 Start the process 2 Set path as Cdeviatmgtset path=pathcj2sdk141bin3 Set class path as Cdeviatmgtset classpath=classpathcj2sdkee121libj2eejar

SOURCE CODE

4 Define the home interface

import javaxejbimport javaioSerializableimport javarmipublic interface atmhome extends EJBHome public atmremote create(int accnoString nameString typefloat balance)throws RemoteExceptionCreateExceptionSave the above interface as atmhomejava

5 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface atmremote extends EJBObject public float deposit(float amt) throws RemoteException public float withdraw(float amt) throws RemoteException Save the remote interface as atmremotejava

6 Write the implementation

import javaxejbimport javarmipublic class atm implements SessionBean

9

int acno String name1 String tt float bal public void ejbCreate(int accnoString nameString typefloat 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) public atm() public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the file as atmjava

7 Write the Client part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiPortableRemoteObjectimport javautilimport javaioimport javanetimport javaxnamingNamingExceptionimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class atmclient public static void main(String args[]) throws Exception

10

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 10: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

int acno String name1 String tt float bal public void ejbCreate(int accnoString nameString typefloat 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) public atm() public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the file as atmjava

7 Write the Client part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiPortableRemoteObjectimport javautilimport javaioimport javanetimport javaxnamingNamingExceptionimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class atmclient public static void main(String args[]) throws Exception

10

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 11: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

float bal=0String tt= Properties props = new Properties() propssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS ) InitialContext initial = new InitialContext(props) Object objref = initiallookup(atm2) atmhome home = (atmhome)PortableRemoteObjectnarrow(objrefatmhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch=1 String name int acc Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) acc=IntegerparseInt(brreadLine()) Systemoutprintln(Enter Ur Name) name=brreadLine() while(chlt=4) Systemoutprintln(ttBANK OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1DEPOSIT) Systemoutprintln(tt2WITHDRAW) Systemoutprintln(tt3DISPLAY) Systemoutprintln(tt4EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) switch(ch) case 1 Systemoutprintln(Enter the Transaction type) tt=brreadLine() atmremote bb= homecreate(accnamett10000) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) float amt=FloatparseFloat(brreadLine()) bal=bbdeposit(amt) Systemoutprintln(Balance after deposit= +bal) break

case 2

11

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 12: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Systemoutprintln(Enter the Transaction type) tt=brreadLine() bb= homecreate(accnamettbal) Systemoutprintln(Entering) Systemoutprintln(Enter the transaction amt) amt=FloatparseFloat(brreadLine()) bal=bbwithdraw(amt) Systemoutprintln(Balance after withdraw + bal) break case 3 Systemoutprintln(Status of the Customer) Systemoutprintln(Account Number+acc) Systemoutprintln(Name of the Customer+name) Systemoutprintln(Transaction type+tt) Systemoutprintln(Balance+bal) break case 4 Systemexit(0) switch while main class

8 Compile all the files Cdeviatmjavac java

9 Select Start-gtPrograms-gtBEA Wblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

10 Select File ndashgtOpen-gtatm -gtopen11 A window will be displayed indicating the JNDI name 12 File-gtSave13 File-gtArchive-gtSave14 After getting the successful message goto start programs-gtBEA weblogic platform 81-gt

user projects-gtmy domain-gtstart server15 If the server is in running mode without any exception goto internet explorer16 Type httplocalhost7001console17 A window will be displayed which prompt you for the username and password as

follows

WebLogic Server Administration ConsoleSign in to work with the WebLogic Server domain mydomain

Username devi

12

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 13: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Password

Sign In

18 If the username and password is correct then the following page is displayed

Welcome to BEA WebLogic Server Home

Connected to localhost 7001 You are logged in as devi Logout Information and Resources

Helpful Tools General Information Convert weblogicproperties Read the documentation Deploy a new Application Common Administration Task Descriptions Recent Task Status Set your console preferences Domain Configurations

Network Configuration Your Deployed Resources Your Applications Security Settings

Domain Applications Realms Servers EJB Modules Clusters Web Application Modules Machines Connector Modules Startup amp Shutdown Services Configurations JDBC SNMP Other Services Connection Pools Agent XML Registries MultiPools Proxies JTA Configuration Data Sources Monitors Virtual Hosts Data Source Factories Log Filters Domain-wide Logging Attribute Changes Mail JMS Trap Destinations FileT3 Connection Factories Templates Connectivity Messaging Bridge Destination Keys WebLogic Tuxedo Connector Bridges Stores Tuxedo via JOLT JMS Bridge Destinations Servers Tuxedo via WLEC General Bridge Destinations Distributed Destinations Foreign JMS Servers Copyright (c) 2003 BEA Systems Inc All rights reserved

13

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 14: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

19 In the above page select the link EJB Modules which leads to the next page as pictured below

Configuration Monitoring

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

sum sumjar 100

_appsdir_atm_jar atmjar 100

_appsdir_bank_jar bankjar 100

_appsdir_hello_jar hellojar 100

_appsdir_ss_jar ssjar 100

20 To check for the successfulness click the required jar file[Note- here the file is atmjar]21 If the process is successful then the following message will be displayed

This page allows you to test remote EJBs to see whether they can be found via their JNDI names

14

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 15: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Session

Atm2 Test this EJB22 Select the link Test this EJB The following message will be displayed if successful23 The EJB atm2 has been tested successfully with a JNDI name of atm2

Continue

24 Before running the client set the path as followsCdeviatmgtset path=pathcj2sdk141binCdeviatmgtset classpath=classpathcj2sdkee121libj2eejarCdeviatmgtset classpath=weblogicjarclasspath

25 Start the clientCdeviatmgtjava atmclient

RESULT

Thus the component was created successfully using EJB

EX No4

DEVELOP A COMPONENT USING EJB FOR LIBRARY OPERATIONS

15

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 16: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

AIM - To Create a component for Library Operations using EJB

DESCRIPTION

1 Start the Process2 Set the path as follows

i Cdevigtset path=pathcj2sdk141binii Cdevigtset classpath=classpathcj2sdkee121libj2eejar

3 Define the Home Interface

import javaxejbimport javaioSerializable

import javarmi public interface libraryhome extends EJBHome public libraryremote create(int idString titleString authorint nc)throws RemoteExceptionCreateException Save the above file as libraryhomejava

4 Define the Remote Interface

import javaioSerializableimport javaxejbimport javarmipublic interface libraryremote extends EJBObject public boolean issue(int idString titleString authorint nc) throws RemoteException public boolean receive(int idString titleString authorint nc) throws RemoteException public int ncpy() throws RemoteException Save the above file as libraryremotejava

5 Implement the EJB

import javaxejbimport javarmipublic class library implements SessionBean int bkid String tit String auth int nc1 boolean status=false public void ejbCreate(int idString titleString authorint nc) bkid=id tit=title

16

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 17: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

auth=author nc1=nc public int ncpy() return nc1 public boolean issue(int idString titString authint nc) if(bkid==id) nc1-- status=true else status=false return(status) public boolean receive(int idString titString authint nc) if(bkid==id) nc1++ status=true else status=false return(status) public void ejbRemove() public void ejbActivate() public void ejbPassivate() public void setSessionContext(SessionContext sc) Save the above file as libraryjava

6 Write the Client Part

import javaxrmiimport javautilimport javaxnamingContextimport javaxnamingInitialContextimport javaxrmiimport javautilimport javaioimport javanetimport javaxnamingimport javarmiRemoteExceptionimport javaxejbCreateExceptionimport javautilPropertiespublic class libraryclient public static void main(String args[]) throws Exception Properties props = new Properties()

17

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 18: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

PropssetProperty(InitialContextINITIAL_CONTEXT_FACTORYweblogicjndiWLInitialContextFactory) propssetProperty(InitialContextPROVIDER_URL t3localhost7001) propssetProperty(InitialContextSECURITY_PRINCIPAL) propssetProperty(InitialContextSECURITY_CREDENTIALS) InitialContext initial = new InitialContext(props) Object objref = initiallookup(library2) libraryhome home= libraryhome)PortableRemoteObjectnarrow(objreflibraryhomeclass) BufferedReader br=new BufferedReader(new InputStreamReader(Systemin)) int ch String titauth int idnc boolean st Systemoutprintln(Enter the Details) Systemoutprintln(Enter the Account Number) id=IntegerparseInt(brreadLine()) Systemoutprintln(Enter The Book Title) tit=brreadLine() Systemoutprintln(Enter the Author) auth=brreadLine() Systemoutprintln(Enter the noof copies) nc=IntegerparseInt(brreadLine()) int temp=nc do Systemoutprintln(ttLIBRARY OPERATIONS) Systemoutprintln(tt) Systemoutprintln() Systemoutprintln(tt1ISSUE) Systemoutprintln(tt2RECEIVE) Systemoutprintln(tt3EXIT) Systemoutprintln(ttENTER UR OPTION) ch=IntegerparseInt(brreadLine()) libraryremote bb= homecreate(idtitauthnc) switch(ch)

18

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 19: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

case 1 Systemoutprintln(Entering) nc=bbncpy() if(ncgt0) if(bbissue(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Book is not available) break case 2 Systemoutprintln(Entering) if(tempgtnc) Systemoutprintln(temp+temp) if(bbreceive(idtitauthnc)) Systemoutprintln(BOOK ID IS+id) Systemoutprintln(BOOK TITLE IS+tit) Systemoutprintln(BOOK AUTHOR IS+auth) Systemoutprintln(NO OF COPIES +bbncpy()) nc=bbncpy() Systemoutprintln(Sucess) break else Systemoutprintln(Invalid Transaction) break case 3 Systemexit(0) switch while(chlt=3 ampamp chgt0) main classSave the above file as libraryclientjava

7 Compile all the filesCdevigtjavac javaCdevigt

8 Start-gtPrograms-gtBEA Weblogic Platform 81-gtOther Development Tools-gtWeblogic Builder

9 File -gtOpen-gtss-gtOk10 File-gtsave11 File-gtArchive-gtName the jarfile(libraryjar)-gtOk12 Tools-gtValidate Descriptors-gtejbc Successful13 Copy the weblogicjar(cbeaweblogic81libweblogicjar) to the folder where Your EJB

module is located (In the Program it is css)

19

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 20: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

14 Copy the Jar file created by you (here it is library jar) to cbeauserprojectsmydomainapplications

15 Start the server(Start-gtprograms-gtBea web logic Platform81-gtUser Projects-gtmydomain-gtStart Server

16 If the server is started successfully without any exception then go to the next step17 Open Internet Explorer-gtType the URL (httplocalhost7001console) in the address

box(Type the user name and password)18 If the username and password is correct a page will be displayed19 In that page click-gtEJB Modules

An EJB module represents one or more Enterprise JavaBeans (EJBs) contained in an EJB JAR (Java Archive) file or exploded JAR directory An EJB module can be deployed on one or more target servers or clusters Configuring and deploying an EJB module in a WebLogic Server domain enables WebLogic Server to serve the modules of the EJB to clients

This EJBs Modules page lists key information about the EJB modules that have been configured for deployment in this WebLogic Server domain

Deploy a new EJB Module

Customize this view

Name URI Deployment Order

ss ssjar 100

_appsdir_atm_jar atmjar 100

_appsdir_hello_jar hellojar 10020 Click the link of the jar file that You have created (Here it is ssjar)21 Click the testing tab22 Click the link Test this EJBThe EJB library2 has been tested successfully with a JNDI

name of library2 Continue 23 In the client part set the path as

Cdeviigtset classpath=weblogicjarclasspath24 Run the client25 Terminate the Client and server

Cdevigtjava libraryclient

20

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 21: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

RESULT

Thus the program was created successfully

Ex No 5CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS

AIM- To Create an Activex Control for File Operations

DESCRIPTION

PART-I

1 Start the process2 Open Visual Studionet3 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Control Library4 Rename the Project as actfileoperation and click ok5 drag and drop the following control

i one Label boxii one Rich Text Boxiii four Button

6 The following code must be included in their respective Button Click EventPublic Class FileControl

Inherits SystemWindowsFormsUserControl

Dim fname As String

newPrivate Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

RichTextBox1Text =

End Sub

open Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button2Click

Dim of As New OpenFileDialog

If ofShowDialog = DialogResultOK Then

fname = ofFileName

RichTextBox1LoadFile(fname)

End If

End Sub

save Private Sub Button3_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button3Click

Dim sf As New SaveFileDialog

21

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 22: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

If sfShowDialog = DialogResultOK Then

fname = sfFileName

RichTextBox1SaveFile(fname)

End If

End Sub

font Private Sub Button4_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button4Click

Dim fo As New FontDialog

If foShowDialog = DialogResultOK Then

RichTextBox1Font = foFont

End If

End Sub

End Class

7 Build solution from the Built Menu

PART-II

1 Open Visual Studionet2 File-gtNew-gtProject-gtVisualBasic Projects-gtWindows Application3 Rename the Project as actref and click ok4 Tools-gtAddRemove Tool Box Item and select the tab NET Framework Components 5 Click the Browse Button and open the actfileoperationdll from (locate the bin folder) and

click ok6 Now the user control (FileControl) will be added to Tool Box7 Drag and Drop the Control in the Form 8 Execute the project by hitting f5

RESULT

Thus the ActiveX control was created successfully

22

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 23: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Ex No 6

DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COMNET

AIM To Create an component for currency conversion using comnet

DESCRIPTION

PART ndash1

CREATE A COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if

required4 include the following coding in the class Library

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

23

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 24: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Return (res) End FunctionEnd Class

5 Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashII

REFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3 File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the

Windows Application if required4 Project -gt Add Reference choose the com tab-gtBrowse the dollartorupeesdll and click

ok5 drag and drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 4 Buttons

6 Include the coding in each of the Respective Button click Event

Imports conversion2

Public Class Form1

Inherits SystemWindowsFormsForm

Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As

SystemEventArgs) Handles Button1Click

Dim obj As New convclass

Dim ret As Double

ret = objdtor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given dollar +

retToString())

End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button2Click

Dim obj As New convclass

Dim ret As Double

ret = objetor(CDbl(TextBox1Text))

MsgBox(The Equivalent Rupees for the given euro +

retToString())

End Sub

Private Sub Button4_Click(ByVal sender As SystemObject ByVal e

As SystemEventArgs) Handles Button4Click

Dim obj As New convclass

Dim ret As Double

ret = objrtod(CDbl(TextBox1Text))

24

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 25: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

MsgBox(The Equivalent Dollar Amount for the given rupees + retToString())

End Sub

Private Sub Button3_Click(ByVal sender As SystemObject

ByVal e As SystemEventArgs) Handles Button3Click

Dim obj As New convclass

Dim ret As Double

ret = objrtoe(CDbl(TextBox1Text))

MsgBox(The Equivalent Euro Amount for the given rupees

+ retToString())

End Sub

End Class

7 Execute the project

RESULT

Thus the above program was executed successfully

25

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 26: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Ex No 7 `

DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COMNET

AIM To Develop a component for cryptography using COMNET

DESCRIPTION

PART ndash1

CREATE A COMPONENT Start the process open VS NET

File-gt New-gt Project-gt visual Basic Project -gt class library rename the class Library if requiredinclude the following coding in the class Library

Public Class Class1 Dim pa1 As String Dim i As Integer Dim ct As Long Public Function enco(ByVal pa As String) As String pa1 = pa pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct + ct pa = pa + ConvertToChar(ct) Next Return (pa) End Function Public Function deco(ByVal pa As String) As String pa1 = pa

26

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 27: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

pa = For i = 0 To pa1Length - 1 ct = ConvertToInt64(ConvertToChar(pa1Substring(i 1))) ct = ct 2 pa = pa + ConvertToChar(ct) Next Return (pa) End Function End Class

iii Build-gtBuild the solutionNote Register the dll using regsvr32 tool or copy the dll to cwindowssystem32

Part ndashIIREFERENCING THE COMPONENT

1 Start the process 2 open VS NET 3File-gt New-gt Project-gt visual Basic Project -gt Windows Application rename the Windows Application if required4Project -gt Add Reference choose the com tab-gtBrowse the encodedll and click ok5Drag and Drop the following controls in the form

i 2 Label Boxesii 1 Text boxiii 3 Buttons

6Include the coding in each of the Respective Button click EventImports encodePublic Class Form1

Inherits SystemWindowsFormsFormPrivate Sub Button3_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button3Click TextBox1Text = End Sub Private Sub ENCRYPT_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ENCRYPTClick

Dim obj As New encodeClass1 Dim temp As String temp = TextBox1Text TextBox1Text = objenco(temp) End Sub

Private Sub Button2_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button2Click

Dim obj As New encodeClass1 Dim temp1 As String temp1 = TextBox1Text

27

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 28: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

TextBox1Text = objdeco(temp1) End Sub End Class

8 Execute the project

RESULT Thus the above program was executed suceessfully

Ex No 8

DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING DCOMNET

AIM To Create a component to retrieve message box information using DCOMNET

DESCRIPTION

Part ndash I

1 Start the process2 Open Visual Studio NET3 Goto File-gtNew-gtProject-gtClassLibrary|Empty Library-gtOK4 Goto Solution Explorer-gtRight Click-gtAdd-gtAdd Component|Add New Item-gtCOM

Class-_OK5 Add the following codings Save amp Build

Public Function test() As String Dim str = hai Return (str) End Function Public Function create() As String MsgBox(test()) End Function

Part ndash II1 Go To Start-gtMicrosoft VisualNet 2003-gtVisual StufioNet tools-gtCommand prompt

Setting environment for using Microsoft Visual Studio NET 2003 tools(If you have another version of Visual Studio or Visual C++ installed and wishto use its tools from the command line run vcvars32bat for that version)CDocuments and Settingsmcaadministratorgtsn -k mssnkMicrosoft (R) NET Framework Strong Name Utility Version 114322573Copyright (C) Microsoft Corporation 1998-2002 All rights reservedKey pair written to mssnkCDocument and Settingsmcaadministratorgt

28

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 29: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Copy mssnk to bin directory (locate the class library)2 start -gt settings -gt control panel-gtadministrative tools-gtcomponent services-gt computer-

gtmy computer-gtcom + Application -gt new -gt application -gtnext -gt create an empty application-gt choose the server Application -gt enter the new Application name (mssg) -gt next -gtchoose the interactive user-gt next-gtfinish

3 expand mssg -gt click the components -gtright click -gt new-gt component -gt next-gtinstall new event classes-gt select the class library1tlb(class library-gtbin-gt

open-gtnext-gtfinish

PART ndashIII

1 Open Visual studio net -gt file-gt new -gtProject-gtWindows Application2 Create one label boxone text box and one button in the form3 Include the following code in the Button click event

Imports msgPublic Class Form1

Inherits SystemWindowsFormsForm

Dim mo As New msgComClass1 Private Sub Button1_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles Button1Click textbox1text = motest() End Sub

End Class4execute the project

RESULT

Thus the component was created using DCOM

29

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 30: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Ex No9

DEVELOP A COMPONENT FOR RETRIEVING STOCK MARKET EXCHANGE INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module simplestocksinterface StockMarket float get_price(in string symbol)Note Save the above module as simplestocksidlCompile the saved module using the idlj compiler as follows

Cdevicorbagtidlj simplestocksidl After compilation a sub directory called simplestocks same as module name will be created and it generates the following files as listed belowCdevicorbagtcd simplestocksCdevicorbasimplestocksgtdir Volume in drive C has no label Volume Serial Number is 348A-27B7 Directory of Csujicorbasimplestocks

30

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 31: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

02062007 1138 AM ltDIRgt 02062007 1138 AM ltDIRgt 02062007 1138 AM 2071 StockMarketPOAjava02072007 0215 PM 2090 _StockMarketStubjava02072007 0215 PM 865 StockMarketHolderjava02072007 0215 PM 2043 StockMarketHelperjava02072007 0215 PM 359 StockMarketjava02072007 0215 PM 339 StockMarketOperationsjava02072007 0208 PM 226 StockMarketclass02072007 0208 PM 180 StockMarketOperationsclass02072007 0208 PM 2818 StockMarketHelperclass02072007 0208 PM 2305 _StockMarketStubclass02062007 1144 AM 2223 StockMarketPOAclass 11 File(s) 15519 bytes 2 Dir(s) 6887636992 bytes free

Cdevicorbasimplestocksgt Implement the interfaceimport orgomgCORBAimport simplestockspublic class StockMarketImpl extends StockMarketPOA private ORB orb public void setORB(ORB v)orb=v public float get_price(String symbol) float price=0for(int i=0iltsymbollength()i++) price+=(int)symbolcharAt(i)price=5return pricepublic StockMarketImpl()super()

Server Program

import orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport simplestockspublic class StockMarketServer public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() StockMarketImpl ss=new StockMarketImpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss)

31

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 32: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

StockMarket hrf=StockMarketHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(StockMarket) ncrfrebind(pathhrf) Systemoutprintln(StockMarket server is ready)ThreadcurrentThread()join()orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport simplestocksimport orgomgCosNamingNamingContextPackagepublic class StockMarketClient public static void main(String[] args) try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) NameComponent path[]=new NameComponent(NASDAQ) StockMarket market=StockMarketHelpernarrow(ncRefresolve_str(StockMarket))Systemoutprintln(Price of My company is+marketget_price(My_COMPANY))catch(Exception e)eprintStackTrace() Compile the above files as Cdevicorbagtjavac javaCdevicorbagtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Cdevicorbagtstart java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost

32

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 33: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

localhostCdevicorbagtStockMarket server is readyCdevicorbagtjava StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was executed successfull

Ex No 10

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

AIM To Create a Component for retrieving stock market exchange information using CORBA

DESCRIPTION

Steps required1 Define the IDL interface2 Implement the IDL interface using idlj compiler3 Create a Client Program4 Create a Server Program5 Start orbd6 Start the Server7 Start the client

Define IDL Interface

module weatherinterface forecast float get_min() float get_max()Note Save the above module as weatheridlCompile the saved module using the idlj compiler as follows Csowmiweathergtidlj weatheridl After compilation a sub directory called weather same as module name will be created and it generates the following files as listed belowCsowmiweathergtcd weatherCsowmiweatherweathergtdir Volume in drive C has no label

33

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 34: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Volume Serial Number is 348A-27B7 Directory of Csujiweatherweather03142007 0252 PM ltDIRgt 03142007 0252 PM ltDIRgt 03142007 0255 PM 2240 forecastPOAjava03142007 0255 PM 2729 _forecastStubjava03142007 0255 PM 796 forecastHolderjava03142007 0255 PM 1926 forecastHelperjava03142007 0255 PM 330 forecastjava03142007 0255 PM 319 forecastOperationsjava03152007 1042 AM 2144 forecastPOAclass03152007 1042 AM 167 forecastOperationsclass03152007 1042 AM 207 forecastclass03152007 1042 AM 2724 forecastHelperclass03152007 1042 AM 2403 _forecastStubclass 11 File(s) 15985 bytes 2 Dir(s) 1726103552 bytes freeCsowmiweatherweathergt

Implement the interfaceimport orgomgCORBAimport weatherimport javautilpublic 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=0ilt10i++) r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float min min=s[0] for(int i=1ilt10i++) if (mingts[i]) min =s[i] float mintemp=Mathabs((float)(min-32)59) return mintemppublic float get_max() for(int i=0ilt10i++)

34

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 35: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

r[i]=Mathabs(rrnextInt()) s[i]=Mathround((float)r[i]000000001) float max max=s[0] for(int i=1ilt10i++) if (maxlts[i]) max =s[i] float maxtemp=Mathabs((float)(max-32)59) return maxtemppublic weatherimpl()super() Server Programimport orgomgCORBAimport orgomgCosNamingimport orgomgCosNamingNamingContextPackageimport orgomgPortableServerimport orgomgPortableServerPOAimport javautilPropertiesimport weatherpublic class weatherserver public static void main(String[] args) try ORB orb=ORBinit(argsnull) POA rootpoa=POAHelpernarrow(orbresolve_initial_references(RootPOA)) rootpoathe_POAManager()activate() weatherimpl ss=new weatherimpl() sssetORB(orb) orgomgCORBAObject ref=rootpoaservant_to_reference(ss) forecast hrf=forecastHelpernarrow(ref) orgomgCORBAObject orf=orbresolve_initial_references(NameService) NamingContextExt ncrf=NamingContextExtHelpernarrow(orf) NameComponent path[]=ncrfto_name(forecast) ncrfrebind(pathhrf) Systemoutprintln(weather server is ready)orbrun()catch(Exception e)eprintStackTrace()

Client Program

import orgomgCORBAimport orgomgCosNamingimport weatherimport orgomgCosNamingNamingContextPackageimport javautil

35

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 36: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

public class weatherclient public static void main(String[] args) String city[]=Chennai Trichy Madurai CoimbatoreSalem Calendar cc=CalendargetInstance() try ORB orb=ORBinit(argsnull) NamingContextExt ncRef=NamingContextExtHelpernarrow(orbresolve_initial_references(NameService)) forecast fr=forecastHelpernarrow(ncRefresolve_str(forecast)) Systemoutprintln(tttW E A T H E R F O R E C A S T) Systemoutprintln(ttt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~) Systemoutprintln() Systemoutprintln(tDATE TIME CITY HIGHEST LOWEST ) Systemoutprintln(t TEMPERATURE TEMPERATURE) for(int i=0ilt5i++) Systemoutprint(t+ccget(CalendarDATE)+ccget(CalendarMONTH)+ccget(CalendarYEAR)+ +ccget(CalendarHOUR)+ +city[i]+ + ) Systemoutprint(Mathfloor(frget_min())+t t+Mathceil(frget_max())) Systemoutprintln() catch(Exception e)eprintStackTrace() Compile the above files as Csowmiweathergtjavac javaCsowmiweathergtstart orbd -ORBInitialPort 1050 -ORBInitialHost localhost

Csowmicorbagtstart java weatherserver -ORBInitialPort 1050 -ORBInitialHostlocalhostCsowmiweathergtweather server is readyCsowmicorbagtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localh

36

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 37: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

ost

Csowmiweathergtjava weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost

RESULT Thus the above program was created successfully

LIST OF MODEL QUESTIONS1 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 applications

5 Develop an Enterprise Java Bean for Library Operations

6 Create an Active-X 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 using DCOM NET

37

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 38: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

10 Develop a component for retrieving stock market exchange information using CORBA

11 Develop a component for retrieving weather forecast information using CORBA

12 Develop an Enterprise Java Bean for displaying Hello message from the server

13 Develop a middleware component for displaying Hello message from the server using

CORBA

14 Develop an Enterprise Java Bean for Student information system

VIVA QUESTIONS1 Define the term Middleware

Middleware is a software component that mediates between an application program and a network It manages the interaction between disparate applications across the heterogeneous computing platforms The ORB software that manages communication between objects is an example of a middleware program

2 What are the types of middleware1 General Middleware2 Service Specific Middleware

3 Enumerate the difference between general and service specific middlewareGeneral Middleware

bull It is a substrate for most clientserver applicationsbull It includes communication stacks distributed directories authentication

services network time RPC and queuing servicesbull Products like DCE NetWare LAN server and NetBIOS

Service Specific Middlewarebull It is needed to accomplish a particular client server type of servicebull It includes database specific middleware OLTP specific middleware

Groupware specific object specific middleware4 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 applicationsEJB 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 application5 When do you use EJB

EJBs are a good fit if your application has any of these requirements

38

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 39: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

Scalability If you have a growing number of users EJBs let you distribute your applicationrsquos components across multiple machines with location transparency to clientsData integrity EJBs give you easy to use distributed transactionsVariety 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

6 List any four exception raised in EJB1 System Exception- javarmiRemote Exception2 Application Exception- javalang Exception3 EJB specific Exception4 Create Exception5 Finder Exception

7 What do you meant by ACLA list of which entities are allowed to invoke which objects and methods

8 What is use of EJBObjectA 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

9 Define EJB serverAn 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 10 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

10 Write short note on Entity Beansbull Can be used concurrently by several clientsbull Are relatively long lived they are intended to exist beyond the lifetime of

any single clientbull Will survive a server crashbull Directly represent data in a database

11 What is the purpose of Finder methodFor entity EJBs a method used to look up existing Entity EJB objects The finsByPrimaryKey () method takes a primary key as its argument and returns a single reference to an Entity EJB Other finder methods can take arbitrary arguments and return either a single reference or set of references If a set of references is returned the finder method will return a set of primary keys in a data structure that implements the javautilEnumeration interface

12 Define the term HandleA serializable reference to a bean A handle can be stored to a file or other persistence store and used later to re obtain a reference to a remote bean

13 Define the term ServletA Java replacement for CGI Servlets are java classes that are invoked by a web server in response to HTTP requests and generate HTML as their output

14 Define Skeleton

39

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 40: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

In CORBA a server side proxy object that is responsible for retrieving arguments from the network and passing them to the program

15 List out the characteristics of stateful session beanA bean that preserves information about the state of its conversation with the client This conversation may consists of several calls that modify the conversation state followed by a final call that writes the result to a database

16 List out the characteristics of stateless session beanA bean that does not save information about the state of its conversation with a client

17 Define stubA client-side proxy for a remote routine The stub takes the arguments that are passed to it by the client passes them over the network to the server retrieves any return value and passes the return value back to the client

18 Give the software architecture of EJB1 A remote interface (a client interact with it)2 A Home interface (used for creating objects and for declaring business methods)3 A bean object (which performs business logic and EJB specific operations)4 A deployment descriptor (XML descriptor or some container specific features)5 A primary Key class (only for entity bean)

19 What is the need of Remote and Home interface Why canrsquot it be in oneThe Home interface is the way to communicate with the container that is responsible of creating locating and removing one or more beans

The remote interface is your link to the bean that will allow you to remotely access to all its methods and members

As you can see there are two distinct elements (the Container and the Beans)

20 Define the term EJBEnterprise Java Beans EJBs are written once run any-where middleware components

21 List out the EJBs Role1 EJB specifies an execution environment2 EJB exists in the middle tier3 EJB supports transaction processing4 EJB can maintain state5 EJB is simple

22 Give the Logical architecture of EJB1 The Client2 The server3 The database (or other persistent store)

23 List out the services of EJB containerbull Support for transactionsbull Support for management of multiple instancesbull Support for persistencebull Support for security

24 List out the Possible modes of transaction managementbull TX_NOT_SUPPORTED

40

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 41: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

bull TX_BEAN_MANAGEDbull TX_REQUIREDbull TX_SUPPORTSbull TX_REQUIRES_NEWbull TX_MANDATORY

25 Differentiate between Session and Entity beanSession Bean

bull Short-livedbull Accessed by single clientbull Shared by multiple clientsbull No primary key

Entity Beano Long-lived o Accessed by multiple clientso No sharingo It must have a primary key

26 What are tasks of Clientbull Finding the beanbull Getting access to a beanbull Calling the beanrsquos methodsbull Getting rid of the bean

27 List out the information available in deployment descriptor1 The name of the EJB class2 The name of the EJB home interface3 The name of the EJB remote interface4 ACLs of entities authorized to use each class or method5 For Entity beans a list of container-managed fields6 For session beans a value denoting whether the bean is stateful or stateless

28 List out the Roles in EJB1 Enterprise Bean Provider2 Deployer3 Application Assembler4 EJB Server Provider5 EJB Container Provider6 System Administrator

29 What are the steps are needed to design a EJB1 Find the Beans home interface2 Get access to the Bean3 Call the beans method with a string as argument and save the return value4 Display the return value to the user

30 What are the steps are needed to implement the EJB program1 Create the remote interface for the bean2 Create the beans home interface3 Create the beans implementation class4 Compile the remote interface home implementation class5 Create a session descriptor6 Create a manifest

41

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 42: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

7 Create an ejb-jar file8 Deploy the ejb-jar file9 Write a client10 Run the client

31 Define Manifest fileA Manifest is a text document that contains information about the contents of a jar- file Actually the jar utility will automatically create a manifest file even if none exists

32 When to use EJB beans1 Where you might currently use RPC mechanism such as RMI or CORBA2 Session Beans are intended to allow the application author to easily implement

portions of application code in middleware and to simplify access to this code33 List out the constraints in Session Beans

1 EJB cannot start new threads or use thread synchronization primitives2 EJB cannot directly access the underlying transaction manager3 EJBs are not allowed to change their javasecurityIdentity at runtime4 If the Session beans timeout value expires5 If the server crashes and is restarted6 If the server is shut down and restarted

34 Differentiate between Stateless Session and Stateful session beansStateless session bean

1 It have no states2 It have only one create () method and takes no argumentsStateful session bean

1 It has states2 It has more than one create () and have different arguments

35 List out the transitions of stateful session beanbull The bean can enter a transactionbull It can be passivatedbull It can be removed

36 Define CORBACORBA is a Standard defined by the Object Management Group (OMG) that enables

software components written in multiple computer languages and running on multiple computers to work together ie it supports multiple platforms

CORBA is a mechanism in software for normalizing the method-call semantics between application objects that reside either in the same address space (application) or remote address space (same host or remote host on a network)

37 Differentiate Between RMI and CORBARMI 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 its limited to only calling other Java applications

38 List out the characteristics of CORBA1 CORBA IDL2 Dynamic invocation

42

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 43: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

3 Portable object adapter4 Interoperability5 COM CORBA Bridging6 Multiple Programming Mapping

39 What is the advantage of using CORBAv Language Independencev OS Independencev Freedom from Technologiesv Strong data typingv High tune abilityv Freedom from data transfer detailsv Compression

40 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

41 Define DIIDII stands for Dynamic Innovation Interface

42 What is the use of ORB InterfaceIt is use to converts object reference to string and string to object reference

43 What is the use of IDL CompilerIt is used to transformation between IDL definition and target programming language

44 What do you meant by GIOPThe GIOP stands for General Inter-ORB Protocol It is a high level standard protocol for communication between ORBs

45 What do you meant by IIOPIIOP stands for Internet Inter-ORB Protocol It is standard protocol for communication between ORBs on TCPIP based networks

46 Define Object AdapterThe Object Adapter is used to register instances of the generated code classes

Generated Code Classes are the result of compiling the user IDL code which translates the high-level interface definition into an OS- and language-specific class base for use by the user application

47 List out the types of AdapterBasic Object AdapterPortable Object AdapterLibrary Object AdapterObject Oriented Data base Adapter

48 List out the types of Activation Polices in BOAi Shared Serverii Unshared serveriii Server-per-methodiv Persistent server

49 What do you meant by socketSocket is an object it used to communicate between client and server

43

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 44: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

50 What is the use of object handlesObject handles are used to reference object instances in a programming language context

In C++ - The handles are called Object reference51 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

52 Define MarshallingIt refers to the process of translating input parameters to a format that can be transmitted across a network

53 Define unmarshallingIt is the reverse of marshalling this process converts a data into output parameters

54 What are the steps are needed to build CORBA Application1 Define the serverrsquos interfaces using IDL2 Choose the implementation approach for the serverrsquos interface3 Use the IDL compiler to generate client stubs and server skeletons for the server

interfaces4 Implement the server interfaces5 Compile the server application6 Run the server application

55 What is the use of Factory methodA Factory is a special type of distributed object whose main purpose is to create other distributed objects

56 What is the advantage of using NET1 It is a language and platform independent2 It support and maps to all languages3 The components are created very easily

57 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

58 What are the components of NETbull Lit Boxbull Labelbull Textboxbull Buttonbull Staticbull Edit

59 Define CLRi CLR ndash Common Language Runtimeii It is a multi language execution environmentiii It described as the execution engine of NETiv It manages the execution of programs

60 List out the goals of CLR

44

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 45: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

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 amp profiling support

61 Define MSILMicrosoft Intermediate LanguageIt defines a set of portable instructions that are independent of any specific CPU It is the job of the CLR to translate this intermediate code into executable code when the program is compiled

62 What do you meant by Meta dataData about the data is called Meta data

63 What do you meant by JIT compilerIt stands Just In TimeJIT compiler converts MSIL into native code on a demand basis as each part of the program is needed

64 Define COMComponent Object Model (COM) is a binary-interface standard for software

componentry introduced by Microsoft in 1993 It is used to enable interprocess communication and dynamic object creation in a large range of programming languages The term COM is often used in the software development industry as an umbrella term that encompasses the OLE OLE Automation ActiveX COM+and DCOM technologies65 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

66 What are the types of Iunknown methodsAddRef()- Increments the reference count for an interface on an objectQuery Interface ()- Retrieves pointer to the supported interfaces on an objectRelease()- Decrements the reference count for an interface on an object

67 What is the use of AddRef methodThe 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

68 What is need of Query Interface methodIt is used to specifying an IID allows a caller to retrieve references to the different interfaces the component implements

69 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 clients code) has no further need for it and hence if this reference count has dropped to zero it may be time to destroy itself

70 What is use of CreateInstance()CreateInstance() method to create an object which exposes an interface identified by the IID_ISomeObject GUID

71 What is the use of CoCreateInstance()

45

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 46: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

The CoCreateInstance() API can be used by an application to directly create a COM object without acquiring the objects class factory CoCreateInstance() API itself will invoke the CoGetClassObject() API to obtain the objects class factory and then use the class factorys CreateInstance() method to create the COM object

72 Write a short note on Class FactoryA 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

73 Write short note on IDL ModulesIDL modules create separate name spaces for IDL definitions This prevents potential name conflicts among identifiers used in different domains

74 What are the types of RMI Applications1 Client2 Server

75 What are the steps are needed to create Distributed application by using RMI1 Designing and implementing the components of your distributed application2 Compiling sources3 Making classes network accessible4 Starting the application

76 List out the steps for designing and implementing remote interfaces1 Defining the remote interface2 Implementing the remote objects3 Implementing the clients

77 What is the use of RMI registryRMI 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

78 Define Compute EngineThe Computing Engine is a remote object on the server that takes tasks from clients runs the tasks and returns any results

79 What are the steps are needed to write a RMI Programming1 Designing a remote Interface2 Implementing a Remote Interface3 Declaring the Remote Interfaces Being Implemented4 Defining the Constructor for the Remote Object

Providing Implementations for each remote method

46

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 47: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

SUDHARSAN ENGINEERING COLLEGE

SATHIYAMANGALAM

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

MIDDLEWARE TECHNOLOGY LABORATORY

LAB MANUAL

47

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 48: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

YEARSEM IVVII

ACADEMIC YEAR2010-2011 ODD SEM

PREPARED BY RAJUC

CONTENTS

SNo LIST OF EXPERIMENTS

Pg No

Date of

Performance

Date of

Submissi

on

Assessme

nt(Max10 marks)

Remarks

Sign Of the

Lab in charge

1DOWNLOADING VARIOUS FILES FROM

VARIOUS SERVERS USING RMI

2DRAW THE VARIOUS GRAPHICAL SHAPES AND

DISPLAY IT USING OR WITHOUT USING BDK

3DEVELOP AN ENTERPRISE JAVA BEAN FOR

BANKING OPERATIONS

4DEVELOP AN ENTERPRISE JAVA BEAN FOR

LIBRARY OPERATIONS

5CREATE AN ACTIVE- X CONTROL FOR FILE

OPERATIONS

6DEVELOP A COMPONENT FOR CONVERTING

THE CURRENCY VALUES USING COM NET

7DEVELOP A COMPONENT FOR ENCRYPTION

AND DECRYPTION USING COM NET

8DEVELOP A COMPONENT FOR RETRIEVING

INFORMATION FROM MESSAGE BOX USING

DCOM NET

9DEVELOP A MIDDLEWARE COMPONENT FOR

RETRIEVING STOCK MARKET EXCHANGE

INFORMATION USING CORBA

10DEVELOP A MIDDLEWARE COMPONENT

FOR RETRIEVING WEATHER FORECAST

48

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49

Page 49: Files CSE Manual VII IT1404 - Middleware Technologies Laboratory.doc

INFORMATION USING CORBA

QUESTION BANK

TOTAL MARKS

AVERAGE MARKS (out of 10)

49