Selected Topics in Java Web Application Development



Similar documents
Internet Engineering: Web Application Architecture. Ali Kamandi Sharif University of Technology Fall 2007

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

Servlet 3.0. Alexis Moussine-Pouchkine. mercredi 13 avril 2011

Java Servlet 3.0. Rajiv Mordani Spec Lead

3-Tier Architecture. 3-Tier Architecture. Prepared By. Channu Kambalyal. Page 1 of 19

Bayeux Protocol: la nuova frontiera della comunicazione a portata di mano. Relatore Nino Guarnacci

Glassfish, JAVA EE, Servlets, JSP, EJB

Course Number: IAC-SOFT-WDAD Web Design and Application Development

Learning GlassFish for Tomcat Users

WebSphere Application Server - Introduction, Monitoring Tools, & Administration

JBoss Seam Performance and Scalability on Dell PowerEdge 1855 Blade Servers

How to Build an E-Commerce Application using J2EE. Carol McDonald Code Camp Engineer

Chapter 2 TOPOLOGY SELECTION. SYS-ED/ Computer Education Techniques, Inc.

2012 LABVANTAGE Solutions, Inc. All Rights Reserved.

What Is the Java TM 2 Platform, Enterprise Edition?

Learn Oracle WebLogic Server 12c Administration For Middleware Administrators

Contents. Client-server and multi-tier architectures. The Java 2 Enterprise Edition (J2EE) platform

<Insert Picture Here> WebLogic High Availability Infrastructure WebLogic Server 11gR1 Labs

Some Issues on Ajax Invocation

This training is targeted at System Administrators and developers wanting to understand more about administering a WebLogic instance.

ACM Crossroads Student Magazine The ACM's First Electronic Publication

CHAPTER 1 - JAVA EE OVERVIEW FOR ADMINISTRATORS

OUR COURSES 19 November All prices are per person in Swedish Krona. Solid Beans AB Kungsgatan Göteborg Sweden

Server-Side JavaScript auf der JVM. Peter Doschkinow Senior Java Architect

Oracle WebLogic Server 11g Administration

Course Description. Course Audience. Course Outline. Course Page - Page 1 of 5

Preface. Motivation for this Book

Oracle WebLogic Server

Load Testing RIA using WebLOAD. Amir Shoval, VP Product Management

Performance Testing for Ajax Applications

White paper. IBM WebSphere Application Server architecture

A Survey Study on Monitoring Service for Grid

Tuning Your GlassFish Performance Tips. Deep Singh Enterprise Java Performance Team Sun Microsystems, Inc.

Basic TCP/IP networking knowledge of client/server concepts Basic Linux commands and desktop navigation (if don't know we will cover it )

White Paper: 1) Architecture Objectives: The primary objective of this architecture is to meet the. 2) Architecture Explanation

LinuxWorld Conference & Expo Server Farms and XML Web Services

IBM Rational Web Developer for WebSphere Software Version 6.0

Titolo del paragrafo. Titolo del documento - Sottotitolo documento The Benefits of Pushing Real-Time Market Data via a Web Infrastructure

Web Application Architecture (based J2EE 1.4 Tutorial)

Project SailFin: Building and Hosting Your Own Communication Server.

Capacity Planning Guide for Adobe LiveCycle Data Services 2.6

Java EE 7: Back-End Server Application Development

Clustering with Tomcat. Introduction. O'Reilly Network: Clustering with Tomcat. by Shyam Kumar Doddavula 07/17/2002

<Insert Picture Here> GlassFish v3 - A Taste of a Next Generation Application Server

The end. Carl Nettelblad

applications. JBoss Enterprise Application Platform

FIVE SIGNS YOU NEED HTML5 WEBSOCKETS

WEBSPHERE APPLICATION SERVER ADMIN V8.5 (on Linux and Windows) WITH REAL-TIME CONCEPTS & REAL-TIME PROJECT

WebSphere Training Outline

