Components for Web Applications - PowerPoint PPT Presentation

1 / 40
About This Presentation
Title:

Components for Web Applications

Description:

Web server: application that responds to HTTP requests by returning web' ... Wainright, P., 'Professional Apache,' Wrox Press Ltd. http://www.webdav.org ... – PowerPoint PPT presentation

Number of Views:109
Avg rating:3.0/5.0
Slides: 41
Provided by: mpe580
Category:

less

Transcript and Presenter's Notes

Title: Components for Web Applications


1
Components for Web Applications
  • Marcia Perry
  • Distributed Systems Department
  • Ernest Orlando Lawrence Berkeley National
    Laboratory
  • August 14, 2001

2
Organization
  • Major Components
  • Overview of the Build Process
  • Configuration
  • URL to File System Mappings
  • Starting/Stopping Web Server Processes
  • More Information

3
Basic Components
  • Web server application that responds to HTTP
    requests by returning web resources (e.g., HTML
    files, images, applets, CGI output, ) over the
    Internet
  • CGI (Common Gateway Interface)
  • conventions used by a web server to execute
    programs
  • early technique for creating dynamic content
  • scripts/apps executed by web server

4
Advanced Components
  • Servlets
  • Java classes loaded into and run by a JVM
    (requires a servlet container)
  • In response to HTTP requests
  • To extend web server functionality
  • Adv. over CGI
  • Java (one language, portability, convenience,
    type-checking, error-handling, )
  • Efficiency (classes usually loaded once not
    necessarily run as separate process)

5
Advanced Components
HelloWWW.java
  • import java.servlet. import java.servlet.http.
    import java.io.
  • public class HelloWWW extends HttpServlet
  • public void doGet(HttpServletRequest req,
    HttpServletResponse resp)
  • throws ServletException, IOException
  • resp.setContentType(text/html)
  • PrintWriter out resp.getWriter()
  • out.println(lthtmlgtltbodygtHello
    WWWlt/bodygtlt/htmlgt)
  • out.close()

6
Servlet Containers
  • Servlet containers can be
  • Standalone Integral part of web server (as when
    using a Java-based web server)
  • Add-on component to web server Java container
    implementation web server plugin
  • Servlet code runs inside Java container
  • Java container runs inside of JVM
  • Web server plugin opens JVM

7
Advanced Components
  • JSPs (Java Server Pages) for mixing static
    content w/ dynamically generated content
  • JSPs are automatically translated into servlets
    behind the scenes
  • More convenient to write/modify
  • Separates content from presentation

8
Advanced Components
Sample JSP page
  • ltHTMLgtltHEADgtltTITLEgtWelcome to Our
    Storelt/TITLEgtlt/HEADgt
  • ltBODYgtltH1gtWelcome to Our Storelt/H1gtWelcome,
  • lt!-- User name is New User for first time
    visitors --gt
  • lt Utils.getUserNameFromCookie(request) gt
  • To access your account settings, click ltA
    HREFAccount-Settings.htmlgt here.lt/Agt
  • Regular HTML for the rest of the on-line stores
    web page.
  • lt/BODYgtlt/HTMLgt

9
Advanced Components
  • Applets Java code that runs inside browser
  • Advantages
  • Extends functionality on the client side
  • More complicated GUIs than w/ HTML or JavaScript
  • Computation can be off-loaded from server
  • Users dont have to build, install, and configure
  • Disadvantages
  • Download time
  • Sandbox limits functionality (unless signed)
  • Window management by browser

10
Advanced Components
  • JavaScript
  • Interpretive language w/ object-oriented
    capabilities
  • Allows including executable content within web
    pages (e.g., window management, further
    processing)
  • Both client and server side

11
Apache
  • Apache Industrial strength HTTP/1.1 compliant
    web server
  • Highly configurable
  • Implements many features in addition to its core
    functionality (e.g., security/access control,
    virtual hosting, CGI script execution, )
  • Extensible with third-party modules (e.g.,
    servlet engine, security, WebDAV, )

12
Modules for Apache
  • mod-ssl (secure HTTP communication between a
    browser and a web server)
  • Provides strong cryptography for privacy
  • Provides use of digital signatures for data
    integrity
  • Allows server and/or client authentication
  • Integrates SSL/TLS protocols w/ Apache (via
    OpenSSL)
  • mod-dav (publishing into the web environment)
  • Provides server support for WebDAV (web-based
    distributed authoring and versioning)
  • Implements WebDAV extensions to HTTP 1.1

