1 Lecture 13 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
1 Lecture 12 George Koutsogiannakis/ Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Remote Method Invocation
J.Sant Servlets Joseph Sant Sheridan Institute of Technology.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
DISTRIBUTED FILE SYSTEM USING RMI
An introduction to Java Servlet Programming
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
M.Sc. Course, Dept. of Informatics and Telecommunications, University of Athens S.Hadjiefthymiades “Web Application Servers” Basics on WAS WAS are necessary.
Chapter 4 Servlets Concept of Servlets (What, Why, and How) Servlet API Third-party tools to run servlets Examples of Using Servlets HTML tag with GET.
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
Web Services CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Java Servlets and JSP.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Introducing JavaBeans Identify the features of a JavaBean Create and add a bean to an application Manipulate bean properties using accessor and mutator.
JSP and Servlets Lecture notes by Theodoros Anagnostopoulos.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
1 Lecture 15 George Koutsogiannakis SUMMER 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Understanding the CORBA Model. What is CORBA?  The Common Object Request Broker Architecture (CORBA) allows distributed applications to interoperate.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES LECTURE 5_1 George Koutsogiannakis/ Summer
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
Objectives Java Servlet Web Components
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
Java Servlets & Java Server Pages Lecture July 2013.
RMI-IIOP.  RMI-IIOP combines RMI-style ease of use with CORBA cross-language interoperability  Java™ Remote Method Invocation (RMI) provides a simple.
1 Lecture 11 George Koutsogiannakis / Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
Java Programming: Advanced Topics 1 Networking Programming Chapter 11.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
Java Servlets and Java Server Pages Norman White Stern School of Business.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
Java Servlets and Java Server Pages
Remote Method Invocation A Client Server Approach.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
1 Lecture 8 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Spell Checker web service (you build a web client that interacts with the service) The client uses a servlet class and a JSP page. The user passes information.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Introduction to Servlets
Java Servlets By: Tejashri Udavant..
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Remote Method Invocation
What is RMI? Remote Method Invocation
Java Servlets and JSP.
Java Remote Method Invocation
Presentation transcript:

1 Lecture 13 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES

Topics Performance comparison between RMI and RMI over IIOP. Example of Applet and Servlet Communications. Example of applet/servlet/RMI over IIOP server communications. Java Beans in Standard Edition jdk. Using Net Beans 2

RMI and RMI over IIOP Performance In general RMI over IIOP is slower than RMI because of : –The IDL conversions needed. –The additional layers in the architecture of RMI over IIOP. It is, however, depended on the amount of data transferred during each invocation, and the type of data being transferred. –IIOP packets can carry more data than RMI packets (approximately 80% more). –The set up for the packets is, however, greater for IIOP than it is for RMI (because of the additional layers). 3

RMI and RMI over IIOP Performance –There is a point where for large amounts of data transfers IIOP can become more efficient than RMI but it also depends on the number of invocations that need to be made. –Because of the Distributed Garbage Collector RMI invocations can take a longer time than RMI over IIOP invocations. –Therefore for large amounts of data to be transferred over a small number of invocations,RMI over IIOP may be more effective. 4

RMI and RMI over IIOP Performance 5 Size of data increases Time increases RMI over IIOP RMI This graph applies for a specific data type of data

Example of Applet and Servlet Communications The following example illustrates how an applet (client side execution) can communicate with a servlet (server side execution). –The example web application is called LoginAppletNORMI and it is posted on the examples page of the course ‘s web site. Architecture: 6 Web Server Web App: LoginAppletNORMI LoginApplet.html LoginApplet.jar WEB-INF web.xml classes TestLoginServlet.class

Example of Applet and Servlet Communications Develop web application outside Tomcat in some folder with the name of the web application: –i.e. folder name: LoginAppletNORMI jar the applet.class files and place them in the web application folder. Make sure that you have the directory structure required for a web application: –i.e WEB-INF folder with the web.xml inside and another folder name d: classes. –Place the servlet class in the classes folder. –You can also create a folder named lib and place a copy of the jar file there. 7

Example of Applet and Servlet Communications Create a war file: –Open a DOS window with the path inside the web application folder. Type the command: >C:\web application folder> jar LoginAppletNORMI.war. –Notice that the name of the war file war file is the same as the name of the web application folder. Go to: and log in as an administrator. –At the bottom of the page browse to where the war file is located and then press deploy. –You web application is now deployed in Tomcat. 8

Example of Applet and Servlet Communications You can now test it by: –Opening a Browser instance and typing: Applet.html. 9

Example of Applet and Servlet Communications LoginApplet.html file: Untitled I am calling Applet 10