COM 440 Distributed Systems Project List Summary

Developer s Guide. Version 1.8

How To Build A Web App

CrownPeak Java Web Hosting. Version 0.20

Oracle WebLogic Server 11g: Administration Essentials

Web Cloud Architecture

.NET 3.0 vs. IBM WebSphere 6.1 Benchmark Results

Cognos8 Deployment Best Practices for Performance/Scalability. Barnaby Cole Practice Lead, Technical Services

Exploring Oracle E-Business Suite Load Balancing Options. Venkat Perumal IT Convergence

Open-Xchange Whitepaper Open-Xchange Server 6 Architecture Overview

Introduction to Cloud Computing. Lecture 02 History of Enterprise Computing Kaya Oğuz

Controlling Web Application Behavior

Reusing Existing * Java EE Applications from Oracle SOA Suite

JAX-WS Developer's Guide

ActiveVOS Server Architecture. March 2009

Contents Introduction... 5 Deployment Considerations... 9 Deployment Architectures... 11

Holistic Performance Analysis of J2EE Applications

WebLogic & Coherence. Best backend for Mobile Apps. July 2014 INSERT PRESENTER TITLE AND DATE

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

Web application development landscape: technologies and models

AJAX and jmaki for Web 2.0 Development using Java. Inyoung Cho Java Technology Evangelist Sun Microsystems, Inc.

Liferay Performance Tuning

Google Web Toolkit (GWT) Architectural Impact on Enterprise Web Application

DEPLOYMENT GUIDE Version 1.1. Deploying F5 with IBM WebSphere 7

White Paper: Why Upgrade from WebSphere Application Server (WAS) v7 to v8.x?

Enterprise Application Integration

Oracle Weblogic. Setup, Configuration, Tuning, and Considerations. Presented by: Michael Hogan Sr. Technical Consultant at Enkitec

IBM WebSphere Server Administration

Apache Tomcat. Load-balancing and Clustering. Mark Thomas, 20 November Pivotal Software, Inc. All rights reserved.

WEB SERVICES. Revised 9/29/2015

WebSphere Product Family Overview

Managing Data on the World Wide-Web

JAVA/J2EE DEVELOPER RESUME

A Comparison of Software Architectures for E-Business Applications

Building Web Services with Apache Axis2

Dragan Juričić, PBZ May 2015

Winning the J2EE Performance Game Presented to: JAVA User Group-Minnesota

An Oracle White Paper July Oracle Primavera Contract Management, Business Intelligence Publisher Edition-Sizing Guide

Credits: Some of the slides are based on material adapted from

GlassFish Security. open source community experience distilled. security measures. Secure your GlassFish installation, Web applications,

Introduction to Sun ONE Application Server 7


MEGA Web Application Architecture Overview MEGA 2009 SP4

Web Container Components Servlet JSP Tag Libraries

A Scalability Study for WebSphere Application Server and DB2 Universal Database

Transcription:

http://www.gerald-loeffler.net/download/java_web_app_dev_2008-10-27.pdf Selected Topics in Java Web Application Development Dr Gerald Loeffler, MBA Web Engineering I WU Wien

2 this presentation agenda web applications and Java EE web applications, Java EE application servers, processing paradigms, important APIs availability and scalability of web applications definitions, horizontal and vertical scalability, load balancers, clustering, availability through redundancy, using HttpSession browser-server interaction beyond simple request-response AJAX and XMLHttpRequest, JSON, Comet, Bayeux, asynchronous servlet request processing this is an overview presentation and will sadly not convey enough detail to actually start using any of the covered technologies > see references and bibliography!

3 references and bibliography (1/4) [1] Java Platform, Enterprise Edition 5 (Java EE 5) Specification, Sun Microsystems http://jcp.org/aboutjava/communityprocess/final/jsr244/index.html [2] The Java EE 5 Tutorial, Sun Microsystems http://java.sun.com/javaee/5/docs/tutorial/doc/ [3] What is an App Server?, Joseph Ottinger, http://www.theserverside.com/tt/articles/article.tss?l=whatisanappserver [4] Release It! Design and Deploy Production-Ready Software, Michael T. Nygard, The Pragmatic Bookshelf [5] Auto-Complete with AJAX, Greg Murray https://bpcatalog.dev.java.net/ajax/autocomplete/index.html

