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



Similar documents
Java Servlet 3.0. Rajiv Mordani Spec Lead

Piotr Nowicki's Homepage. Java EE 6 SCWCD Mock Exam. "Simplicity is the ultimate sophistication." Important!

SSC - Web applications and development Introduction and Java Servlet (II)

The Java EE 6 Platform. Alexis Moussine-Pouchkine GlassFish Team

Java Servlet Specification

Java EE 6 Ce qui vous attends

The Server.xml File. Containers APPENDIX A. The Server Container

Controlling Web Application Behavior

Web Applications. Originals of Slides and Source Code for Examples:

Managing Data on the World Wide-Web

Java and Web. WebWork

Web Applications. For live Java training, please see training courses at

Introduction to J2EE Web Technologies

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

Developing Web Applications using JavaServer Pages and Servlets

Java 2 Web Developer Certification Study Guide Natalie Levi

Model-View-Controller. and. Struts 2

Web Container Components Servlet JSP Tag Libraries

Java EE 6 New features in practice Part 3

Principles and Techniques of DBMS 5 Servlet

Ch-03 Web Applications

Servlet and JSP Filters

Creating Java EE Applications and Servlets with IntelliJ IDEA

CIS 455/555: Internet and Web Systems

Java Web Programming. Student Workbook

Web Frameworks and WebWork

Get Success in Passing Your Certification Exam at first attempt!

JWIG Yet Another Framework for Maintainable and Secure Web Applications

PowerTier Web Development Tools 4

ACM Crossroads Student Magazine The ACM's First Electronic Publication

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

Nicholas S. Williams. wrox. A Wiley Brand

What's new in Java EE 6? Antonio Goncalves

Bienvenue chez le Ch ti JUG!

How To Understand The Architecture Of Java 2Ee, J2Ee, And J2E (Java) In A Wordpress Blog Post

Course Name: Course in JSP Course Code: P5

Oracle Hyperion Financial Management Developer and Customization Guide

Web Application Programmer's Guide

The. Platform. Alexis Moussine-Pouchkine Antonio Goncalves

Oracle Hyperion Financial Management Custom Pages Development Guide

Java Servlet Tutorial. Java Servlet Tutorial

Exam Prep. Sun Certified Web Component Developer (SCWCD) for J2EE Platform

Selected Topics in Java Web Application Development

Outline. CS 112 Introduction to Programming. Recap: HTML/CSS/Javascript. Admin. Outline

CHAPTER 9: SERVLET AND JSP FILTERS

CONTROLLING WEB APPLICATION BEHAVIOR WITH

PA165 - Lab session - Web Presentation Layer

Università degli Studi di Napoli Federico II. Corsi di Laurea Specialistica in Ingegneria Informatica ed Ingegneria delle Telecomunicazioni

2. Follow the installation directions and install the server on ccc

INTRODUCTION TO WEB TECHNOLOGY

Web Application Architecture (based J2EE 1.4 Tutorial)

Web Development in Java Live Demonstrations (Live demonstrations done using Eclipse for Java EE 4.3 and WildFly 8)

OSGi Application Development using GlassFish Server. Version 1.5. By: Sanjeeb Sahoo

JAX-WS Developer's Guide

Web Service Development Using CXF. - Praveen Kumar Jayaram

Integration of Shibboleth and (Web) Applications

INSIDE SERVLETS. Server-Side Programming for the Java Platform. An Imprint of Addison Wesley Longman, Inc.

Glassfish, JAVA EE, Servlets, JSP, EJB

Struts 2 - Practical examples

Configure a SOAScheduler for a composite in SOA Suite 11g. By Robert Baumgartner, Senior Solution Architect ORACLE

Apache Sling A REST-based Web Application Framework Carsten Ziegeler cziegeler@apache.org ApacheCon NA 2014

Arjun V. Bala Page 20

Spring 3.1 to 3.2 in a Nutshell. Sam Brannen Senior Software Consultant

In this chapter, we lay the foundation for all our further discussions. We start

Running and Testing Java EE Applications in Embedded Mode with JupEEter Framework

Tomcat 5 New Features

Server Setup and Configuration

