IT 1404- MIDDLEWARE TECHNOLOGIES LAB MANUAL SRINVASAN ENGINEERING COLLEGE

SRINVASAN ENGINEERING COLLEGE
PERAMBALUR - 621212
DEPARTMENT OF INFORMATION TECHNOLOGY
IT 1404- MIDDLEWARE TECHNOLOGIES
LAB MANUAL
Academic year (2013-2014) VII SEMESTER
PREPARED BY
S.SATHISHKUMAR
Assistant Professor (IT),
Srinivasan Engineering College, Perambalur-621212
PREFACE
Middleware Technologies Lab manual is intended to provide
a basic knowledge of middleware software programming for
students and readers. To develop software development skills in
middleware programming like CORBA and Students will have
the proficiency to develop projects in distributed environment.
Acknowledgement
I give all glory and thanks to our god almighty for showering upon, the
necessary wisdom and grace for accomplishing the lab manual.
I am highly indebted to our respectable chairman and founder of Dhanalakshmi
Srinivasan Group of institutions, SHRI.A.SRINIVASAN for providing with
sufficient facilities that contributed to the success in this endeavor.
I
am
very
thankful
to
our
reputable,
beloved
principal,
Dr.B.KARTHIKEYAN M.E., Ph.D., for his continuous encouragement and for
motivating me to complete this lab manual.
I would like to express my sincere thanks and deep sense of gratitude to our
Head of the Department, Mrs. P. MANJULA M.E for his valuable guidance,
suggestions and constant encouragement paved way for the completion of the manual.
Contents
EX.NO
NAME OF THE EXPERIMENT
1
Create a distributed application to download various
files from various servers using RMI
2
Create a Java Bean to draw various graphical shapes
and display it using or without using BDK
3
Develop an Enterprise Java Bean for Banking
operations
4
Develop an Enterprise Java Bean for Library
operations
5
Create an Active-X control for file operations
6
Develop a component for converting the currency
values using COM/.NET
7
Develop a component for encryption and decryption
using COM/.NET
8
Develop a component for retrieving information from
message box using DCOM/.NET
9
Develop a middleware component for retrieving Stock
Market Exchange information using CORBA
10
Develop a middleware component for retrieving
weather forecast information using CORBA
INTRODUCTION OF THE LANGUAGE
In its most general sense, middleware is computer software that provides
services to software applications beyond those available from the operating system.
Middleware can be described as "software glue”. Thus middleware is not obviously
part of an operating system, not a database management system, and neither is it part
of one software application. Middleware makes it easier for software developers to
perform communication and input/output, so they can focus on the specific purpose of
their application. To compile and run Java program code you need to download JDK
(Java Development Kit).
MAIN FEATURES MIDDLEWARE TECHNOLOGIES
The term is most commonly used for software that enables communication and
management of data in distributed applications. In this more specific sense middleware can
be described as “the dash in 'client-server'” (or the '-to-' in peer-to-peer for that matter).
Object Web defines middleware as: "The software layer that lies between the
operating system and applications on each side of a distributed computing system in a
network." Services that can be regarded as middleware include enterprise application
integration, data integration, message oriented middleware (MOM), object request brokers
(ORBs), and the enterprise service bus (ESB)
Distributed computing system middleware can loosely be divided into two categories
– those that provide human-time services (such as web request servicing) and those that
perform in machine-time. This latter middleware is somewhat standardized through the
Service Availability Forum and is commonly used in complex, embedded systems within
telecom, defense and aerospace industries.
APPLICATIONS
1. The primary role of middleware systems is to transfer data between applications.
Typically between Frontend and Backend applications, one or other of which, may be
packaged applications. The data transfer may be in one, or both directions.
2. Middleware applications decouple the Frontend and Backend applications in order to
enable changes to the Backend systems to be transparent to the Frontend applications
and vice versa.
3. The primary functions of the middleware software are data generation, validation,
authorization, conversion, re-formatting, transaction mapping and logging. They add
value to transactions that are initiated by Frontend systems and are intended for
processing on Backend systems (and vice versa).
4. Application to application interfaces; represent the majority of business functions in a
middleware application.
5. Middleware applications receive input from external applications and provide a
response, based upon internal processing performed, or responses received from
destination applications. Internal Logical Files (ILF), other than log and error files,
are not maintained as part of this processing.
6. Processes (as opposed to files) are the major contributor to the application size.
7. Middleware processes tend to comprise multiple sub-processes. IFPUG guidelines
apply at the elementary process level.
8. The middleware processes do not have a predominant role that defines the process
type according to the IFPUG classifications of External Input, External Output, and
External Enquiry.
9. Middleware applications usually support online, real-time processing as opposed to
batch processing.
LIST OF EXPERIMENTS
1. Create a distributed application to download various files from various servers
using RMI.
2. Create a Java Bean to draw various graphical shapes and display it using or
without using BDK.
3. Develop an Enterprise Java Bean for Banking operations.
4. Develop an Enterprise Java Bean for Library operations.
5. Create an Active-X control for file operations.
6. Develop a component for converting the currency values using COM/.NET.
7. Develop a component for encryption and decryption using COM/.NET.
8. Develop a component for retrieving information from message box using
DCOM/.NET.
9. Develop a middleware component for retrieving Stock Market Exchange
information using CORBA.
10. Develop a middleware component for retrieving weather forecast information
using CORBA.
IT 1404- Middleware Technologies lab
Objective
To give the students an overview of Client Server concepts,
middleware and RPC. An overview of EJB , EJB architecture and its roles
EJB , beans and building an EJB application, CORBA architecture and
object model, software quality assurance and measuring user satisfaction.
Create a distributed application to download various files from
Ex.No:1
various servers using RMI.
Aim: - To Create a program to download files from various servers using
RMI
Description:1. Define the interface.
2. Interface must extend Remote
3. All methods must throw an exception RemoteException individually
4. Implement the interface.
5. Create a server program.
6. Create a Client Program.
7. Generate stubs and skeletons using rmic tool.
8. Start the server.
9. Start the client.
10.Once the process is over stop the client and server respectively.
Program:
Part 1 : Interface Defintion
import java.rmi.*;
public interface fileinterface extends Remote
{
public byte[] downloadfile(String s) throws RemoteException;
}
Part 2. Interface Implementation
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
public class fileimplement extends UnicastRemoteObject implements fileinterface
{
private String name;
public fileimplement(String s)throws RemoteException
{
super();
name=s;
}
public byte[] downloadfile(String fn)
{
try
{
File fi=new File(fn);
byte buf[]=new byte[(int)fi.length()];
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(fn));
bis.read(buf,0,buf.length);
bis.close();
return(buf);
}
catch(Exception ee)
{
System.out.println("Error:"+ee.getMessage());
ee.printStackTrace();
return(null);}}}
Part 3 : Server Part
import java.rmi.*;
import java.io.*;
import java.net.*;
public class fileserver
{
public static void main(String args[])
{
try
{
fileimplement fi=new fileimplement("fileserver");
Naming.rebind("//127.0.0.1/fileserver",fi);
}
catch(Exception e)
{
System.out.println(" "+e.getMessage());
e.printStackTrace();
}
}
}
Part 4: Client Part
import java.net.*;
import java.rmi.*;
import java.io.*;
public class fileclient
{
public static void main(String[] args)
{
try
{
InetAddress addr=InetAddress.getLocalHost();
String address=addr.toString().substring(addr.toString().indexOf("/")+1);
String url="rmi://"+ address + "/fileserver";
fileinterface f1=(fileinterface)Naming.lookup(url);
byte[] data=f1.downloadfile(args[0]);
File ff=new File("f1.txt");
BufferedOutputStream bos=new BufferedOutputStream(new
FileOutputStream(ff.getName()));
bos.write(data,0,data.length);
bos.flush();
bos.close();
}
catch(Exception e)
{
System.out.println(" "+e.getMessage());
e.printStackTrace();
}
}
}
Part –5 Compile all the files as follows
C:\suji\rmi>javac *.java
C:\suji\rmi>
Part – 6 Generate stubs and skeletons as follows
C:\suji\rmi>rmic fileimplement
.
C:\suji\rmi>dir *.class
Volume in drive C has no label.
Volume Serial Number is 348A-27B7
The Following files are generated
Directory of C:\suji\rmi
02/13/2007 02:47 PM
231 fileinterface.class
02/13/2007 02:47 PM
1,120 fileimplement.class
02/13/2007 02:47 PM
1,458 fileclient.class
02/13/2007 02:47 PM
850 fileserver.class
02/13/2007 02:49 PM
3,262 fileimplement_Stub.class
02/13/2007 02:49 PM
1,738 fileimplement_Skel.class
6 File(s)
8,659 bytes
0 Dir(s) 6,812,475,392 bytes free
C:\suji\rmi>
Part – 7 : Start rmiregistry as given below . If registry is properly started, a window will be
opened
C:\suji\rmi>start rmiregistry
C:\suji\rmi>
Part – 8 : Start the server
C:\suji\rmi>java fileserver
Output:
Part – 9: Start the client
C:\suji\rmi>java fileclient c:\suji\corba\StockMarketClient.java
C:\suji\rmi>type f1.txt
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import simplestocks.*;
import org.omg.CosNaming.NamingContextPackage.*;
public class StockMarketClient
{
public static void main(String[] args)
{
try
{
ORB orb=ORB.init(args,null);
NamingContextExt ncRef=NamingContextExtHelper.narrow(orb.resolve_initial_r
eferences("NameService"));
//NameComponent path[]={new NameComponent("NASDAQ","")};
StockMarket market=StockMarketHelper.narrow(ncRef.resolve_str("StockMarket
"));
System.out.println("Price of My company is"+market.get_price("My_COMPANY"));
}
catch(Exception e){
e.printStackTrace();
}
}
}
C:\suji\rmi>
Note: The above procedure works fine for inprocess (ie) if the client and server reside on
same machine.If server resides on another machine remote IP address of the server must
be provided by the client [ > java fileclient 192.168.0.34 filename]
Result:
Thus the RMI program was executed and compiled successfully.
Viva questions:
1. Define RMI:
The Java Remote Method Invocation Application Programming
Interface (API), or Java RMI, is a Java API that performs the objectoriented equivalent of remote procedure calls (RPC), with support for
direct transfer of serialized Java objects and distributed garbage
collection.
2. What is RMI registry:
Registry is a remote interface to a simple remote object registry
that provides methods for storing and retrieving remote object references
bound with arbitrary string names.
3. What is client and server:
The client–server model is a distributed application structure in
computing that partitions tasks or workloads between the providers of a
resource or service, called servers, and service requesters, called clients.
4. What is interface:
An interface defines the protocol of communication between two
separate components of a system. The interface describes what services are
provided by a component and the protocol for using those services.
Ex.No.2 Create a Java Bean to draw various graphical shapes using BDK or
without Using BDK.
Aim:- To Create a Java Bean to draw various graphical shapes using BDK or
without Using BDK.
Description:
1. Start the Process.
2. Set the classpath for java as given below
C:\suji\bean>set path=%path%;c:\j2sdk1.4.1\bin;
3. Write the Source code as given below.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code="shapes" width=400 height=400></applet>*/
public class shapes extends Applet implements ActionListener
{
List list;
Label l1;
Font f;
public void init()
{
Panel p1=new Panel();
Color c1=new Color(255,100,230);
setForeground(c1);
f=new Font("Monospaced",Font.BOLD,20);
setFont(f);
l1=new Label("D R A W I N G V A R I O U S G R A P H I C A L S H A P E S",Label.CENTER);
p1.add(l1);
add(p1,"NORTH");
Panel p2=new Panel();
list=new List(3,false);
list.add("Line");
list.add("Circle");
list.add("Ellipse");
list.add("Arc");
list.add("Polygon");
list.add("Rectangle");
list.add("Rounded Rectangle");
list.add("Filled Circle");
list.add("Filled Ellipse");
list.add("Filled Arc");
list.add("Filled Polygon");
list.add("Filled Rectangle");
list.add("Filled Rounded Rectangle");
p2.add(list);
add(p2,"CENTER");
list.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
repaint();
}
public void paint(Graphics g)
{
int i;
Color c1=new Color(255,120,130);
Color c2=new Color(100,255,100);
Color c3=new Color(100,100,255);
Color c4=new Color(255,120,130);
Color c5=new Color(100,255,100);
Color c6=new Color(100,100,255);
if (list.getSelectedIndex()==0)
{
g.setColor(c1);
g.drawLine(150,150,200,250);
}
if (list.getSelectedIndex()==1)
{
g.setColor(c2);
g.drawOval(150,150,190,190);
}
if (list.getSelectedIndex()==2)
{
g.setColor(c3);
g.drawOval(290,100,190,130);
}
if (list.getSelectedIndex()==3)
{
g.setColor(c4);
g.drawArc(100,140,170,170,0,120);
}
if (list.getSelectedIndex()==4)
{
g.setColor(c5);
int x[]={130,400,130,300,130};
int y[]={130,130,300,400,130};
g.drawPolygon(x,y,5);
}
if (list.getSelectedIndex()==5)
{
g.setColor(Color.cyan);
g.drawRect(100,100,160,150);
}
if (list.getSelectedIndex()==6)
{
g.setColor(Color.blue);
g.drawRoundRect(190,110,160,150,85,85);
}
if (list.getSelectedIndex()==7)
{
g.setColor(c2);
g.fillOval(150,150,190,190);
}
if (list.getSelectedIndex()==8)
{
g.setColor(c3);
g.fillOval(290,100,190,130);
}
if (list.getSelectedIndex()==9)
{
g.setColor(c4);
g.fillArc(100,140,170,170,0,120);
}
if (list.getSelectedIndex()==10)
{
g.setColor(c5);
int x[]={130,400,130,300,130};
int y[]={130,130,300,400,130};
g.fillPolygon(x,y,5);
}
if (list.getSelectedIndex()==11)
{
g.setColor(Color.cyan);
g.fillRect(100,100,160,150);
}
if (list.getSelectedIndex()==12)
{
g.setColor(Color.blue);
g.fillRoundRect(190,110,160,150,85,85);
}
}
}
1. Save the above file as shapes. java
2. compile the file as
C:\suji\bean>javac shapes.java
C:\suji\bean>
3. If BDK is not used then execute the file as
C:\suji\bean>appletviewer shapes.java
4. Stop the process
OUTPUT:-
Result:
Thus the Java Bean to draw various graphical shapes was executed and
compiled successfully.
VIVA
1. What is BDK?
The Beans Development Kit (BDK) is intended to support the early development of
JavaBeans components and to act as a standard reference base for both bean developers
and tool vendors.
2. What is meant by Applet?
An applet is a small Internet-based program written in Java, a programming language
for the Web, which can be downloaded by any computer. The applet is also able to run
in HTML. The applet is usually embedded in an HTML page on a Web site and can be
executed from within a browser.
3. What is AWT?
The Abstract Window Toolkit (AWT) is Java's original platform-independent
windowing, graphics, and user-interface widget toolkit.
Ex.No:3
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 C:\suji\atm>set path=%path%;c:\j2sdk1.4.1\bin;
3. Set class path as C:\suji\atm>set
classpath=%classpath%;c:\j2sdkee1.2.1\lib\j2ee.jar;
4. Define the home interface
5. Compile all the files
C:\suji\atm\javac *.java
6. Select Start->Programs->BEA Wblogic Platform 8.1->Other Development
Tools->Weblogic Builder.
7. Select File –>Open->atm ->open
8. A window will be displayed indicating the JNDI name
9. File->Save
10.File->Archive->Save
11.After getting the successful message goto start programs->BEA weblogic
platform 8.1-> user projects->my domain->start server.
12.If the server is in running mode without any exception goto internet
explorer
13.Type http://localhost:7001/console
14.A window will be displayed which prompt you for the username and
password as follows.
Program:
import javax.ejb.*;
import java.io.Serializable;
import java.rmi.*;
public interface atmhome extends EJBHome
{
public atmremote create(int accno,String name,String type,float balance)throws
RemoteException,CreateException;
}
Save the above interface as atmhome.java
1. Define the Remote Interface.
import java.io.Serializable;
import javax.ejb.*;
import java.rmi.*;
public interface atmremote extends EJBObject
{
public float deposit(float amt) throws RemoteException;
public float withdraw(float amt) throws RemoteException;
}
Save the remote interface as atmremote.java
2. Write the implementation.
import javax.ejb.*;
import java.rmi.*;
public class atm implements SessionBean
{
int acno;
String name1;
String tt;
float bal;
public void ejbCreate(int accno,String name,String type,float balance)
{
acno=accno;
name1=name;
tt=type;
bal=balance;
}
public float deposit(float amt)
{
return(bal+amt);
}
public float withdraw(float amt)
{
return(bal-amt);
}
public atm()
{}
public void ejbRemove(){}
public void ejbActivate(){}
public void ejbPassivate(){}
public void setSessionContext(SessionContext sc){}
}
Save the file as atm.java
3. Write the Client part.
import javax.rmi.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.naming.NamingException;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import java.util.Properties;
public class atmclient
{
public static void main(String args[]) throws Exception
{
float bal=0;
String tt=" ";
Properties props = new Properties();
props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContex
tFactory");
props.setProperty(InitialContext.PROVIDER_URL, "t3://localhost:7001");
props.setProperty(InitialContext.SECURITY_PRINCIPAL,"");
props.setProperty(InitialContext.SECURITY_CREDENTIALS," ");
InitialContext initial = new InitialContext(props);
Object objref = initial.lookup("atm2");
atmhome home = (atmhome)PortableRemoteObject.narrow(objref,atmhome.class);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int ch=1;
String name;
int acc;
System.out.println("Enter the Details");
System.out.println("Enter the Account Number:");
acc=Integer.parseInt(br.readLine());
System.out.println("Enter Ur Name:");
name=br.readLine();
while(ch<=4)
{
System.out.println("\t\tBANK OPERATIONS");
System.out.println("\t\t***************");
System.out.println("");
System.out.println("\t\t1.DEPOSIT");
System.out.println("\t\t2.WITHDRAW");
System.out.println("\t\t3.DISPLAY");
System.out.println("\t\t4.EXIT");
System.out.println("\t\tENTER UR OPTION:");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.println("Enter the Transaction type;");
tt=br.readLine();
atmremote bb= home.create(acc,name,tt,10000);
System.out.println("Entering");
System.out.println("Enter the transaction amt:");
float amt=Float.parseFloat(br.readLine());
bal=bb.deposit(amt);
System.out.println("Balance after deposit=" +bal);
break;
case 2:
System.out.println("Enter the Transaction type;");
tt=br.readLine();
bb= home.create(acc,name,tt,bal);
System.out.println("Entering");
System.out.println("Enter the transaction amt:");
amt=Float.parseFloat(br.readLine());
bal=bb.withdraw(amt);
System.out.println("Balance after withdraw" + bal);
break;
case 3:
System.out.println("Status of the Customer");
System.out.println("Account Number:"+acc);
System.out.println("Name of the Customer:"+name);
System.out.println("Transaction type:"+tt);
System.out.println("Balance"+bal);
break;
case 4:
System.exit(0);
} //switch
}//while
}//main
}//class
OUTPUT:
WebLogic Server Administration Console
Sign in to work with the WebLogic Server domain mydomain
Username:
suji
Password:
Sign In
1. If the username and password is correct then the following page is displayed
Welcome to BEA WebLogic Server Home
Connected to : localhost :7001
Logout
You are logged in as : suji
Information and Resources
Helpful Tools
General Information
Convert weblogic.properties
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 Application's Security
Settings
Domain
Applications
Realms
Servers
EJB Modules
Clusters
Web Application Modules
Machines
Connector Modules
Startup & 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
Trap Destinations
FileT3
Templates
Connectivity
Messaging Bridge
Destination Keys
WebLogic Tuxedo Connector
Bridges
Stores
Tuxedo via JOLT
JMS Bridge Destinations
Servers
Tuxedo via WLEC
General Bridge Destinations
JMS
Connection Factories
Distributed Destinations
Foreign JMS Servers
Copyright (c) 2003 BEA Systems, Inc. All rights reserved.
2. 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
sum.jar 100
_appsdir_atm_jar
atm.jar
100
_appsdir_bank_jar bank.jar 100
_appsdir_hello_jar hello.jar 100
_appsdir_ss_jar
ss.jar
100
3. To check for the successfulness click the required jar file.[Note:- here the file is atm.jar]
4. 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.
Session
atm2
Test this EJB
5. Select the link Test this EJB. The following message will be displayed if successful
The EJB atm2 has been tested successfully with a JNDI name of atm2
Continue
6. Before running the client set the path as follows
C:\suji\atm>set path=%path%c:\j2sdk1.4.1\bin;
C:\suji\atm>set classpath=%classpath%;c:\j2sdkee1.2.1\lib\j2ee.jar;
C:\suji\atm>set classpath=weblogic.jar;%classpath%;
7. Start the client
C:\suji\atm>java atmclient
Enter the Details
Enter the Account Number:
101
Enter Ur Name:
xxx
BANK OPERATIONS
***************
1.DEPOSIT
2.WITHDRAW
3.DISPLAY
4.EXIT
ENTER UR OPTION:
1
Enter the Transaction type;
dep
Entering
Enter the transaction amt:
5000
Balance after deposit=15000.0
BANK OPERATIONS
***************
1.DEPOSIT
2.WITHDRAW
3.DISPLAY
4.EXIT
ENTER UR OPTION:
2
Enter the Transaction type;
with
Entering
Enter the transaction amt:
4000
Balance after withdraw11000.0
BANK OPERATIONS
***************
1.DEPOSIT
2.WITHDRAW
3.DISPLAY
4.EXIT
ENTER UR OPTION:
3
Status of the Customer
Account Number:101
Name of the Customer:xxx
Transaction type:with
Balance11000.0
BANK OPERATIONS
***************
1.DEPOSIT
2.WITHDRAW
3.DISPLAY
4.EXIT
ENTER UR OPTION:
4
Result:
Thus the EJB for banking operations program was compiled and executed successfully.
VIVA
1. What is EJB:
Enterprise JavaBeans (EJB) is an architecture for setting up program components,
written in the Java programming language, that run in the server parts of a computer
network that uses the client/server model.
2. What is Web Server ?
A Web Server is a computer system that delivers web pages. Every web server
has an IP address and possibly a domain name.
3. What is HTTP?
Hyper Text Transfer Protocol is the underlying protocol used by the World
Wide Web. HTTP defines how messages are formatted and transmitted and what
action web servers and browsers should take in response to various commands.
Ex.No:4 Develop a Component using EJB for Library Operations.
AIM: To Create a component for Library Operations using EJB
Description:1. Start the Process.
2. Set the path as follows:
i. C:\ss>set path=%path%;c:\j2sdk1.4.1\bin;
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
ii.
C:\ss>set classpath=%classpath%;c:\j2sdkee1.2.1\lib\j2ee.jar;
iii.
Define the Home Interface
Define the Remote Interface
Implement the EJB
Write the Client Part
Compile all the files
Start->Programs->BEA Weblogic Platform 8.1->Other Development Tools->Weblogic Builder
File ->Open->ss->Ok
File->save
File->Archive->Name the jarfile(library.jar)->Ok
Tools->Validate Descriptors->ejbc Successful
Copy the weblogic.jar(c:\bea\weblogic81\lib\weblogic.jar) to the folder where Your EJB
module is located (In the Program it is c:\ss)
Copy the Jar file created by you (here it is library. jar) to
c:\bea\userprojects\mydomain\applications.
Start the server(Start->programs->Bea web logic Platform8.1->User Projects->mydomain>Start Server
If the server is started successfully without any exception then go to the next step.
Open Internet Explorer->Type the URL (http://localhost:7001/console) in the address
box.(Type the user name and password)
If the username and password is correct a page will be displayed.
In that page click->EJB Modules
Click the link of the jar file that You have created (Here it is ss.jar)
Click the testing tab.
Click the link Test this EJB.
In the client part set the path as
C:\ss\set classpath=weblogic.jar;%classpath%;
24. Run the client
25. Terminate the Client and server.
PROGRAM:
import javax.ejb.*;
import java.io.Serializable;
import java.rmi.*;
public interface libraryhome extends EJBHome
{
public libraryremote create(int id,String title,String author,int nc)throws
RemoteException,CreateException;
}
Save the above file as libraryhome.java
1. Define the Remote Interface
import java.io.Serializable;
import javax.ejb.*;
import java.rmi.*;
public interface libraryremote extends EJBObject
{
public boolean issue(int id,String title,String author,int nc) throws RemoteException;
public boolean receive(int id,String title,String author,int nc) throws RemoteException;
public int ncpy() throws RemoteException;
}
Save the above file as libraryremote.java
2. Implement the EJB
import javax.ejb.*;
import java.rmi.*;
public class library implements SessionBean
{
int bkid;
String tit;
String auth;
int nc1;
boolean status=false;
public void ejbCreate(int id,String title,String author,int nc)
{
bkid=id;
tit=title;
auth=author;
nc1=nc;
}
public int ncpy()
{
return nc1;
}
public boolean issue(int id,String tit,String auth,int nc)
{
if(bkid==id)
{
nc1--;
status=true;
}
else
{
status=false;
}
return(status);
}
public boolean receive(int id,String tit,String auth,int nc)
{
if(bkid==id)
{
nc1++;
status=true;
}
else
{
status=false;
}
return(status);
}
public void ejbRemove(){}
public void ejbActivate(){}
public void ejbPassivate(){}
public void setSessionContext(SessionContext sc){}
}
Save the above file as library.java
3. Write the Client Part
import javax.rmi.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.*;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.naming.*;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import java.util.Properties;
public class libraryclient
{
public static void main(String args[]) throws Exception
{
Properties props = new Properties();
props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory
");
props.setProperty(InitialContext.PROVIDER_URL, "t3://localhost:7001");
props.setProperty(InitialContext.SECURITY_PRINCIPAL,"");
props.setProperty(InitialContext.SECURITY_CREDENTIALS,"");
InitialContext initial = new InitialContext(props);
Object objref = initial.lookup("library2");
libraryhome home= (libraryhome)PortableRemoteObject.narrow(objref,libraryhome.class);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int ch;
String tit,auth;
int id,nc;
boolean st;
System.out.println("Enter the Details");
System.out.println("Enter the Account Number:");
id=Integer.parseInt(br.readLine());
System.out.println("Enter The Book Title:");
tit=br.readLine();
System.out.println("Enter the Author:");
auth=br.readLine();
System.out.println("Enter the no.of copies");
nc=Integer.parseInt(br.readLine());
int temp=nc;
do
{
System.out.println("\t\tLIBRARY OPERATIONS");
System.out.println("\t\t***************");
System.out.println("");
System.out.println("\t\t1.ISSUE");
System.out.println("\t\t2.RECEIVE");
System.out.println("\t\t3.EXIT");
System.out.println("\t\tENTER UR OPTION:");
ch=Integer.parseInt(br.readLine());
libraryremote bb= home.create(id,tit,auth,nc);
switch(ch)
{
case 1:
System.out.println("Entering");
nc=bb.ncpy();
if(nc>0)
{
if(bb.issue(id,tit,auth,nc))
{
System.out.println("BOOK ID IS:"+id);
System.out.println("BOOK TITLE IS:"+tit);
System.out.println("BOOK AUTHOR IS:"+auth);
System.out.println("NO. OF COPIES :"+bb.ncpy());
nc=bb.ncpy();
System.out.println("Sucess");
break;
}
}
else
System.out.println("Book is not available");
break;
case 2:
System.out.println("Entering");
if(temp>nc)
{
System.out.println("temp"+temp);
if(bb.receive(id,tit,auth,nc))
{
System.out.println("BOOK ID IS:"+id);
System.out.println("BOOK TITLE IS:"+tit);
System.out.println("BOOK AUTHOR IS:"+auth);
System.out.println("NO. OF COPIES :"+bb.ncpy());
nc=bb.ncpy();
System.out.println("Sucess");
break;
}
}
else
System.out.println("Invalid Transaction");
break;
case 3:
System.exit(0);
} //switch
}while(ch<=3 && ch>0);
}//main
}//class
Save the above file as libraryclient.java
4. Compile all the files
C:\ss>javac *.java
C:\ss>
5.
6.
7.
8.
9.
Start->Programs->BEA Weblogic Platform 8.1->Other Development Tools->Weblogic Builder
File ->Open->ss->Ok
File->save
File->Archive->Name the jarfile(library.jar)->Ok
Tools->Validate Descriptors->ejbc Successful
10. Copy the weblogic.jar(c:\bea\weblogic81\lib\weblogic.jar) to the folder where Your EJB
module is located (In the Program it is c:\ss)
11. Copy the Jar file created by you (here it is library. jar) to
c:\bea\userprojects\mydomain\applications.
12. Start the server(Start->programs->Bea web logic Platform8.1->User Projects->mydomain>Start Server
13. If the server is started successfully without any exception then go to the next step.
14. Open Internet Explorer->Type the URL (http://localhost:7001/console) in the address
box.(Type the user name and password)
15. If the username and password is correct a page will be displayed.
16. In that page click->EJB 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
ss.jar
100
_appsdir_atm_jar
atm.jar
100
_appsdir_hello_jar hello.jar 100
17. Click the link of the jar file that You have created (Here it is ss.jar)
18. Click the testing tab.
19. Click the link Test this EJB.
The EJB library2 has been tested successfully with a JNDI name of library2
Continue
20. In the client part set the path as
C:\ss\set classpath=weblogic.jar;%classpath%;
21. Run the client
22. Terminate the Client and server.
Output:C:\ss>java libraryclient
Enter the Details
Enter the Account Number:
101
Enter The Book Title:
Java
Enter the Author:
Schildt
Enter the no.of copies
2
LIBRARY OPERATIONS
***************
1.ISSUE
2.RECEIVE
3.EXIT
ENTER UR OPTION:
1
Entering
BOOK ID IS:101
BOOK TITLE IS:Java
BOOK AUTHOR IS:Schildt
NO. OF COPIES :1
Sucess
LIBRARY OPERATIONS
***************
1.ISSUE
2.RECEIVE
3.EXIT
ENTER UR OPTION:
1
Entering
BOOK ID IS:101
BOOK TITLE IS:Java
BOOK AUTHOR IS:Schildt
NO. OF COPIES :0
Sucess
LIBRARY OPERATIONS
***************
1.ISSUE
2.RECEIVE
3.EXIT
ENTER UR OPTION:
1
Entering
Book is not available
LIBRARY OPERATIONS
***************
1.ISSUE
2.RECEIVE
3.EXIT
ENTER UR OPTION:
2
Entering
temp2
BOOK ID IS:101
BOOK TITLE IS:Java
BOOK AUTHOR IS:Schildt
NO. OF COPIES :1
Sucess
LIBRARY OPERATIONS
***************
1.ISSUE
2.RECEIVE
3.EXIT
ENTER UR OPTION:
2
Entering
temp2
BOOK ID IS:101
BOOK TITLE IS:Java
BOOK AUTHOR IS:Schildt
NO. OF COPIES :2
Sucess
LIBRARY OPERATIONS
***************
1.ISSUE
2.RECEIVE
3.EXIT
ENTER UR OPTION:
2
Entering
Invalid Transaction
LIBRARY OPERATIONS
***************
1.ISSUE
2.RECEIVE
3.EXIT
ENTER UR OPTION:
3
Result:
Thus the EJB for Library Operations was compiled and executed successfully.
VIVA
1. What is the role of system administrator in EJB Server?
System administrators are responsible for the day-to-day operations of the EJB
Server. Their responsibilities include keeping security information up-to-date and monitoring
the performance of the server
2. What is Entity Bean?
Entity beans are long-lived, they exist across client session, one shared by
multiple clients and remain alive even after a restart of the server or other failures. An
entity bean must implement the entity bean interface.
3. What is Session Bean?
Session beans are generally tied to the lifetime of a given client session. They are
relatively short-lived, state full session object are created in response to a single clients
request.
Ex.No:5
CREATE AN ACTIVEX CONTROL FOR FILE OPERATIONS
AIM: To Create an Activex Control for File Operations
Description:PART-I
1.
2.
3.
4.
5.
Start the process.
Open Visual Studio.net
File->New->Project->VisualBasic Projects->Windows Control Library
Rename the Project as actfileoperation and click ok
drag and drop the following control
i.
one Label box
ii.
one Rich Text Box
iii.
four Button
6. The following code must be included in their respective Button Click Event
Public Class FileControl
Inherits System.Windows.Forms.UserControl
Dim fname As String
//new
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.Text = ""
End Sub
//open
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim of As New OpenFileDialog
If of.ShowDialog = DialogResult.OK Then
fname = of.FileName
RichTextBox1.LoadFile(fname)
End If
End Sub
//save
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim sf As New SaveFileDialog
If sf.ShowDialog = DialogResult.OK Then
fname = sf.FileName
RichTextBox1.SaveFile(fname)
End If
End Sub
//font
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim fo As New FontDialog
If fo.ShowDialog = DialogResult.OK Then
RichTextBox1.Font = fo.Font
End If
End Sub
End Class
7. Build solution from the Built Menu
PART-II
1.
2.
3.
4.
5.
Open Visual Studio.net
File->New->Project->VisualBasic Projects->Windows Application
Rename the Project as actref and click ok
Tools->Add/Remove Tool Box Item and select the tab .NET Framework Components.
Click the Browse Button and open the actfileoperation.dll from (locate the bin folder) and
click ok.
6. Now the user control (FileControl) will be added to Tool Box.
7. Drag and Drop the Control in the Form
8. Execute the project by Hitting f5.
OUTPUT:
Result:
Thus the Activex Control for File Operations was compiled and executed successfully.
VIVA:
1. What is meant by Deployment?
Deployment is the process of installing an object in server side.
2. What is Activex control?
ActiveX control is a control using Microsoft ActiveX technologies. An ActiveX
control can be automatically downloaded and executed by a Web browser.
3. Specify some features of .NET
.NET is the framework for which we develop applications. It sits in between our
application programs and operating system. Applications developed for .NET run inside .NET
and are controlled by .NET. It supports both Windows and web applications.
Ex. No: 6 DEVELOP A COMPONENT FOR CURRENCY CONVERSION USING COM/.NET
AIM: To Create a component for currency conversion using com/.net
DESCRIPTION:
PART –1
CREATE A COMPONENT
1. Start the process
2. open VS .NET
3. File-> New-> Project-> visual Basic Project -> class library, rename the class Library if
required
4. 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
Return (res)
End Function
End Class
5. Build->Build the solution
Note: Register the dll using regsvr32 tool or copy the dll to c:\windows\system32.
Part –II
REFERENCING THE COMPONENT
1. Start the process
2. open VS .NET
1. File-> New-> Project-> visual Basic Project -> Windows Application, rename the Windows
Application if required
2. Project -> Add Reference choose the com tab->Browse the dollartorupees.dll and click ok
3. drag and drop the following controls in the form
i.
2 Label Boxes
ii.
1 Text box
iii.
4 Buttons
4. Include the coding in each of the Respective Button click Event.
Imports conversion2
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim obj As New convclass
Dim ret As Double
ret = obj.dtor(CDbl(TextBox1.Text))
MsgBox("The Equivalent Rupees for the given dollar" +
ret.ToString())
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim obj As New convclass
Dim ret As Double
ret = obj.etor(CDbl(TextBox1.Text))
MsgBox("The Equivalent Rupees for the
ret.ToString())
given euro" +
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim obj As New convclass
Dim ret As Double
ret = obj.rtod(CDbl(TextBox1.Text))
MsgBox("The Equivalent Dollar Amount for the given rupees" +
ret.ToString())
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim obj As New convclass
Dim ret As Double
ret = obj.etor(CDbl(TextBox1.Text))
MsgBox("The Equivalent Rupees for the
ret.ToString())
End Sub
End Class
5. Execute the project.
OUTPUT:
given euro" +
Result:
Thus the DNA sequences were read sorted and output was given to an output file.
VIVA
1. What is VB.NET?
VB.NET is the successor to VB 6.0, but language wise, it was modified
substantially as it became complete OOPL – no more "object-based language."
2. What Common Language Runtime(CLR)?
The Common Language Runtime (CLR) is the environment where all
programs in .NET are run. It provides various services, like memory management and
thread management.
Ex.No:7
DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING COM/.NET
AIM:
To develop a component for cryptography using com/.net
DESCRIPION:
PART –1
CREATE A COMPONENT
1. Start the process
2. open VS .NET
3. File-> New-> Project-> visual Basic Project -> class library, rename the class Library if
required
4. include 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 pa1.Length - 1
ct = Convert.ToInt64(Convert.ToChar(pa1.Substring(i, 1)))
ct = ct + ct
pa = pa + Convert.ToChar(ct)
Next
Return (pa)
End Function
Public Function deco(ByVal pa As String) As String
pa1 = pa
pa = ""
For i = 0 To pa1.Length - 1
ct = Convert.ToInt64(Convert.ToChar(pa1.Substring(i, 1)))
ct = ct / 2
pa = pa + Convert.ToChar(ct)
Next
Return (pa)
End Function
End Class
5. Build->Build the solution
Note: Register the dll using regsvr32 tool or copy the dll to c:\windows\system32.
Part –II
REFERENCING THE COMPONENT
1. Start the Process
2. open VS .NET
3. File ->New -> Project->Visual Basic Project->Windows Application, Rename the Windows
Application as Cryptography Reference if required
4. Project -> Add Reference choose the com tab->Browse the encode.dll and click ok
5. Drag and Drop the following controls in the form
a. 2 Label Boxes
b. 1 Text box
c. 3 Buttons
6. Include the coding in each of the Respective Button click Event.
Imports encode
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
TextBox1.Text = ""
End Sub
Private Sub ENCRYPT_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ENCRYPT.Click
Dim obj As New encode.Class1
Dim temp As String
temp = TextBox1.Text
TextBox1.Text = obj.enco(temp)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim obj As New encode.Class1
Dim temp1 As String
temp1 = TextBox1.Text
TextBox1.Text = obj.deco(temp1)
End Sub
End Class
7. Execute the project.
8. OUTPUT.
Result:
Thus the component for cryptography using com/.net was compiled and executed
successfully.
VIVA
1. What is encryption?
Encryption is the process of encoding messages (or information) in such a way that
eavesdroppers or hackers cannot read it, but that authorized parties can.
2. What is decryption?
An authorized party, however, is able to decode the cipher text using a decryption algorithm,
that usually requires a secret decryption key, that adversaries do not have access to.
3. What is Marshaling?
Marhsaling refers to the process of translating input parameters to a format that can be
transmitted across a network.
Ex.No:8 Develop a component to retrieve message box information using DCOM/.NET
AIM:
To Create a component to retrieve message box information using DCOM/.NET
Description:
Part – I
1.
2.
3.
4.
5.
Start the process.
Open Visual Studio. NET.
Goto File->New->Project->ClassLibrary|Empty Library->OK
Goto Solution Explorer->Right Click->Add->Add Component|Add New Item->COM Class-_OK
Add the following codings Save & Build.
Public Function test() As String
Dim str = "hai"
Return (str)
End Function
Public Function create() As String
MsgBox(test())
End Function
Part – II
1. Go To Start->Microsoft Visual.Net 2003->Visual Stufio.Net tools->Command prompt
Setting environment for using Microsoft Visual Studio .NET 2003 tools.
(If you have another version of Visual Studio or Visual C++ installed and wish
to use its tools from the command line, run vcvars32.bat for that version.)
C:\Documents and Settings\mcaadministrator>sn -k ms.snk
Microsoft (R) .NET Framework Strong Name Utility Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Key pair written to ms.snk
C:\Documents and Settings\mcaadministrator>
2. Copy ms.snk to bin directory (locate the class library)
3. start -> settings -> control panel->administrative tools->component services-> computer->my
computer->com + Application -> new -> application ->next -> create an empty application->
choose the server Application -> enter the new Application name (mssg) -> next ->choose the
interactive user-> next->finish.
4. expand mssg -> click the components ->right click -> new-> component ->
next->install new event classes-> select the class library1.tlb(class library->bin->
open->next->finish.
PART –III
1. Open Visual studio .net -> file-> new ->Project->Windows Application
2. Create one label box,one text box and one button in the form.
3. Include the following code in the Button click event
Imports msg
Public Class Form1
Inherits System.Windows.Forms.Form
Dim mo As New msg.ComClass1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
textbox1.text = mo.test()
End Sub
End Class
4.execute the project
OUTPUT:
Result:
Thus the component to retrieve message box information using DCOM/.NET was
compiled and executed successfully.
VIVA
1. What is DCOM?
Distributed Component Object Model (DCOM) is a proprietary Microsoft
technology for communication among software components distributed across networked
computers.
2.
What are the component of object model?
It is used to enable inter process communication and dynamic object creation in a
large range of programming languages.
Ex.No:9 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 required:
1.
2.
3.
4.
5.
6.
7.
Define the IDL interface
Implement the IDL interface using idlj compiler
Create a Client Program
Create a Server Program
Start orbd.
Start the Server.
Start the client
PROGRAM:
// Define IDL Interface
module simplestocks{
interface StockMarket
{
float get_price(in string symbol);
};
};
Note:
Save the above module as simplestocks.idl
Compile the saved module using the idlj compiler as follows .
C:\suji\corba>idlj simplestocks.idl
After compilation a sub directory called simplestocks same as module name will be created and it
generates the following files as listed below.
C:\suji\corba>cd simplestocks
C:\suji\corba\simplestocks>dir
Volume in drive C has no label.
Volume Serial Number is 348A-27B7
Directory of C:\suji\corba\simplestocks
02/06/2007 11:38 AM <DIR>
.
02/06/2007 11:38 AM <DIR>
..
02/06/2007 11:38 AM
2,071 StockMarketPOA.java
02/07/2007 02:15 PM
2,090 _StockMarketStub.java
02/07/2007 02:15 PM
865 StockMarketHolder.java
02/07/2007 02:15 PM
2,043 StockMarketHelper.java
02/07/2007 02:15 PM
359 StockMarket.java
02/07/2007 02:15 PM
339 StockMarketOperations.java
02/07/2007 02:08 PM
226 StockMarket.class
02/07/2007 02:08 PM
180 StockMarketOperations.class
02/07/2007 02:08 PM
2,818 StockMarketHelper.class
02/07/2007 02:08 PM
2,305 _StockMarketStub.class
02/06/2007 11:44 AM
2,223 StockMarketPOA.class
11 File(s)
15,519 bytes
2 Dir(s) 6,887,636,992 bytes free
C:\suji\corba\simplestocks>
// Implement the interface
import org.omg.CORBA.*;
import simplestocks.*;
public class StockMarketImpl extends StockMarketPOA
{
private ORB orb;
public void setORB(ORB v){orb=v;}
public float get_price(String symbol)
{
float price=0;
for(int i=0;i<symbol.length();i++)
{
price+=(int)symbol.charAt(i);}
price/=5;
return price;
}
public StockMarketImpl(){super();}
}
//Server Program
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA.*;
import java.util.Properties;
import simplestocks.*;
public class StockMarketServer
{
public static void main(String[] args)
{
try
{
ORB orb=ORB.init(args,null);
POA rootpoa=POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
StockMarketImpl ss=new StockMarketImpl();
ss.setORB(orb);
org.omg.CORBA.Object ref=rootpoa.servant_to_reference(ss);
StockMarket hrf=StockMarketHelper.narrow(ref);
org.omg.CORBA.Object orf=orb.resolve_initial_references("NameService");
NamingContextExt ncrf=NamingContextExtHelper.narrow(orf);
NameComponent path[]=ncrf.to_name("StockMarket");
ncrf.rebind(path,hrf);
System.out.println("StockMarket server is ready");
//Thread.currentThread().join();
orb.run();
}
catch(Exception e){
e.printStackTrace();
}
}
}
// Client Program
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import simplestocks.*;
import org.omg.CosNaming.NamingContextPackage.*;
public class StockMarketClient
{
public static void main(String[] args)
{
try
{
ORB orb=ORB.init(args,null);
NamingContextExt
ncRef=NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
//NameComponent path[]={new NameComponent("NASDAQ","")};
StockMarket market=StockMarketHelper.narrow(ncRef.resolve_str("StockMarket"));
System.out.println("Price of My company is"+market.get_price("My_COMPANY"));
}
catch(Exception e){
e.printStackTrace();
}
}
}
OUTPUT:
Compile the above files as
C:\suji\corba>javac *.java
C:\suji\corba>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost
C:\suji\corba>start java StockMarketServer -ORBInitialPort 1050 -ORBInitialHost
localhost
C:\suji\corba>
StockMarket server is ready
C:\suji\corba>java StockMarketClient -ORBInitialPort 1050 -ORBInitialHost localh
ost
Price of My company is165.6
C:\suji\corba>
Result:
Thus the retrieving stock market exchange information using CORBA was compiled and
executed successfully.
VIVA
1. Define CORBA.
The Common Object Request Broker Architecture (CORBA) from the Object
Management Group (OMG) provides a platform-independent, language-independent
architecture for writing distributed, object-oriented applications.
2. What is meant by ORB?
A fundamental part of the Common Object Request Broker architecture is the
Object Request Broker (ORB).
3. What is IDL and why is it useful?
The Interface Definition Language (IDL) is a standard language used to define the
interfaces used by CORBA objects. The IDL specification is responsible for ensuring that
data is properly exchanged between dissimilar languages.
4. What does IIOP stand for and what is its significance?
The Internet Inter-ORB Protocol (IIOP) is a specialization of the GIOP. IIOP is
the standard protocol for communication between ORBs on TCP/IP based networks.
Ex.No:10 Develop a middleware component for retrieving weather forecast information using CORBA
AIM: To Create a Component for retrieving weather forecast information using CORBA
Description:
Steps required:
1.
2.
3.
4.
5.
6.
7.
Define the IDL interface
Implement the IDL interface using idlj compiler
Create a Client Program
Create a Server Program
Start orbd.
Start the Server.
Start the client
PROGRAM:
// Define IDL Interface
module weather{
interface forecast
{
float get_min();
float get_max();
};
};
Note:
Save the above module as weather.idl
Compile the saved module using the idlj compiler as follows .
C:\suji\weather>idlj weather.idl
After compilation a sub directory called weather same as module name will be created and it
generates the following files as listed below.
C:\suji\weather>cd weather
C:\suji\weather\weather>dir
Volume in drive C has no label.
Volume Serial Number is 348A-27B7
Directory of C:\suji\weather\weather
03/14/2007 02:52 PM <DIR>
.
03/14/2007 02:52 PM <DIR>
..
03/14/2007 02:55 PM
2,240 forecastPOA.java
03/14/2007 02:55 PM
2,729 _forecastStub.java
03/14/2007 02:55 PM
796 forecastHolder.java
03/14/2007 02:55 PM
1,926 forecastHelper.java
03/14/2007 02:55 PM
330 forecast.java
03/14/2007 02:55 PM
319 forecastOperations.java
03/15/2007 10:42 AM
2,144 forecastPOA.class
03/15/2007 10:42 AM
167 forecastOperations.class
03/15/2007 10:42 AM
207 forecast.class
03/15/2007 10:42 AM
2,724 forecastHelper.class
03/15/2007 10:42 AM
2,403 _forecastStub.class
11 File(s)
15,985 bytes
2 Dir(s) 1,726,103,552 bytes free
C:\suji\weather\weather>
// Implement the interface
import org.omg.CORBA.*;
import weather.*;
import java.util.*;
public class weatherimpl extends forecastPOA
{
private ORB orb;
int r[]=new int[10];
float s[]=new float[10];
Random rr=new Random();
public void setORB(ORB v){orb=v;}
public float get_min()
{
for(int i=0;i<10;i++)
{
r[i]=Math.abs(rr.nextInt());
s[i]=Math.round((float)r[i]*0.00000001);
}
float min;
min=s[0];
for(int i=1;i<10;i++)
{
if (min>s[i])
min =s[i];
}
float mintemp=Math.abs((float)(min-32)*5/9);
return mintemp;
}
public float get_max()
{
for(int i=0;i<10;i++)
{
r[i]=Math.abs(rr.nextInt());
s[i]=Math.round((float)r[i]*0.00000001);
}
float max;
max=s[0];
for(int i=1;i<10;i++)
{
if (max<s[i])
max =s[i];
}
float maxtemp=Math.abs((float)(max-32)*5/9);
return maxtemp;
}
public weatherimpl(){super();}
}
//Server Program
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA.*;
import java.util.Properties;
import weather.*;
public class weatherserver
{
public static void main(String[] args)
{
try
{
ORB orb=ORB.init(args,null);
POA rootpoa=POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
weatherimpl ss=new weatherimpl();
ss.setORB(orb);
org.omg.CORBA.Object ref=rootpoa.servant_to_reference(ss);
forecast hrf=forecastHelper.narrow(ref);
org.omg.CORBA.Object orf=orb.resolve_initial_references("NameService");
NamingContextExt ncrf=NamingContextExtHelper.narrow(orf);
NameComponent path[]=ncrf.to_name("forecast");
ncrf.rebind(path,hrf);
System.out.println("weather server is ready");
orb.run();
}
catch(Exception e){
e.printStackTrace();
}
}
}
// Client Program
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import weather.*;
import org.omg.CosNaming.NamingContextPackage.*;
import java.util.*;
public class weatherclient
{
public static void main(String[] args)
{
String city[]={"Chennai ","Trichy ","Madurai ","Coimbatore","Salem
Calendar cc=Calendar.getInstance();
try
{
ORB orb=ORB.init(args,null);
"};
NamingContextExt
ncRef=NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
forecast fr=forecastHelper.narrow(ncRef.resolve_str("forecast"));
System.out.println("\t\t\tW E A T H E R F O R E C A S T");
System.out.println("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println();
System.out.println("\tDATE TIME CITY
System.out.println("\t
HIGHEST
TEMPERATURE
LOWEST ");
TEMPERATURE");
for(int i=0;i<5;i++)
{
System.out.print("\t"+cc.get(Calendar.DATE)+cc.get(Calendar.MONTH)+cc.get(Calendar.YEAR)+"
"+cc.get(Calendar.HOUR)+" "+city[i]+"
"+" ");
System.out.print(Math.floor(fr.get_min())+"\t \t"+Math.ceil(fr.get_max()));
System.out.println();
}
}
catch(Exception e){
e.printStackTrace();
}
}
}
OUTPUT:
Compile the above files as
C:\suji\weather>javac *.java
C:\suji\weather>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost
C:\suji\corba>start java weatherserver -ORBInitialPort 1050 -ORBInitialHost
localhost
C:\suji\weather>
weather server is ready
C:\suji\corba>java weatherclient -ORBInitialPort 1050 -ORBInitialHost localh
ost
C:\suji\weather>java weatherclient -ORBInitialPort 1050 -ORBInitialHost localhost
WEATHERFORECAST
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DATE
TIME
CITY
HIGHEST
TEMPERATURE
LOWEST
TEMPERATURE
16/2/2007 11:36 Chennai
16.0
16/2/2007 11:36 Trichy
17.0
8.0
16/2/2007 11:36 Madurai
15.0
8.0
16/2/2007 11:36 Coimbatore
16.0
9.0
16/2/2007 11:36 Salem
16.0
7.0
C:\suji\weather>
8.0
Result:
Thus a Component for retrieving weather forecast information using CORBA was compiled
and executed successfully.
.
VIVA
1. What is an Object reference?
When an object is passed by reference, the object itself remains "in place" while
an object reference for that object is passed.
2. Define Language Mapping.
A language mapping is a specification that maps IDL language constructs to the
constructs of a particular programming language.
3. What is Partitioning ?
The grouping together of similar interfaces, constant values, and the like is
commonly referred to as partitioning and is a typical step in the system design process
(particularly in more complex systems).
4. What is Client Stub?
A client stub, which is generated by the IDL compiler, is a small piece of code
that makes a particular CORBA server interface available to a client.
5. What is Server Skeleton?
A server skeleton, also generated by the IDL compiler, is a piece of code that
provides the "framework" on which the server implementation code for a particular
interface is built.