4 references and bibliography (2/4) [6] ICEfaces Developer s Guide, ICEsoft Technologies http://www.icefaces.org [7] The XMLHttpRequest Object, W3C http://www.w3.org/tr/xmlhttprequest/ [8] Introducing JSON http://json.org [9] ECMAScript Language Specification 3 rd Edition, Standard ECMA-262, ECMA http://www.ecma.ch [10] Bayeux Protocol 1.0draft1, The Dojo Foundation http://svn.xantus.org/shortbus/trunk/bayeux/bayeux.html

5 references and bibliography (3/4) [11] Comet: Low Latency Data for the Browser, Alex Russell http://alex.dojotoolkit.org/2006/03/comet-low-latency-data-for-the-browser/ [12] GlassFish application server https://glassfish.dev.java.net/ [13] Project Grizzly https://grizzly.dev.java.net/ [14] dojo the JavaScript toolkit http://dojotoolkit.org/ [15] Java theory and practice: State replication in the Web tier, Brian Goetz http://www.ibm.com/developerworks/java/library/j-jtp07294.html

6 references and bibliography (4/4) [16] Java Servlet Specification, Version 3.0 Early Draft, Sun Microsystems http://jcp.org/aboutjava/communityprocess/edr/jsr315/index.html [17] Are all stateful Web applications broken?, Brian Goetz http://www.ibm.com/developerworks/java/library/j-jtp09238.html [18] The application/json Media Type for JavaScript Object Notation (JSON), RFC 4627, IETF, D. Crockford http://www.ietf.org/rfc/rfc4627.txt?number=4627

web applications and Java EE

8 what s a web application? Address Verification Message Oriented Middleware Host JAX-WS SOAP/HTTP JMS TCP/IP Customer Browser HTTPS Web App App Server JDBC SQL*Net DB HTTPS SOAP/HTTP Administrator Browser Monitoring System SNMP JNDI LDAP Directory Server JAX-WS SOAP/HTTP Document Management System Printing Scanning

9 what s a Java EE application server? software product Sun Glassfish, Oracle/BEA WebLogic, IBM WebSphere AS,... runtime environment for Java EE apps/modules/comps web apps, enterprise apps, connectors,... exposing Java EE APIs to these applications providing services such as listeners for HTTP/HTTPS (hence SOAP/HTTP), IIOP thread pools JDBC connection pools transaction management JMS provider (i.e., message-oriented middleware) security, management, deployment, lifecycle,... References: [1, 3, 12]

10 demo GlassFish v2 admin basics References: [12]

11 processing paradigms in Java EE (1/2) synchronous request/response HTTP: Servlets, JSPs, SOAP/HTTP; IIOP; local: EJBs client issues request, waits for server to respond server receives request, blocks thread until response ready by far the most common in typical Java EE applications can be asynchronized selectively asynchronous HTTP client asynchronous EJBs in EJB 3.0/Java EE 6 async servlets in Servlet 3.0/Java EE 6 References: [2, 3, 16]

12 processing paradigms in Java EE (2/2) timer-triggered execution/batch processing EJB timers EJB creates timer application server invokes timeout callback on EJB asynchronous messaging via JMS message producer sends message to destination (queue, topic) hosted in JMS provider (MOM) message consumer receives message from destination receipt is decoupled from send may be synchronous (polling) or asynchronous (callback) asynchronous processing of messages from connector similar to asynchronous JMS message receipt via MDBs References: [2, 3]

