java server and servlets

Upload: ashishkumar-haldar

Post on 04-Jun-2018

246 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 JAVA Server and Servlets

    1/61

    Servers and Server Extensions

  • 8/13/2019 JAVA Server and Servlets

    2/61

    JavaJavaServer andServer andServletsServlets

    Pavani DiwanjiPavani DiwanjiDave ConnellyDave Connelly

    Prasad WaglePrasad Wagle

  • 8/13/2019 JAVA Server and Servlets

    3/61

    Outline

    Jeeves - The Java Web Server Technical Overview

    Implementation and Examples

    Administration and Performance

    Demos

    Questions?

  • 8/13/2019 JAVA Server and Servlets

    4/61

    Why?

    Why do yet another web server?

    Why do a server toolkit in Java?

    Why develop the web server in Java?

  • 8/13/2019 JAVA Server and Servlets

    5/61

    Why?

    Java Ubiquity: client and server side Cannot do toolkit without a reference

    Application Server

    Java: A better language for developing

    Applications

    Multiplatform servers and servlets

  • 8/13/2019 JAVA Server and Servlets

    6/61

    What Are Http Servlets?

    Servlets are Java objects that extendthe web server functionality:

    server-side applets

    Dynamically loadable at runtime Loaded from the local disk or the net

  • 8/13/2019 JAVA Server and Servlets

    7/61

    Http Servlets...

    Servlets are identified using a class name or a

    URL (i.e http://host/)

    Servlets are instantiated at server startup time

    or on demand Servlets live on until server decides to

    remove them

    Arguments can be passed to a servlet atinitialization time and per request

  • 8/13/2019 JAVA Server and Servlets

    8/61

    Http Servlet Interface

    interface HttpServlet {interface HttpServlet {

    initialize(ServletContext, ServerProperties);initialize(ServletContext, ServerProperties);

    service(HttpRequest, HttpResponse);service(HttpRequest, HttpResponse);

    destroy();destroy();

    }}

    Handles to the per request, response

    information like input and output streams etc. ServletContext: Context information

    accessible to the servlet

  • 8/13/2019 JAVA Server and Servlets

    9/61

    Http Servlet Invocation

    Conventional invocation (CGI style) http:///date.html?

    Explicit invocation:

    http:///?

    Server side includes

    Servlet tag

    Parsing is expensive

  • 8/13/2019 JAVA Server and Servlets

    10/61

    Example Servlets

    Web servlets: All the existing cgi-scriptscan be done better as Java servlets

    Online publishing helper servlets

    Financial servlets: online banking etc. Other Cool Servlets: Chat, Calendar,

    Notifier

    Proxy servlets: Filtering, Traffic

    characterizing etc.

  • 8/13/2019 JAVA Server and Servlets

    11/61

  • 8/13/2019 JAVA Server and Servlets

    12/61

    Database Connectivity

    Example servlets using JDBC APIs:

    Connectivity to Sybase and Oracle

    databases

    Capability to execute SQL queries on thedatabase

    Working with vendors to provide higher

    level database connectivity classes as well

  • 8/13/2019 JAVA Server and Servlets

    13/61

    Simple, But Useful

    Persistant Applets using DBServlet Serialization API

    Security

    Applet DBServletStore

    Restore

  • 8/13/2019 JAVA Server and Servlets

    14/61

    Security: Servlets

    Security needed for network servlets

    Runtime server security manager gives policy

    control to the server administrator

    Servlets loaded from the network runs in aseparate thread in a distinct group

    Use signed class loader for loading signed

    servlets First release: Allow only local servlets and

    signed network servlets

  • 8/13/2019 JAVA Server and Servlets

    15/61

    Security: Access Control

    ACL classes can guard multiple entities:

    Servers, servlets, files, directories

    Access Control Manager is consulted by

    the server, for protected entities Default Server ACL

    Servlets can do custom authorization

  • 8/13/2019 JAVA Server and Servlets

    16/61

    Security: Authentication

    Authentication: Standard security protocol

    support i.e. SSL

    Make use of the base encryption

    capabilities (java.security) Current state: Basic Http Authentication,

    ACL based Authorization

  • 8/13/2019 JAVA Server and Servlets

    17/61

    Dynamic Html Generation

    Really simple but useful: sun.server.html

    Classes: HtmlPage, HtmlTag, HtmlText..

    Code:

    HttpOutputStream out = resp.getOutputStream();HtmlPage = new HtmlPage(Welcome Page);

    page.addElement(new HtmlTagPair(H1, Hello));

    page.write(out);

    out.flush();

  • 8/13/2019 JAVA Server and Servlets

    18/61

    Server Administration

    Most existing servers allow local

    administration

    Some servers allow administration through

    the Web but they use a fixed forms based

    interface

    Dynamic, user-customizable server tools

    through the use of applets (client side) andcorresponding server objects

  • 8/13/2019 JAVA Server and Servlets

    19/61

    Roadmap

    When?

    First Internal release April

    Demo in Developer conference May

    Alpha soon, FCS later this year

    Provide the base extensible framework

    and a completely Java-based web server

    along with some sample demo servlets to

    start with

    Use the toolkit to feature other servers later

  • 8/13/2019 JAVA Server and Servlets

    20/61

    Java ServerJava Serverandand

    ServletsServlets

    David ConnellyDavid ConnellyJavaSoftJavaSoft

  • 8/13/2019 JAVA Server and Servlets

    21/61

    Overview

    Server foundation class

    HttpServer implementation

    Servlet API and example

    Network servlets

    Performance issues

  • 8/13/2019 JAVA Server and Servlets

    22/61

    Class sun.server.Server

    Abstract class for implementing

    connection-oriented servers

    Manages pool of handler threads

    Many tuneable parameters

    Parameters can be changed on-the-fly

  • 8/13/2019 JAVA Server and Servlets

    23/61

    sun.server.Server

    public abstract

    class Server implements Runnable {

    public Server(ServerProperties props);

    public Socket getConnection();

    public void run();

    public abstract ServerHandler createHandler();

    }

  • 8/13/2019 JAVA Server and Servlets

    24/61

    sun.server.ServerHandler

    public abstract

    class ServerHandler implements Runnable {

    public void run();

    public abstract

    void handleConnection(Socket s)

    throws IOException;

    }

  • 8/13/2019 JAVA Server and Servlets

    25/61

    How it Works...

    Server

    ServerHandler

    c c c

    ServerHandler

    ServerHandler

    Connection Queue

    getConnection()

    accept()

  • 8/13/2019 JAVA Server and Servlets

    26/61

    Implementing a Server

    Extend sun.server.Server

    implement createHandler()

    Extend sun.server.ServerHandler

    implement handleConnection()

  • 8/13/2019 JAVA Server and Servlets

    27/61

    Example: EchoServer

    EchoServer

    ServerHandlerServer

    EchoServerHandler

    createHandler() handleConnection()

    extendsextends

  • 8/13/2019 JAVA Server and Servlets

    28/61

    Example: EchoServer

    class EchoServer extends Server {

    public EchoServer() {init(System.getProperties());

    }

    public ServerHandler createHandler() {

    return new EchoServerHandler(this);

    }

    public static void main(String args[]) {

    new EchoServer().run();

    }

    }

  • 8/13/2019 JAVA Server and Servlets

    29/61

    EchoServerHandler

    class EchoServerHandler extends ServerHandler {

    void handleConnection(Socket s) throws IOException { InputStream in = s.getInputStream();

    OutputStream out = s.getOutputStream();

    int len; byte[] buf = new byte[512];

    while ((len = in.read(buf)) != -1) {

    out.write(buf, 0, len);

    }

    in.close(); out.close();

    }

    }

  • 8/13/2019 JAVA Server and Servlets

    30/61

    HttpServer

    Extends sun.server.Server

    Inherits from sun.server.Server:

    Threads management

    Observable properties

    Supports local and network servlets

    Core extensions through servlets

  • 8/13/2019 JAVA Server and Servlets

    31/61

    How it Works...

    HttpServer HttpServerHandler

    FileServlet

    CgiServlet

    DBServlet

  • 8/13/2019 JAVA Server and Servlets

    32/61

    Core Servlets

    FileServlet

    Handles file GET requests

    Ram cache

    CgiServlet For backwards compatibility

    StubServlet

    For downloading network servlets

  • 8/13/2019 JAVA Server and Servlets

    33/61

    HttpServlet Interface

    interface HttpServlet { initialize(ServletContext, ServerProperties);

    service(HttpRequest, HttpResponse);

    destroy();

    }

  • 8/13/2019 JAVA Server and Servlets

    34/61

    BasicHttpServlet

    Implements HttpServlet

    Base class for writing most servlets

    Provides default implementation

    initialize(), destroy(), etc

  • 8/13/2019 JAVA Server and Servlets

    35/61

    HttpRequest

    Encapsulates Http request message

    Input stream for reading entity data

    Contains all header field values

    Headers parsed on demand

  • 8/13/2019 JAVA Server and Servlets

    36/61

    HttpResponse

    Encapsulates Http response message

    Used to set response headers

    Output stream for writing entity data

  • 8/13/2019 JAVA Server and Servlets

    37/61

    Example: HelloServlet

    class HelloServlet extends BasicHttpServlet {

    static String hello = Hello, world\r\n;public HelloServlet() {};

    public void service(HttpRequest req,

    HttpResponse res) {

    res.setContentLength(hello.length());

    res.writeHeaders();

    res.getOutputStream().print(hello);

    }

    }

  • 8/13/2019 JAVA Server and Servlets

    38/61

    FormServlet

    Automates parsing of form input

    Passes form input in Hashtable

    Servlets can extend FormServlet

    Override sendResponse()

    Easier than writing cgi-bin

  • 8/13/2019 JAVA Server and Servlets

    39/61

    Example: FormServlet

    class SimpleForm extends FormServlet {

    public void sendResponse(HttpResponse res,Hashtable table) {

    HttpOutputStream out = res.getOutputStream();

    res.putHeaders();

    Enumeration e = table.keys();

    while (e.hasMoreElements()) {

    String key = (String)e.getNextElement();

    out.print(key + = + table.get(key));

    }

    }}

  • 8/13/2019 JAVA Server and Servlets

    40/61

    Network Servlets

    StubServlet

    manages downloaded servlets

    Separate thread group, class loader

    Working on signed servlets support

  • 8/13/2019 JAVA Server and Servlets

    41/61

    Performance Enhancements

    Reuse per-request data

    Minimize object allocation

    Reduce GC overhead

    Minimize synchronized method calls

    HttpInputStream, HttpOutputStream

  • 8/13/2019 JAVA Server and Servlets

    42/61

    Keep-alive

    Support keep-alive count and timeout

    Content length maintains keep-alive

    Limitations with read()

    Alarm timer closes connection

    Thread.interrupt() is better solution

  • 8/13/2019 JAVA Server and Servlets

    43/61

    AlarmManager Class

    AlarmHandler

    AlarmHandler

    AlarmHandler

    AlarmManager

    handleAlarm()

  • 8/13/2019 JAVA Server and Servlets

    44/61

    Where Are We Now?

    HTTP 1.0 support, CGI

    Keep-alive

    HttpServlets: API and examples

    Prototype: signed network servlets

    ACL support

    Win32, Solaris releases

  • 8/13/2019 JAVA Server and Servlets

    45/61

    Where Are We Going?

    Proxy

    Filters

    SSL

    Session support

    Administration tools

  • 8/13/2019 JAVA Server and Servlets

    46/61

    JeevesJeeves

    AdministrationAdministrationandandPerformancePerformance

    Prasad WaglePrasad WagleJavaSoftJavaSoft

  • 8/13/2019 JAVA Server and Servlets

    47/61

    Jeeves Installation

    Simple

    Single binary release

    Disk space

    Memory

    Documentation - http:///doc/

  • 8/13/2019 JAVA Server and Servlets

    48/61

    Jeeves Administration

    Dynamic

    Remote

    Secure

    Front end is Java applets and HTML

    Back end is composed of servlets

  • 8/13/2019 JAVA Server and Servlets

    49/61

    Jeeves Administration

    Changing server properties

    Monitoring the server

    Administering servlets

  • 8/13/2019 JAVA Server and Servlets

    50/61

    Administration Examples

    Server properties

    MinThreads, maxThreads

    Keep-alive

    Memory cache sizeDocument hierarchy mappings

  • 8/13/2019 JAVA Server and Servlets

    51/61

    Administration Examples

    Logging

    Files or databases

    Format (Common Log, Free format)

  • 8/13/2019 JAVA Server and Servlets

    52/61

    Administration Examples

    Controlling access to documents

    Based on user, host, groups

    Create users, groups

    Security

  • 8/13/2019 JAVA Server and Servlets

    53/61

    Jeeves Monitoring

    Dynamic

    Number and rate of requests

    Type of requests

    Callbacks when certain events happen

  • 8/13/2019 JAVA Server and Servlets

    54/61

    Servlet Administration

    Servlet startup

    View loaded servlets

    Upload a servlet

    Servlet security restrictions

    Stop a servlet

  • 8/13/2019 JAVA Server and Servlets

    55/61

  • 8/13/2019 JAVA Server and Servlets

    56/61

    Jeeves Performance

    150 HTTPops/sec on an Ultra

    1 HTTPop = 1 request = 1 hit

    150 HTTPops/sec = 15 million/day

    Very respectable

    Will release SPECweb results

  • 8/13/2019 JAVA Server and Servlets

    57/61

    Jeeves Performance

    Java runtime:

    Garbage collection

    Threads

    MonitorsJIT compiler

  • 8/13/2019 JAVA Server and Servlets

    58/61

    Credits andCredits andContact Info.Contact Info.

    JavaSoftJavaSoft

  • 8/13/2019 JAVA Server and Servlets

    59/61

    Engineering Credits

    James Gosling (Architect)

    Dave Connelly (Server, Protocols)

    Satish Dharmaraj (Security)

    Pavani Diwanji (Lead Engineer)

    Rachel Gollub (Release)

    Marianne Mueller (Security)

    Freeman Murray (Html Gen., Demos)

    Prasad Wagle (Server, Performance)

    Dave Brownell (Security)

  • 8/13/2019 JAVA Server and Servlets

    60/61

    Contact Information

    http://www.javasoft.com/products/jeeves/

    [email protected]

  • 8/13/2019 JAVA Server and Servlets

    61/61

    Questions

    ?