13
Tomcat
  • Tomcat Java-based web server servlet container
    w/ JSP environment
  • Execution modes
  • Standalone default mode for Tomcat
  • Out-of-process add-on web server plugin opens
    JVM outside web server plugin and JVM
    communicate using IPC mechanism (TCP/IP sockets
    and special protocol)
  • Most popular!!

14
Tomcat Execution Modes
  • Standalone
  • Not as fast as Apache for static pages
  • Not as configurable as Apache
  • Not as robust as Apache
  • May not support functionality found only in
    Apache modules (e.g., Perl, PHP, security)
  • Mainly for development and debugging

15
Tomcat and Apache
  • Communication mechanism between Tomcat and
    Apache
  • Termed web server adapter or connector
  • Implemented as library (e.g., mod_jserv.so,
    mod_jk.so)
  • Uses/manages TCP connections
  • Uses the AJPV12/AJPV13 communication protocol

16
A Basic Installation
servlet
17
How Apache Tomcat Interoperate
http//host/path/to/resource
Apache
adapter
Apache in standalone mode Tomcat in
out-of-process add-on mode
18
Building and Installing Apache and Tomcat
  • Apache supports statically-linked and
    dynamically-linked modules (DSOs)
  • Script to automate the build/configure process
    www-itg.lbl.gov/Grid/projects/WebServer-SG.html
  • Step-by-step procedure www-itg.lbl.gov/mperry/ap
    ache_build.html

19
Overview of the Build Process
  • Assumptions
  • Java already installed (JDK 1.2/JDK1.3)
  • APACHE /usr/local/apache
  • TOMCAT /usr/local/tomcat
  • Build OpenSSL (needed for mod_ssl)
  • Configure mod_ssl
  • Build mod_dav.a
  • Build and install Apache w/ DSO support

20
Configuration
  • Apache
  • httpd.conf (in APACHE/conf/) master
    configuration file
  • tomcat-apache.conf (generated by tomcat at
    startup from tomcat.conf) included in httpd.conf
    to give mod_jserv info about Tomcat
  • Tomcat (in TOMCAT/conf/)
  • server.xml global configuration file for Tomcat
  • tomcat.conf for interoperability between Apache
    Tomcat
  • web.xml deployment descriptor configures Tomcat
    web applications (contexts) by mapping web app
    components and properties

21
Configuring the Ports
Default configuration
http/8080
Apache
Tomcat
22
Configuring the Ports
server.xml lt! disable webserver on port 8080
ltConnector classNameorg.apache.tomcat.servi
ce.SimpleTcpConnectorgt ltParameter
namehandler valueorg.apache.tomcat.service.ht
tp.HttpConnectionHandler/gt ltParameter
nameport value8080/gt
lt/Connectorgt --gt ltConnector
classNameorg.apache.tomcat.service.SimpleTcpConn
ectorgt ltParameter namehandler
valueorg.apache.tomcat.service.connector.Ajp12Co
nnectionHandler/gt ltParameter nameport
value8007/gt lt/Connectorgt
23
Configuring the Ports
  • tomcat.conf
  • Tell Apache to load the shared object
    communication module
  • LoadModule jserv_module libexec/mod_jserv.so
  • Set communication protocol and port
  • ApJServDefaultProtocol ajpv12
  • ApJServDefaultPort 8007

24
Configuring the Ports
  • httpd.conf
  • ServerRoot /usr/local/apache
  • Heres where we can overwrite default ports
  • Port 80
  • ltIfDefine SSLgt
  • Listen 80
  • Listen 443
  • lt/IfDefinegt
  • ltVirtualHost _default_443gt

25
Sample File System
  • APACHE
  • TOMCAT

26
URL to File System Mappings
  • httpd.conf
  • DocumentRoot /usr/local/apache/htdocs
  • ltIfDefine SSLgt
  • General setup for the virtual host
  • DocumentRoot /usr/local/apache/securedocs
  • Lots of stuff
  • lt/IfDefinegt
  • Include /usr/local/tomcat/conf/tomcat-apache.conf

http//hostname / foo/
/usr/local/apache/htdocs/ foo/
https//hostname / foo/
/usr/local/apache/securedocs/ foo/
27
Apache Directory Access
  • Restrict access on per-directory basis via
    httpd.conf.
  • ltDirectory /gt
  • AllowOverride None
  • lt/Directorygt
  • ltDirectory /usr/local/apache/htdocs/webDAVdirgt
  • Order deny, allow
  • Deny from all
  • Allow from .lbl.gov
  • DAV On
  • lt/Directorygt