13 some important APIs in Java EE 5 EJB 3.0 including Java Persistence (JPA) 1.0, JDBC 3.0 transactional, secure, remotable business logic components persistent entitites: objects stored in a relational database Servlet 2.5, JSP 2.1, JSF 1.2 for building web user interfaces in web applications JMS 1.1 sending/receiving messages to/from queues/topics JTA 1.1 to interface with a transaction manager, e.g. to demarcate TXs JAX-WS 2.0, JAXB 2.0, StAX 1.0 expose or call web services manipulate XML documents References: [1, 2]

availability and scalability of web applications

15 definitions (1/3) workload the number of transactions (requests) requested from a system in a given time span less precise: the number of concurrent users transactions per second, requests per second e.g., 500 request per second performance the time required to process a single transaction (request) response time varies depending on the kind of transaction and the workload of the system e.g., 0.2s References: [4]

16 definitions (2/3) throughput the number of transactions (requests) processed by a system in a given time span transactions per second, requests per second e.g., 250 TPS capacity the sustainable throughput of a system while maintaining good enough performance e.g., 300 requests per second at 0.2s median response time scalability if/how to increase the capacity of a system typically by adding hardware References: [4]

17 definitions (3/3) availability the fraction of time the system executes transactions/requests correctly and with expected performance 1 - downtime should be qualified with type of request/functionality e.g., 99.999% availability for opening new accounts, 98% availability for managing existing accounts, 90% availability for functionality accessed through admin user interface References: [4]

18 scalability vertical scalability add hardware (CPUs, RAM, disks,...) to existing servers limited by type/model of server typical for scaling database servers horizontal scalability add new servers also adds redundancy typical for scaling web/application servers linear scalability increasing available hardware (horizontally or vertically) by a factor of F increases capacity by the same factor 300 rps with 2 servers, 600 rps with 4 servers, @ same resp time References: [4]

19 horizontal and vertical scalability Browser Browser Load Balancer Load Balancer Web App App Server 2 CPUs 8 GB RAM Web App App Server 2 CPUs 8 GB RAM Web App App Server 2 CPUs 8 GB RAM Web App App Server 2 CPUs 8 GB RAM Web App App Server 2 CPUs 8 GB RAM DB 4 CPUs 32 GB RAM DB 6 CPUs 48 GB RAM References: [4]

20 load balancer client directs request (HTTP or any TCP/IP-based protocol) at load balancer (through its virtual IP) which forwards it to one of several back-end servers web app on back-end servers gens URLs with lb s DNS name configurable distribution algorithm round-robin, weighted/unweighted, request/load-based,... session affinity: lb routes all requests for the same HTTP session to the same server (inspects cookies/request URLs) detects health of back-end servers periodically probes servers with health-check requests hardware (F5, Altheon) or (with limitations) software (Apache mod_proxy_balancer) References: [4]

21 application server clustering (1/3) all serious Java EE application servers are clusterable keeping state in application server nodes makes the nodes distinguishable (non-interchangeable) here: HTTP session state but also: stateful session bean instances, in-memory caches,... the primary feature of clustering is state replication, i.e., the copying of state from the app server node in the cluster that has the authoritative copy of that piece of state (typically because that s where it has last been changed) so that the heap (RAM) of that app server node is not the only place where that state is kept and so that that state can be accessed from other nodes References: [4, 15]

22 application server clustering (2/3) where can (session) state be copied to?: to other app server nodes (backup servers) in the cluster must decide to how many (at least 1) and which one(s) load-balancer must be able to identify the backup servers to a database shared amongst all app server nodes slow, database quickly becomes bottleneck to a filesystem shared amongst all app server nodes (to the browser, via cookies or Bayeux) when to replicate state (scalability vs. correctness): when it has changed (before sending HTTP response) complete state or only changes; synchronous or asynchronous at regular intervals References: [4, 10, 15]