Application Security

Supporting Multi-tenancy Applications with Java EE

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

CS506 Web Design and Development Solved Online Quiz No. 01

ActiveVOS Server Architecture. March 2009

Supplement IV.E: Tutorial for Tomcat. For Introduction to Java Programming By Y. Daniel Liang

Please send your comments to:

WEB SERVICES. Revised 9/29/2015

Server-side OSGi with Apache Sling. Felix Meschberger Day Management AG 124

Web Applications and Struts 2

Keycloak SAML Client Adapter Reference Guide

Learning GlassFish for Tomcat Users

Complete Java Web Development

Pure server-side Web Applications with Java, JSP. Application Servers: the Essential Tool of Server-Side Programming. Install and Check Tomcat

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

Web Application Development

Development. with NetBeans 5.0. A Quick Start in Basic Web and Struts Applications. Geertjan Wielenga

JBoss Portlet Container. User Guide. Release 2.0

Java Server Pages combined with servlets in action. Generals. Java Servlets

Oracle EXAM - 1Z Java EE 6 Web Services Developer Certified Expert Exam. Buy Full Product.

Getting Started with Web Applications

In this chapter the concept of Servlets, not the entire Servlet specification, is

JBoss SOAP Web Services User Guide. Version: M5

Servlets. Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun

CQCON 2013: five Sling features you should know

JMS 2.0: Support for Multi-tenancy

Transcription:

Servlet 3.0 Alexis Moussine-Pouchkine 1

Overview Java Servlet 3.0 API JSR 315 20 members Good mix of representation from major Java EE vendors, web container developers and web framework authors 2

Overview Main areas of focus Ease of Development Extensibility Asynchronous support Security Final release available now as part of Java EE 6 and GlassFish v3 3

Ease of Development Enhance API using new language features in introduced since Java SE 5.0 Annotations for declarative style of programming Generics for type safety in API without breaking backwards compatibility Better defaults and convention over configuration 4

Ease of Development Annotations to declare Servlets, Filters, Listeners and Security constraints @WebServlet Defines a Servlet @WebFilter Defines a Filter @WebListener Defines a listener @WebInitParam Defines an init param @ServletSecurity security constraints @MultipartConfig file upload Use web.xml to override values 5

Ease of Development @WebServlet - For defining a Servlet MUST specify url mapping All other attributes optional with reasonable defaults For example, the default name of a Servlet is the fully qualified class name Must still extend HttpServlet to derive method contracts for doget, dopost and other methods