28
Apache Directory Access
  • Per-directory access restriction (httpd.conf)
  • ltDirectory /usr/local/apache/htdocs/webDAVdirgt
  • Order deny, allow
  • ltLimit GET POST gt
  • Deny from all
  • Allow from .lbl.gov
  • lt/Limitgt
  • ltLimit PUT DELETE MKCOL COPY MOVE LOCK UNLOCKgt
  • Deny from all
  • Allow from 131.243.2
  • lt/Limitgt
  • lt/Directorygt

29
Tomcat File System
index.html
30
URL to File System Mappings
  • tomcat-apache.conf
  • AddType text/jsp .jsp
  • AddHandler jserv-servlet .jsp
  • Alias /examples /usr/local/tomcat/webapps/examples
  • ApJServMount /examples/servlet /examples
  • ltLocation /examples/WEB-INF/ gt
  • AllowOverride none
  • deny from all
  • lt/Locationgt

31
URL to File System Mappings
  • server.xml
  • ltContext path/examples docBasewebapps/examp
    les debug0 reloadabletrue
  • lt/Contextgt

SIDE NOTES (1) path is used in URLs docBase
is actual directory name on f/s. They do NOT have
to match! (2)Tomcat docs recommend turning on
servlet auto-reloading only for development.
32
Configuring a Context
  • web.xml
  • ltweb-appgt
  • ltservletgt
  • ltservlet-namegtMyServletlt/servlet-namegt
  • ltservlet-classgtSimpleServletlt/servlet-classgt
  • lt/servletgt
  • ltservlet-mappinggt
  • ltservlet-namegtMyServletlt/servlet-namegt
  • lturl-patterngt/docservlet/lt/url-patterngt
  • lt/servlet-mappinggt
  • lt/web-appgt

URLs
https//server/context/url-pattern/servlet-name
servlet-class servlet default
url-pattern
http//shaggy/ examples/servlet/MyServlet
examples/servlet/SimpleServlet
examples/docservlet/MyServlet
examples/docservlet/NewServlet
33
Starting Tomcat
  • Do NOT start Tomcat as root.
  • Create a new user account or use an existing one.
  • Use the startup.sh script in TOMCAT/bin
  • If necessary add or modify entries for JAVA_HOME,
    TOMCAT_HOME, and CLASSPATH.

34
Tomcat Startup Script
  • TOMCAT/bin/startup
  • !/bin/sh
  • TOMCAT_HOME/usr/local/tomcat
  • export TOMCAT_HOME
  • PATH/usr/local/java/binPATH
  • export PATH
  • CLASSPATHCLASSPATH/usr/local/MyJavaPkg.
  • export CLASSPATH
  • BASEDIRdirname 0
  • BASEDIR/tomcat.sh start _at_

35
Executing Apache
  • Specify user and group to run as (in httpd.conf)
  • User nobody
  • Group cpc
  • Remember to add libexec/ to LD_LIBRARY_PATH
  • Start Apache as root
  • cd /usr/local/apache/bin
  • ./apachectl startssl

36
Starting Apache
  • Sample startup script APACHE/start
  • !/bin/sh
  • LD_LIBRARY_PATH/usr/local/apache/libexec/usr/loc
    al/openssl-0.9.6LD_LIBRARY_PATH
  • export LD_LIBRARY_PATH
  • /usr/local/apache/bin/apachectl startssl
  • echo Apache started

37
Starting Apache
  • Usage APACHE/bin/httpd -d directory -v -h
    -l
  • -d specify alternative ServerRoot
  • -v show version number
  • -h list available command line options
  • -l list compiled-in (static) modules

38
Stopping Apache/Tomcat
  • Tomcat
  • As tomcat user run TOMCAT/bin/shutdown.sh
  • Apache
  • As root, use apachectl (or write a stop
    script)
  • cd /usr/local/apache/bin
  • ./apachectl stop
  • OR
  • cd /usr/local/apache
  • ./stop

39
More Information
  • Wainright, P., Professional Apache, Wrox Press
    Ltd.
  • http//www.webdav.org/
  • http//httpd.apache/org/docs/
  • http//jakarta.apache.org/tomcat/
  • http//java.sun.com/products/servlet/download/

40
More Information
  • http//www.ccl.net/cca/software/UNIX/apache/
  • http//www-itg.lbl.gov/mperry/apache_build.html
  • http//www-itg.lbl.gov/Grid/projects/WebServer-SG.
    html
  • https//idcg-ca.lbl.gov
  • http//www.modssl.org/
Write a Comment
User Comments (0)
About PowerShow.com