23 application server clustering (3/3) cluster management (including state replication) inevitably adds overhead, resulting in less than ideal scalability state replication requires resources CPU for serialising/de-serialising state RAM and/or disk space for the state itself and its transport form network bandwidth for replicating state only a shared-nothing architecture can scale linearly if scalability is of the essence, and (session) state has to be provided (as it usually must) then the only option is to sacrifice availability by not replicating session state removing the need for the most important feature of an application server cluster References: [4, 15]

24 availability through horizontal scalability Browser Browser Load Balancer Load Balancer Web App App Server 33.3% load Web App App Server 33.3% load Web App App Server 33.3% load Web App App Server 50% load Web App App Server 50% load Web App App Server 0% load DB DB References: [4, 15]

25 using HttpSession correctly (1/2) all session attributes must be Serializable call HttpSession. setattribute() after changing an attribute this allows you to rely on replication of changed state only keep overall session small keep each attribute small use HttpSession invalidate() and removeattribute() expect concurrent (multi-threaded) access to HttpSession and each session attribute! if using a web framework try to set synchronize on session mark web app as distributable to enable clustering web.xml: <distributable /> References: [16, 17]

26 using HttpSession correctly (2/2) final HttpSession session = req.getsession(); final Cart cart = getcart(session); cart.additem("#123", 2); // atomic/synchronized setcart(session, cart); // make change to cart explicit private Cart getcart(httpsession session) { Cart cart; synchronized (session) { cart = (Cart) session.getattribute("cart"); if (cart == null) { cart = new Cart(); setcart(session, cart); } } return cart; } private void setcart(httpsession session, Cart cart) { session.setattribute("cart", cart); // atomic/synchronized } References: [16, 17]

browser-server interaction beyond simple request-response

28 AJAX = Asynchronous JavaScript and XML a client-side web programming technique that makes web applications more dynamic JavaScript embedded in an HTML page (typically dynamically generated by a JSP) issues asynchronous HTTP/HTTPS requests (to the server from which it was loaded) which return XML (or JSON or similar). The response content is used to dynamically update the DOM of that HTML page (rather than load a new page). made possible by XMLHttpRequest object in JavaScript applications: auto-completion of entered text, on-the-fly form data validation, refreshing data; think Google References: [5, 7, 9, 14]

29 AJAX browser-server interaction HTML page JavaScript event handler XMLHttpRequest Server/Servlet trigger event create set HTTP method, URL set callback send JavaScript callback HTTP request XML/HTTP response call callback update DOM References: [5, 7, 9]