Example of Applet and Servlet Communications 11 LoginApplet.java code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.net.*; import java.io.*; public class LoginApplet extends JApplet { Container c; JTextField ltf=new JTextField();; String login; JButton exitbutton, submitbutton;

Example of Applet and Servlet Communications 12 public void init() { c=getContentPane(); ltf.setEditable(true); BorderLayout bl=new BorderLayout(); setLayout(bl); c.add(ltf, BorderLayout.NORTH); exitbutton=new JButton("Exit"); MyPanel mp=new MyPanel(); c.add(exitbutton, BorderLayout.SOUTH); c.add(mp, BorderLayout.CENTER); Handler h=new Handler(); ltf.addActionListener(h); submitbutton.addActionListener(h); exitbutton.addActionListener(h); }

Example of Applet and Servlet Communications class MyPanel extends JPanel { public MyPanel() { submitbutton=new JButton("Submit"); add(submitbutton); } 13

Example of Applet and Servlet Communications 14 class Handler implements ActionListener { public void actionPerformed(ActionEvent e){ if(e.getSource()==exitbutton){ System.exit(0); } else if(e.getSource()==submitbutton){ System.out.println("Inside handler for submit button"); try{ login=ltf.getText(); URL url=new URL(" /TestLoginServlet?loginname="+login); URLConnection uc=url.openConnection(); uc.setDoOutput(true); uc.setDoInput(true); ltf.setText("I sent info to servlet"); InputStreamReader instream=new InputStreamReader(uc.getInputStream()); BufferedReader in=new BufferedReader(instream); ltf.setText("I am reading input stream now");

Example of Applet and Servlet Communications 15 String line; while((line=in.readLine())!=null) { ltf.setText(line); } in.close(); System.out.println("I finished try block. Name="+" "+login); } catch(MalformedURLException exception){ltf.setText("Malformed exc."); } catch(IOException exception){ltf.setText("IO exc."+exception.getMessage());} System.out.println("I finished actionPerformed"); }

Example of Applet and Servlet Communications 16 TestLoginServlet.java code: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class TestLoginServlet extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String login=req.getParameter("loginname"); res.setContentType("text/html"); PrintWriter out=res.getWriter(); if(login.equals("george")) out.println("The servlet verifies that your name is:"+login); else out.println("Wrong login name. Please try again"); out.close(); }

Example: ServletLoginApplet web application This example simulates the communications between an applet and a servlet which acts as a client for an RMI over IIOP server. The applet sends a request to the servlet. The servlet in turn is a client to an RMI server. It sends a request to the RMI server. The RMI server returns a response to the servlet which in turn sends a response to the applet. 17

Example: ServletLoginApplet web application This application requires that: –Deployment in Tomcat of the web application part A signed jar file for the applet. A html file that calls the signed applet via the archive attribute of the applet tag. A servlet under the WEB-INF/classes path. The class ReverseInterface.class under the WEB-INF/classes path. –This is the interface file from the RMI over IIOP server 18

Example: ServletLoginApplet web application The stub file from the RMI over IIOP server called: _ReverseInterface_stub.class under the path WEB-INF/classes A web.xml file under the WEB-INF folder. –Deploy using a war file as in previous example. –The RMI over IIOP server classes (interface, implementation class tie class etc.) should reside in a path outside of Tomcat. 19

Example: ServletLoginApplet web application To test the web application certain tasks have to be done in the proper sequence: –From the folder where the RMI over IIOP server is located start an instance of the naming service (registry): C:\ >tnameserv –ORBInitialPort –Next start the RMI over IIOP server: C:\>……>java Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:900 ReverseInterfaceImpl 20

Example: ServletLoginApplet web application –Next, start an instance of the Browser and type: 21

Example: ServletLoginApplet web application 22 Applet streams (POST HTTP request) URL url=new URL(" qr="qr="+URLEncoder.encode(query); textarea.append("\n"+"The applet displays"+qr+"\n"); URLConnection uc=url.openConnection(); uc.setDoOutput(true); uc.setDoInput(true); uc.setUseCaches(false); ByteArrayOutputStream bytestream=new ByteArrayOutputStream(512); PrintWriter out=new PrintWriter(bytestream,true); out.print(qr); out.flush(); //POST requests are required to have Content Length String lengthString=String.valueOf(bytestream.size()); uc.setRequestProperty("Content-Length", lengthString); uc.setRequestProperty("Content-type", "application/x-www-form-urlencoded"); bytestream.writeTo(uc.getOutputStream()); out.flush(); out.close();

Example ServletLoginApplet web application 23 InputStreamReader in=new InputStreamReader(uc.getInputStream()); int chr=in.read(); while(chr!=-1) { textarea.append(String.valueOf((char)chr)); chr=in.read(); } in.close(); System.out.println("I finished try. Name="+" "+query); } catch(MalformedURLException exception){textarea.setText(e.toString()); } catch(IOException exception){textarea.setText(e.toString());} System.out.println("I finished actionPerformed"); }

Example: ServletLoginApplet web application 24 Servelt code: import javax.naming.*; import java.util.*; public class IIOPTestLoginServlet extends HttpServlet { protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String qr=req.getParameter("qr"); String loginmod="The name is:"+" "+qr+" "+"Therefore the servlet works with doPost"; res.setContentType("text/html"); PrintWriter out=res.getWriter(); out.println(loginmod); out.println("The servlet captured the value of qr="+qr);

Example: ServletLoginApplet web application 25 ReverseInterface r; Hashtable env=new Hashtable(); env.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory"); env.put("java.naming.provider.url", "iiop://localhost:900"); try{ out.println("TRYING TO CONTACT REGISTRY"); Context initialNamingContext=new InitialContext(env); out.println("obtained InitialContext"); r=(ReverseInterface)PortableRemoteObject.narrow( initialNamingContext.lookup("Reverse"), ReverseInterface.class); out.println("The registry lookup was successful"); out.println("the opposite of "+qr+"is"+r.reverseString(qr)); } catch (Exception e) { out.println("Error executing remote method or lookup 1:30 p.m."); out.println(e.toString());} out.close(); }

Example ServletLoginApplet web application 26 RMI over IIOP server import java.rmi.Remote; import java.rmi.RemoteException; public interface ReverseInterface extends Remote { String reverseString(String originalstring) throws RemoteException; }

Example ServletLoginApplet web application 27 import java.rmi.*; import java.rmi.server.*; //add the lines below import javax.rmi.PortableRemoteObject; import javax.naming.*; import java.net.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class ReverseInterfaceImpl extends PortableRemoteObject implements ReverseInterface { public ReverseInterfaceImpl() throws RemoteException { super(); }

Example ServletLoginApplet web application 28 public String reverseString(String originalstring) throws RemoteException { int length=originalstring.length(); StringBuffer temp=new StringBuffer(length); for (int i=length; i>0; i-- ) { temp.append(originalstring.substring(i-1,i)); } return temp.toString(); }

Example ServletLoginApplet web application 29 public static void main(String[] args){ try{ ReverseInterfaceImpl r= new ReverseInterfaceImpl(); Context initialNamingContext=new InitialContext(); System.out.println("Binding server to registry.."); initialNamingContext.rebind("Reverse",r); System.out.println("Object was registered"); } catch(Exception e) { System.out.println("Error while binding object 11:00am"); System.out.println(e.toString()); } System.out.println("The RMI server is up and Running!"); }

Example ServletLoginApplet web application 30 Command to start RMI over IIOP server: C:\.....>java -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:900 ReverseInterfaceImpl Command to compile server with rmic compiler: C:\......>rmic -iiop ReverseInterfaceImpl Notice that the rmic command should be done after the server file has been compiled with the normal javac compiler.

Java Beans The Java Beans architecture is based on the component model. –Components are self sustained reusable software modules. The idea behind Java Beans is that we can introduce customization of the component during run time (dynamically). Java Beans Architecture promotes reusability but it is different than inheritance. Inheritance is introduced at compilation time. Any changes result to recompilation. –Java Beans, however, have their properties changed by another class dynamically during run time. –A java Bean can be used by another Java Bean thus resulting in a new Java Bean which is the combination of the two. Java Beans expose their properties to other Beans. 31

Java Beans Internal workings of the Java Bean are hidden from the user. All the user needs to know is what functionality the Bean offers and what interface it provides. –The user can access and set properties of the Bean as needed during run time. In Java Standard Edition Beans are supported via the packages: –java.beans –java.beans.beancontext Other languages have similar concept to Beans such as Delphi and Visual Basic. 32

Java Beans 33 Bean A Bean B Bean C Bean C combines the functionality of Bean A and Bean B

Java Beans To write a Java Bean we need: –Rules that ensure consistency in writing interfaces: i.e accessor method names begin with get, mutator methods begin with set. Bean properties must use get /set followed by the property’s name i.e. String LastName; public String getLastName(); Properties of a Bean can be: –Simple: String LastName ( contains a single value). –Indexed: to keep track of the values of a group of properties. –Bound: alert other objects when its value changes. –Constrained: notifies other objects of impending changes –Read/Write, read-only, write-only 34

Java Beans –An event handling model. –Persistence. Retaining information about the state of an object. –Introspection: Discover how to access other Java Bean components. –We need support from a Builder IDE. The IDE will allow connection of Java Beans to produce the final application. Such an IDE can be NetBeans. 35

Java Beans Introspector class –java.beans.Introspector provides a standard way for building tools to learn about the properties, events and methods supported by a target java bean. –The introspector will analyze the bean’s class and superclass looking for its accessor and mutator methods, event methods and so on. –Introspection will also look for explicit information that can be provided about a Bean via a BeanInfo class provided by the developer of the Bean. 36

Java Beans 37

Java Beans For example, the builder tool in the previous slide shows a calculator component that is built from: – 16 button components, –a text field component, –and a panel upon which the buttons and a text display are placed. –In addition, you can see five invisible components. These specific components hold values or strings used by the calculator for intermediate calculations, operation codes, and display strings, as well a boolean flag to determine when evaluation of a new expression is started. The calculator shown becomes itself a component that can be integrated in another application 38

Java Beans More information about Java Beans is provided in the Java Beans Specification available at: html 39

Java Beans To create a simple Bean and import it in a tool like Net Beans : –Create the Java Bean program. Notice that all Java Bean classes must be serializable. –Create a Manifest File –Jar the files –Import into the tool Note: A Java Bean can also be created outside the builder tool by having the developer write the code for it. 40

Creating A Java Bean programmatically Java Beans are normally stored and distributed in jar files. –The jar file must contain a manifest file which describes the contents of the jar file. Contents are defined under specific headers in the manifest file. The manifest file is read by the IDE (Builder) tool when we load the Bean on the IDE. To create the manifest file we can use a text editor i.e Main-Class: folder1.folder2.MyBean Name: folder1.folder2.MyBean.class Java-Bean: True The file needs to be saved as manifest.tmp. >jar cmf manifest.tmp MyBean.jar MyBean.class The jar utility uses the file manifest.tmp to create the file MANIFEST.MF and place it in a directory called META-INF inside the jar. Note: The jar file can also become an executable. In other words we can execute the program just by double clicking on the icon of the jar file (at least in Windows platforms). 41

Creating A Java Bean programmatically To confirm the file is in the jar use the command: >jar tvf MyBean.jar The jar file can also be executed via the command: > java –jar MyBean.jar 42

Development Environments There are Development Environments for learning purposes. –A tool like that was the BDK-Bean Development Kit (not available any more) offered by SUN –Another tool like that offered is the BeanBuilder available at: Neither of these tools is suitable for a production environment 43

Net Beans IDE An IDE that allows the creation of GUIs via drop and drag actions. The creation of Enterprise Java Beans. A small example of how the Net Beans IDE can be used to create a GUI is described in file: netbeansGUI.doc posted in the examples page of the course’ s web site. 44

Net Beans IDE Install NetBeans 6.5 or higher from the netbeans.org site. Use the choice that includes all. Before installation make sure: –That you have installed Java SDK with EE. 45

Net Beans IDE During installation of NetBeans: –Make sure that you choose the customization choice: Add Tomcat as part of the installation –Make sure that you choose the SDK/jdk path as the jdk to be used by NetBeans. Check PATH variable to make sure that is shown as SDK/bin 46

Net Beans IDE Make sure that you record all port numbers and passwords. –The Tomcat passwords need to be recorded. If for some reason you forget you can recover the Tomcat passwords from file: C:\Users\YourUserNamefor your system\.netBeans\6.5\apatche-tomcat _base\conf\tomcat-users.xml 47

Net Beans IDE After NetBeans installation is completed: –Go to services and right click to add the GlassFish 2 server as a server (or GlassFish 3). –You will be asked to create a Domain for your applications. Choose “Create Personal Domain”. 48

Net Beans IDE Create a Folder C:\GlassFishDomains in windows explorer first. In the NetBeans window type: C:\GlassFishDomains\Domains The system will create the folder Domains and place the required files in it. You will be asked to create a password to access the administrative console of GlassFish. 49

Net Beans IDE Make a note of the system paths to the various installations. Make a note of port numbers –i.e due to conflicts with exiting usages of port numbers Tomcat make work in port 8084 now. If you deploy a web application using GlassFish, then you do not need to deploy it in Tomcat also. 50

Net Beans IDE Notice that under services Tomcat and GlassFish appear as separate services. –i.e. You can deploy a web service that does not have beans in it in Tomcat and not bother with GlassFish. –You will deploy on Tomcat using the manager page of Tomcat and a war file. 51

Study Guide Study slides. Suggest that you experiment with Bean Builder tool. Download and start experimenting with Net Beans 52