Ease of Development Servlet 2.5 example /* Code in Java Class */ package com.foo; public class MyServlet extends HttpServlet { public void doget (HttpServletRequest req, HttpServletResponse res) {... }... } <!--Deployment descriptor web.xml --> <web-app> <servlet> <servlet-name>myservlet </servlet-name> <servlet-class> com.foo.myservlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>myservlet </servlet-name> <url-pattern>/myapp/* </url-pattern> </servlet-mapping>... </web-app> 7

Ease of Development package com.foo; @WebServlet(name="MyServlet", urlpattern="/myapp/*") public class MyServlet extends HttpServlet {! public void doget(httpservletrequest req,!!!!! HttpServletResponse res) {!!... }! 8

Extensibility Enable use of frameworks without boiler plate configuration in deployment descriptors Put the burden on framework developer Dynamic registration of Servlets and Filters using programmatic configuration APIs Modularize web.xml to allow frameworks to be self-contained Use of annotations enables extensibility as well 9

Extensibility web-fragment.xml partial web.xml Bundled in framework jar file in META-INF directory Container discovers and assembles the effective descriptor Almost identical to web.xml a few ordering related elements are different Only JAR files in WEB-INF/lib are considered 10

Extensibility <web-fragment> <servlet> <servlet-name>welcome</servlet-name> <servlet-class> WelcomeServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>welcome</servlet-name> <url-pattern>/welcome</url-pattern> </servlet-mapping>... </web-fragment> 11

metadata-complete The spontaneous assembly of fragments can be scary to some If metadata-complete is set to "true", the deployment tool must ignore any annotations that specify deployment information If metadata-complete is not specified or is set to "false", the deployment tool must examine the class files of the application for annotations 12

Programmatic Registration and lookup ServletRegistration.Dynamic dynamic = servletcontext.addservlet ("DynamicServlet","com.mycom.MyServlet"); dynamic.addmapping("/dynamicservlet"); dynamic.setasyncsupported(true); ServletRegistration declared = servletcontext.getservletregistration ("DeclaredServlet"); declared.addmapping("/declaredservlet"); declared.setinitparameter("param", "value"); 13

ServletContainerInitializer Provided by apps or the container Discovered using the service provider API in the Java runtime Expresses interest in classes via @HandlesTypes Container scans webapp for classes that match @HandlesTypes and passes them to the ServletContainerInitializer, along with ServletContext 14

Resource JARs WEB-INF/lib/{*.jar}/META-INF/resources Modular web applications static content Images, CSS, JavaScript (think dojo, jquery,...) a JAR placed in WEB-INF/lib has static content from its META-INF/resource directory served from the application webcontext root : WEB-INF/lib/pictures.jar/META-INF/resources/foo.png WEB-INF/lib/styles.jar/META-INF/resources/foo.css WEB-INF/lib/scripts.jar/META-INF/resources/foo.js http://host:port/webcontext/foo.png http://host:port/webcontext/foo.css http://host:port/webcontext/foo.js 15

Asynchronous Support Useful for Comet, long waits Must declare @WebServlet (asyncsupported=true) Then Call AsyncContext ctx = ServletRequest.startAsync(req, res) AsyncContext can then either: dispatch(string path) start(runnable action) Then paired with complete() 16

Asynchronous API ServletRequest ServletRequest.isAsyncSupported() > True if ALL [Filter Servlet]s support async in The Filter chain The Request dispatch chain Can be configured > web.xml > Annotation > API 17

Asynchronous API ServletRequest AsyncContext ServletRequest.startAsync > Called by Servlet Filter > Response not committed on return of Service method Filter chain 18

Asynchronous API AsyncContext AsyncContext.dispatch > Called by asynchronous handler > Schedule async dispatch DispatcherType.ASYNC > Response generated by [Servlet Filter] using Container thread pool JSP, JSF or other frameworks 19

Asynchronous API AsyncContext AsyncContext.complete > Called by asynchronous handler or container > Signals Response has been generated 20

Asynchronous servlet @WebServlet(asyncSupported=true, urlpatterns={"/myapp"}) public class MyServlet extends HttpServlet { } public void doget (HttpServletRequest req, HttpServletResponse res){... AsyncContext ctx = req.startasync();... } 21

ChatServlet (1/2) import javax.servlet.asynccontext; import javax.servlet.asyncevent; import javax.servlet.asynclistener; Queue<AsyncContext> queue; BlockingQueue<String> messagequeue;... @WebServlet(urlPatterns = {"/chat"}, asyncsupported = true) public class ChatServlet extends HttpServlet { doget(...) { AsyncContext ac = req.startasync(); ac.settimeout(10 * 60 * 1000); ac.addlistener(new AsyncListener() { public void oncomplete(asyncevent event) { queue.remove(ac); }... }); queue.add(ac); }... 22

ChatServlet (2/2) init(...) { while (true) { String message = messagequeue.take(); for (AsyncContext ac : queue) { PrintWriter acwriter = ac.getresponse().getwriter(); acwriter.println(message); } } } dopost(...) { String action = req.getparameter("action"); String name = req.getparameter("name"); String message = req.getparameter("message"); if ("login".equals(action)) { messagequeue.put(name + " has joined."); } else if ("post".equals(action)) { messagequeue.put(message); } 23

Security Programmatic login / logout Support for programmatic authentication, login and logout > HttpServletRequest.authenticate > HttpservletRequest.login > HttpServletRequest.logout Annotations for declaring http constraints for resources > @ServletSecurity 24

Servlet 3.0 Annotations for ease of development Optional web.xml Better defaults Web Framework pluggability Asynchronous Processing Security enhancements 25

Q & A Alexis.Moussine-Pouchkine@Oracle.COM 26