30 working with XMLHttpRequest in JavaScript var xhr; function sendrequest() { // extract request data from HTML page and (e.g.) pack into URL var field = document.getelementbyid( datafield ) var url = /autocomplete?data= + encodeuricomponent(field.value) xhr = new XMLHttpRequest() // browser-dependent! xhr.onreadystatechange = callback xhr.open( GET, url, true) // async GET request xhr.send(null) // no body in GET request, request data is in URL } function callback() { if (xhr.readystate == 4 && xhr.status == 200) { // update DOM based on xhr.responsetext or xhr.responsexml } } References: [5, 7, 9, 14]

31 using AJAX-enabled JSF components <ice:selectinputtext width="300" rows="#{bean.numcities}" value="#{bean.selectedcity}" valuechangelistener="#{bean.valuechanged}"> <f:selectitems value="#{bean.matchingcities}"/> </ice:selectinputtext> JavaServer Faces GUI components can be AJAX-enabled (-> ICEfaces) capitalizes on JSF technology base no JavaScript necessary #{} refers to server-side Java code in backing beans References: [2, 6]

32 AJAX web application characteristics rich internet applications (RIA), application on a page depart from request-response nature of traditional ( web 1.0 ) web applications many more requests, at higher frequency (1 per second?) roundtrip latency of proportionally higher importance high likelihood of concurrent requests for each user session typically smaller requests and responses especially if using JSON may make browser back button meaningless (yet again) AJAX requests must contain the user session identifier just like any other HTTP requests in general, AJAX requires more server-side resources References: [4]

33 JSON = JavaScript Object Notation a data-interchange format encoding unordered sets of name-value pairs and ordered lists of values, possibly nested, as JavaScript source code (object and array definitions) more concise than XML could (ignoring security!) be eval()-ed from JavaScript can be parsed and generated from any language References: [8, 9, 18]

34 JSON vs XML: XML <?xml version="1.0" encoding="utf-8"?> <web-app version="2.5"> <display-name>my Web App</display-name> <servlet> <servlet-name>faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.facesservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> </web-app> 439 bytes References: [8]

35 JSON vs XML: JSON { "web-app": { "version": "2.5", "display-name": "My Web App", "servlet": { "servlet-name": "Faces Servlet", "servlet-class": "javax.faces.webapp.facesservlet" }, "servlet-mapping": { "servlet-name": "Faces Servlet", "url-pattern": "/faces/*" } } } 291 bytes References: [8, 9, 18]

36 Comet aka AJAX push, server push a technique to push data from the server to the browser literally opening an HTTP request from the server to the browser would require a HTTP server running in the browser and fails because of numerous security restrictions typical implementation: AJAX with long polling 1. browser uses XMLHttpRequest to send request to server 2. server creates response only when there is data to be sent to the browser request may time out if this takes too long 3. after receiving response (or timeout) browser immediately opens next request...goto 1. References: [11, 13, 14]

37 Bayeux a nascent web-centric (asynchronous) messaging protocol designed primarily for HTTP/HTTPS messages are JSON objects messages sent to/received from named channels: publishsubscribe messaging message delivery client->server, server->client, client->browser client: any Bayeux-enabled HTTP client, e.g. JavaScript executing in a browser using e.g. dojo library defines a concrete, interoperable approach to Comet and more general messaging architectures implemented e.g. in Grizzly which is used in GlassFish v3 References: [10, 12, 13, 14]

38 asynchronous servlets (Servlet 3.0/Java EE 6) API to allow a servlet to suspend/resume request processing ServletRequest suspend(), resume(), complete() allows the app server to free the request processing thread until a response can be produced serve more web clients without increasing thread pool size should be used whenever a servlet can not produce a response immediately such as when waiting for the response to a SOAP request, a JMS response message or even a JDBC connection (to become available from a pool) essential for Comet (long polling) References: [16]

39 asynchronous servlet request processing (1/2) public class AsyncServlet extends HttpServlet { private MyResult getresult(httpservletrequest req) { return (MyResult) req.getattribute("result"); } private void setresult(httpservletrequest req, MyResult result) { req.setattribute("result", result); } @Override protected void doget(final HttpServletRequest req, HttpServletResponse resp) throws IOException { if (req.isinitial() getresult(req) == null) { processrequestasync(req); } else { respond(req, resp); } } References: [16]

40 asynchronous servlet request processing (2/2) private void processrequestasync(final HttpServletRequest req) { req.suspend(); final ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { public void run() { final MyResult result = longrunningrequesttoproduceresult(); setresult(req, result); req.resume(); executor.shutdown(); } }); } private void respond(httpservletrequest req, HttpServletResponse resp) throws IOException { final MyResult result = getresult(req); resp.setcontenttype("text/html"); final PrintWriter pw = resp.getwriter(); pw.println("<html><body>the result is " + result.getresult() + "</body></html>"); pw.close(); } } References: [16]

41 summary we have covered web applications and Java EE web applications, Java EE application servers, processing paradigms, important APIs availability and scalability of web applications definitions, horizontal and vertical scalability, load balancers, clustering, availability through redundancy, using HttpSession browser-server interaction beyond simple request-response AJAX and XMLHttpRequest, JSON, Comet, Bayeux, asynchronous servlet request processing for more detail see the references and bibliography! or attend Web Engineering II

http://www.gerald-loeffler.net/download/java_web_app_dev_2008-10-27.pdf Selected Topics in Java Web Application Development Dr Gerald Loeffler, MBA Web Engineering I WU Wien