SERVLET by wuyunyi


									Internet Protocols I

      Incheon Paik
Some Protocols
   HTTP Communication
                   (1) TCP Connection Request

                   (2) HTTP Request
                   (3) HTTP Response

                   (4) TCP Connection Close

     ConnectionlessCommunication
     Stateless Communication

Some Protocols
   HTTP Message
     StartLine : Client Request Information / Response
      Status Information
     Message Header : Additional Information for HTTP
      Message such as Date, Program Name, Version,
      Cookie, User Authentication, Cache
     Message Body : Contents for Request or Response.
      In case of POST, Input data consists of data stream
      encoded in request message.

Some Protocols
   Client Request Message in HTTP
     Request: HTTP Command, URI, and HTTP Version, Header
      Name:Header Value, Request Message Body

   Server Response Message in HTTP
     Response  Message : HTTP Version, Status Code, Code
      Description, Response Header, Response Message Body
     Response Status Code : (Reference 100-199), (Success 200-
      299), (Redirection 300-399), (Incomplete 400-499), (Server
      Error 500-599)

Some Protocols
   HTTP Message Header
     HTTP   Header : Used for transmitting any kinds of information
      between client and server, [Header Name : Blank Header-
     General Header : Client Request, Server Response, Cache
      setup, Connection, Date, etc
     Client Request Header : Client information and preferred data
      type, Accept Character set, encoding type, and authorization
     Response Header : Server Information, Message processing
      methods for response message. Web server information,
      Cookie setup, authenticate information.
     Entity Header : HTTP message body information, encoding
      method of message, contents length, MD5 information,
      encoding method of contents transmission, MIME type
Some Protocols
   MIME Type
     As HTTP transmission deal with multimedia
      documents, pre-defined method to deal with that
      data by client should be described.
     MIME(Multipurpose Internet Mail Extension) Type
       Client: Using Accept Header, Clients can define their
        preferred media type
       Server : Describe MIME Type in Content-Type Header

     MIME  Type form : Type/Subtype (ex: application/x-
     Standard MIME Type :
       Text,    Multipart, Message, Application, Image, Audio, Video
CGI Communication
   CGI(Common Gateway Interface)
   Transmit Messages by GET/POST Method
   Characteristics
   Extend Web Server, Dynamic Response, Only Install in Server
   Overhead, Security, Interactive pages, Cannot keep the
    connection : Problems

                                                 Process 1

                                                 Process 1

                                                 Process 1

            Web Server       CGI Program         Processes
Extended CGI
   ASP (Active Server Page) of Microsoft
       Combine HTML, Server side Script, and Server side Component
       Written in Jscript, VBScript, and run on IIS Server
       Can use COM Component

   Java Servlet and JSP
       Platform Independent, Safe and Effective Thread Service, Object
        Oriented Paradigm
       Easy to interoperate with Legacy Application
       JSP is similar to ASP, and provide HTML script language and JavaBeans
   Object Web
       CORBA (Common Object Request Broker Architecture)
       EJB (Enterprise JavaBeans)
       DCOM (Distributed Common Object Model)
Motivations of Servlet and JSP
Slide 9-18, Used the Material by Philippe Rochat
   Faster than CGI (no process creation overhead)
   Java is Internet oriented
   Servlet API:
     Security
     Session    support
   Code reuse and portability
   JDBC support
   Next step: Enterprise Java Beans (EJB)

 Object Web

HTML/                         JSP                 EJB
           HTTP                                           DBMS

                Web Server
                             Servlet              CORBA


Servlet and Servlet Container
          Servlet Application 1      Servlet Application 2   Servlet Application N

                                  Java Servlet API

       Servlet Container 1           Servlet Container 2         Servlet Container N

 Servlet Container:
 - To run servlet, there need to be JVM to run Java servlet class and
   servlet container to provide servlet applications with system service.
 - Deliver HTTP request of a client to servlet application,
   and HTTP response of the servlet applcation to the client
How-to Write Servlet
   Very Similar to applet
     Must   inherits
        HttpServlet

     Must   implements one of
        doGet

        doPost

        doPut


     Receives
        HttpServletRequest

        HttpServletResponse

 Execution of JSP
             JSP Request             Request
Web                     Web                     Servlet                       Handler
Browser                 Server                  Container                     Servlet
                                   JSP File                                                      Servlet
                                    Check                                                      Invocation

                                                          Java file                   Class
                                  JSP file                Compile
                                  Compile                                            Loading
                                                                      Class File                     JSP
                  JSP File                    Java File                                             Servlet
                  (.jsp)                      (.java)                 (.class)

    A user requests .jsp file through URL.
    Web server requests JSP handler to process .jsp file
    JSP/Servlet container pass the corresponding .jsp file to JSP handler servlet
    JSP Handler Servlet
        • Check JSP file, execute the existing .class servlet when no change
        • When there was change, generate .java source code from .jsp
        • Compile the java source
        • when .class file was generated normally, execute the servlet.
Servlet and JSP Examples
   Refer to Apache Tomcat
   When you install Apache Tomcat,

   Introduction to
Java Remote Method
  Invocation (RMI)
    Distributed Objects
 Objects that can communicate with objects on heterogeneous run-
time environments
 Distribute Objects Standard Protocol – ex: JRMP
 Robust
 Reliable
 Transparent
 Distributed Objects Technology
   Multi-Platform
   Transparent access to distributed objects
   Language Neutral: RMI, CORBA, DCOM
Java Remote Method Invocation (RMI)

 Can use objects on remote different run-time
environments as like objects on a local run-time
 Abstraction of low-level network code on
distributed network to provide developers an
environment where they focus on their application
  Introduction to RMI

Distributed Processing on Network
Define of Remote Interface
Object Serialization
java.rmi and java.rmi.server
Create Stub and Skeleton
Communication of Remote Object and

           JVM                                    JVM
  Client                    Stub   Skeleto                    Object


   RMI Client Application                RMI Server Application

Writing Java RMI Application
 Writing RMI Application
   Definition of Remote Interface
    Definition of Remote Implementation Class
    Write RMI Server Application
    Write Client Application
 Compile and Run the Application
   Compilation of the Implementation Class
      Creation of Stub and Skeleton using “rmic” command
      Compilation of the Server Application
      Run the RMI Registry and Start the Server Program
      Compilation of the Client Program
      Run the Client
Hello Example : RMI


import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
  String sayHello() throws
    Hello Example : RMI
                                                                                       “HelloImpl” object
Implementation (Server)
                                                      try {
                                                                        HelloImpl obj = new HelloImpl();
import   java.rmi.Naming;                                               // Bind this object instance to the name
import   java.rmi.RemoteException;                    "HelloServer"
import   java.rmi.RMISecurityManager;                                   Naming.rebind("HelloServer", obj);
import   java.rmi.server.UnicastRemoteObject;                           System.out.println("HelloServer bound in
public class HelloImpl extends UnicastRemoteObject          } catch (Exception e) {
  implements Hello {                                                   System.out.println("HelloImpl err: " +
  public HelloImpl() throws RemoteException {                          e.printStackTrace();
    super();                                                }
  }                                                      }
  public String sayHello() {
    return "Hello World!";
  public static void main(String args[]) {           Compile & Skeleton Creation :
    // Create and install a security manager         % javac
    if (System.getSecurityManager() == null) {
               System.setSecurityManager(new         % javac
RMISecurityManager());                               % rmic HelloImpl
          Hello Example : RMI
A Client Application
import java.rmi.Naming;
import java.rmi.RemoteException;

public class HelloClient {

 public static void main(String args[]) {
  String message = "Hello: This is my test message";

  // "obj" is the identifier that we'll use to refer
  // to the remote object that implements the "Hello"
  // interface
  Hello obj = null;

  try {
                 obj = (Hello)Naming.lookup("//" + "/HelloServer");
                 message = obj.sayHello();
              } catch (Exception e) {
                 System.out.println("HelloClient exception: " + e.getMessage());
   System.out.println("Message = " + message);
 } // end of main
} // end of HelloClient
        Hello Example : RMI
   File “policy”

   grant {
                   // Allow everything for now

  Start Registry Server & Run Server and Client
   % rmiregistry &
   % java – HelloImpl            Run the RMI Server
   % javac examples/hello/
   % java [–] HelloClient          Compile the Client

Please ensure there is the “policy” file in                     Run the Client
the current directory
RMI Structure
 Protocol
   Java Remote Method Protocol (JRMP)
      • For distribute object environment by pure Java environment
    RMI/IIOP: Can communicate with CORBA

    Communication Mechanism between Stub and Skeleton
    Object Serialization: Types of parameters and return type of a
   remote method should follow Java serialization mechanism
Stub and Skeleton

             JVM                                                                     JVM
             Remote Method                                                      Remote Method
             Invocation                                                         Invocation
   Client                           Stub               Skeleton                                 Object
             Data Transformation                                                Remote Method

     RMI Client Application                                               RMI Server Application



Stub and Skeleton
  Stubs and Skeleton
     When RMI client invokes a remote method of a remote object, it
    uses stub reference of the remote object instead of remote object
     For marshalling and unmarshalling of stub and skeleton, object
    serialization and deserialization are used.
     Condition of Object for Object Serialization
       • Object should interface
       • Built-in types can be serialized basically
       • Member variables should implement the Serializable
       interface or be declared as transient
       • Static member variables can not be serialized.
             JRMP Class

                         (Object Serialization)


                               connection             Creation of
                                                  reference to remote
Managing connection to
   remote object
    Introduction to
Common Object Request
  Broker Architecture
 Overview   of distributed programming challenges
 Overview   of CORBA architecture
 CORBA    programming with Java ORB
 WWW,     Java and CORBA
 GIOP   and IIOP
 Trends   in Internet
     CORBA Contributions
   CORBA addresses two challenges of developing
    distributed system:
     Making distributed application development no more
      difficult than developing centralized programs.
     Easier said than done due to :
          Partial failures
          Impact of latency
          Load balancing
          Event Ordering
     Providing an infrastructure to integrate application
      components into a distributed system
     i.e., CORBA is an "enabling technology"

Related Works
 Related technologies for application integration
 include :
 Traditional RPC
   Provides   "procedural" integration of application
   Doesn't provide object abstractions
   Does not address inheritance of interfaces

 Widows DCOM
CORBA Components
   The CORBA specification is comprised of several parts :
       1.   An Object Request Broker (ORB)
       2.   Basic Object Adapter (BOA), Portable Object Adapter(POA)
       3.   An Interface Definition Language (IDL)
       4.   A Static Invocation Interface (SII)
       5.   A Dynamic Invocation Interface (DII)
       6.   A Dynamic Skeleton Interface(DSI)
       7.   Interface and implementation repositories
       8.   Programming language mappings
       9.   An Interoperability Spec(GIOP and IIOP)
   Other documents form OMG descirbe common object
    services built upon CORBAservices
      e.g. , Event services, Name services, Lifecycle service
Object Request Broker
    Object Request Broker(ORB) is the central
 The
 component in CORBA
   AnORB provides mechanisms for invoking methods
   on local/remote objects

 ORB    mechanisms automate :
   Objectlocation, creation, activation and object
   Message exchange between objects

 CORBA    ORB provides security also.
Interface Definition Language (IDL)

      Developing flexible distributed applications on
       heterogeneous platforms requires a strict
       separation of interface from implementation(s)
      Benefits of using an IDL
        Ensure platform independence
            e.g., Windows NT to UNIX

        Enforce modularity
            e.g., must separate concerns
        Increase robustness
            e.g., reduce opportunities for network programming errors
        Enable language independence
            e.g., C, Smalltalk, COBOL to C++, Java
   OMG IDL is an object-oriented interface definition
     Used  to specify interfaces containing operations and
     OMG IDL support interface inheritance (both single and
      multiple inheritance)
   OMG IDL is designed to map onto multiple
    programming languages
     e.g.,   C, C++, Smalltalk, COBOL, Modula 3, DCE, Java,
   OMG IDL is similar to Java interfaces, class and
    C++ class
Initial OMG IDL Bank Specification

   // Bank.idl
   module Bank {
   interface Account {
     float balance();
   interface AccountManager {
     Account open(in string name);

OMG IDL Compiler
A OMG IDL compiler generates client stubs and
 server skeletons
 Stubs  and skeletons automate the following
 activities (in conjunction with the ORB)
   Clientproxy factories
   Prameter marshalling/demarshalling
   Implementation class interface generation
   Object registration and activation
   Object location and binding
Producing IDL file, Client, and Object

Application Interfaces
   Interfaces described using OMG IDL may be
    application-specific, e.g.,
     Databases
     Spreadsheets
     Spell checker
     Network manager
     Air traffic control
     Documents
     Medical imaging systems

   Objects may be defined at any level of granularity
       e.g., from fine-grained GUI objects to multi-mega byte
        multimedia "Blobs"
OMG IDL Features
   OMG IDL is a superset of C++, Java, etc.
       Note, it is not a complete programming language, it only defines
   OMG IDL supports the following features :
       Modules
       Interfaces
       Operations
       Attributes
       Inheritance
       Basic types(e.g., double, long, char, etc).
       Arrays
       Sequence
       Struct, enum, union, typedef
       Consts
       Exceptions
Object References

 An    "Object reference" is an opaque handle
    to an object
 Object   references amy be passed among
    processes on separate hosts
     The underlying CORBA ORB will correctly convert object
      references into a form that can be transmitted over the network
         Presumably by converting it to a "stringfied" reference
     The ORB passes the receiver's implementation a pointer to a
      proxy in its own address space
         This proxy refers to the object's implementation

   Object references are a powerful feature of
       e.g., supports "peer-to-peer" interactions
Object Adaptor

   CORBA "object adaptors" provide services for
    binding object references to their associated
    object implementations
   Several types of object adaptors are available :
       Basic Object Adaptor(BOA)
          Objects and object references are known to the ORB

          Thus, an object implementation has to explicitly register objects
           to be activated

   Object-Oriented Database Adaptor(OODA)
     This adapter uses a connection to an o-o db to access
      the objects stored in it.
     Since the OODB provides the emthods and persistent
      storage, object may be registerd implicitly.
      Object Adaptor

   Creation and Analysis of Object Reference
   Method Invocation
   Interaction
   Activation and Deactivation of Object and Implementation
   Matching to    Object    Implementation     According   to   Object
   Registration of Object

   Problem of BOA
     Inconsistency of Specification
     Difference of BOA Implementation
     Problem in Server Portability
         Portable Object Adaptor
   Allow the Persistent Object
   Allow more Object Implementation

   Characteristics
       Map an Object Reference to the Servant that Implements that object
       Allow Transparent Activation of Objects
       Associate Policy Information With Objects
       Make a CORBA object persistent over several server process lifetimes
       Object ID Namespace
       Policy of Multi-Threading, Security, Object Management
       Multi POA with different policy and name space exist in a server

 Hello   Example

   Look at the demonstration
   You can exercise the CORBA programming
    using JDK simply.
Internet Inter-ORB Protocol (IIOP)

    The mapping of the GIOP message transfer to
     TCP/IP connections is called IIOP
    GIOP can map to Novell IPX and OSI also
    TCP/IP Connection Usage
        Servers must listen for connection requests.
        A client needing a object’s services must initiate a connection
         with the address specified in the IOR, with a connection request
        The listening server may accept or reject the connection.
        Once a connection is accepted, the client may send Request,
         LocateRequest, or CancelRequest messages by writing to the
         TCP/IP socket it owns for the connection.

CORBA Common Services
      Services to build distributed object
 Basic
 Naming,  Event, Persistence, Life Cycle,
 Concurrency, Externalization, Relation,
 Transaction, Timing, License,
 Security,Property, Query, Trader,
 Collection, Startup, Interface type Version
 Management Services

CORBA Common Facilities

   Software Components to provide some
    application function
   Horizontal facilities, Vertical facilities
   Horizontal facilities : Compound Presentation,
    Compound Interchange, Internalization, Time
    Operations, Mobile Agent, System Management
   Vertical facilities : Healthcare, Financial Facilities.


To top