SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
1
<Insert Picture Here>




Servlet 3.0, Asynchronous, Easy extensible

Rajiv Mordani
rajiv.mordani@oracle.com
The following is intended to outline our general product
direction. It is intended for information purposes only,
and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality,
and should not be relied upon in making purchasing
decisions.
The development, release, and timing of any features or
functionality described for Oracle’s products remains at the
sole discretion of Oracle.


                                                               3
Agenda


•   Overview
•   Ease of Development
•   Dynamic registration
•   Pluggability
•   Asynchronous Support
•   Security Enhancements
•   Miscellaneous


                            4
Overview


• Final release done in December 2009.
• ~20 members in the expert group
   – Good mix of representation from major Java EE
     vendors, open source web container developers and
     framework authors
• Main areas of focus
   – Ease of Development
   – Pluggability
   – Asynchronous support
   – Security                                            5
Ease of Development


• Focus on Ease of Development in the Servlet 3.0 API
• Enhanced APIs to use new Java SE language features
  introduced since J2SE 5.0
• Annotations for declarative style of programming
   – web.xml optional
• Generics for type safety in API where possible
• Better defaults
• Convention over configuration

                                                        6
Ease of Development
Use of annotations

• Annotations to declare Servlets, Filters, Listeners and
  servlet security
   – @WebServlet – Define a Servlet
   – @WebFilter - Define a Filter
   – @WebListener – Define a Listener
   – @WebInitParam – Define init param
   – @MultipartConfig – Define file upload properties
   – @ServletSecurity – Define security constraints
• Can use web.xml to override values specified in
  annotations                                               7
Ease of Development
Use of annotations (contd)

• @WebServlet for defining a Servlet
   – Annotations MUST have at a minimum a URL pattern
     for the Servlet
   – All other attributes optional with reasonable defaults
   – For example, the default name of the Servlet is the
     fully qualified class name
   – Class MUST still extend HttpServlet
   – Method contracts for doGet, doPost (and others)
     derived from HttpServlet
                                                              8
Servlet 2.5 example
At least 2 files

<!--Deployment         /* Code in Java Class
 descriptor web.xml    */
 -->
<web-app>              package com.sun;
 <servlet>             public           clas s
   <servlet-           MyServlet     extend s
 name>MyServlet        HttpServlet
          </servlet-   {
name>                      public void
       <servlet-
class>                 doGet(HttpServletRequ
                                                 9
Servlet 3.0 example


@WebServlet(“/foo”)
public class SimpleSample extends
HttpServlet
{
    public void doGet(HttpServletRequest
              req,HttpServletResponse res)
    {

    }
}                                            10
Servlet 3.0 example


@WebServlet(urlPatterns=“/foo”,
name=”MyServlet”, asyncSupported=true)
public class SimpleSample extends
HttpServlet
{
    public void doGet(HttpServletRequest
              req,HttpServletResponse res)
    {

    }                                        11
Dynamic Registration
Register

• Performed during ServletContext initialization
• ServletContext#add[Servlet | Filter]
   – Overloaded versions take [Servlet | Filter] name and
      • Fully qualified [Servlet | Filter] class name or
      • Class <? extends [Servlet | Filter]> or
      • [Servlet | Filter] instance
   – User returned Registration handle to configure all
     aspects of [Servlet | Filter]

                                                            12
Dynamic Registration
Create and register

• ServletContext#create[Servlet | Filter]
   – Takes Class<? Extends [Servlet | Filter]>
     argument
   – Supports resource injection by container
   – Returned [Servlet | Filter] instance may be fully
     customized before it is registered via the
      • ServletContext.add[Servlet | Filter]
        methods


                                                         13
Dynamic Registration
Lookup

• ServletContext#get[Servlet |
  Filter]Registration
   – Takes [Servlet | Filter] name as argument
   – Returned Registration handle provides subset of
     configuration methods
   – May only be used to add initialization parameters and
     mappings
   – Conflict returned as
      • java.util.Set

                                                             14
Dynamic Registration
Register example

ServletRegistration.Dynamic dynamic =
    servletContext.addServlet(
        "DynamicServlet",
        "com.mycom.MyServlet");
dynamic.addMapping("/dynamicServlet");
dynamic.setAsyncSupported(true);




                                         15
Dynamic Registration
Lookup example

ServletRegistration declared =
servletContext.getServletRegistration("Decl
aredServlet");
declared.addMapping("/declaredServlet");
declared.setInitParameter("param",
"value");




                                              16
Pluggability


• Enable use of libraries and framework without boiler
  plate configuration in deployment descriptors
   – Put the burden on the framework developer
• Modularize web.xml to allow frameworks to be self-
  contained within their own JAR file
• Programmatic configuration APIs
• Use of annotations



                                                         17
Pluggability
Motivation for web.xml modularization

• Use of framework requires (possibly complex)
  configuration in web.xml
• For example
   – Declare a controller Servlet
   – Logging and security Filters
   – Declare Listeners to perform actions at various points
     in the lifecycle of the application
• Can get complex as dependencies increase
• Frameworks also need to document all the configuration
  that needs to be done                                       18
Pluggability
web-fragment.xml

• web-fragment.xml is descriptor for framework / library
• Included in META-INF directory
• Container responsible for discovering fragments and
  assembling the effective deployment descriptor
• Almost identical to web.xml
   – Ordering related elements different
• Only JAR files in WEB-INF/lib considered as
  fragments


                                                           19
Pluggability
web-fragment.xml

<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>
                                           20
Pluggability
Ordering

• Compatible with JavaServer™ Faces
• Fragments identified by <name>
• web.xml may declare absolute ordering of fragments
  via <absolute-ordering>
• Fragments may declare ordering preferences relative to
  other fragments via <ordering> with nested <before>
  and <after>
   – Ignored if <absolute-ordering> specified
• Special <others/> element moves fragment to
  beginning or end of list of sorted fragments
                                                           21
Pluggability
Shared libraries

• Support plugging in of container installed JAR files
   – Examples: JSF, JAX-WS, Spring
• Libraries may provide implementation of
  ServletContainerInitializer
• Looked up via the JAR Services API in JDK 6
• Invoked before any Listeners during the initialization of
  the application



                                                              22
Pluggability
Shared libraries (contd)

• ServletContainerInitializer expresses interest
  in Classes via @HandlesTypes
• Container discovers classes that match
  @HandlesTypes and passes them to
  ServletContainerInitializer
• ServletContainerInitializer inspects passed in
  Classes and may register Servlets and Filters based on
  them


                                                           23
Pluggability
ServletContainerInitializer example

@HandlesTypes(WebService.class)
public class JAXWSInitializer implements
ServletContainerInitializer {
  public void onStartup(Set<Class<?>> c,
                        ServletContext ctx)
  {
    ctx.addServlet(“JAXWSServlet”,
             “com.sun.jaxws.JAXWSServlet”);

   }
                                              24
Pluggability
Resource sharing

• Static and JavaServer™ Pages (JSP) resources no
  longer confined to web application's document root
• May be placed inside WEB-INF/lib/[*.jar]/META-
  INF/resources
• Container must honor this new location when processing
  HTTP requests and calls to
  ServletContext#getResource[AsStream]
• Resources in document root take precedence over those
  in bundled JAR files

                                                           25
Pluggability
Resource sharing example

mywebapp.war packaging:
 /index.jsp
 /WEB-INF/lib/shared.jar!/META-
INF/resources/shared.jsp
Request for:
http://localhost:8080/mywebapp/shared.jsp
will be served from:
/path/to/mywebapp/WEB-
INF/lib/shared.jar!/META-
INF/resources/shared.jsp                    26
Why Asynchronous Servlets?


• Async Servlets are for:
  – Waiting for resources (eg JDBC connection)
  – Waiting for events (eg Chat)
  – Waiting for responses (eg web services)
• Not for Async IO!
  – Requests mostly small (single packet)
  – Hard to asynchronously produce large responses
  – Async IO support waiting for NIO2

                                                     27
Blocking waiting consumes resources


• Web Application using remote web services
  – Handling 1000 requests / sec
  – 50% requests call remote web service
  – 500 threads in container thread pool

• If remote web service is slow (1000ms)
   – Thread starvation in 1 second!
   – 50% of requests use all 500 threads

                                              28
Asynchronous API
Enable asynchronous support

• ServletRequest#isAsyncSupported()
   – True if ALL [Filter|Servlet]s support async in
      • the Filter chain
      • the RequestDispatch chain
• Configured in
   – web.xml
      • <async-supported>true</async-
        supported>
   – With annotation
      • @WebServlet(asyncSupported=true)              29
Asynchronous API
Start asynchronous processing

• AsyncContext ServletRequest#startAsync()
   – Called by [Filter|Servlet]
   – Response is NOT commited on return of:
     • Servlet.service(request,response)
     • Filter chain
• AsyncContext ServletRequest#startAsync
                                (ServletRequest
  req,
                                 ServletResponse
  res)
                                                   30
Asynchronous API
AsyncContext

• AsyncContext#dispatch()
   – Called by your asynchronous handler
   – Schedule async dispatch:DispatcherType.ASYNC
   – Response generated by [Filter|Servlet] using:
     • container thread pool
     • JSP, JSF or other frameworks usable
     • JNDI, JTA, EJBs usable

• AsyncContext#dispatch(String path)
   – Variation to async dispatch to specific Servlet   31
Asynchronous API
AsyncContext (contd)

• AsyncContext#complete()
   – Called by your asynchronous handler
   – Signals Response has been generated
     • without [Filter|Servlet] dispatch
     • without Servlet features
     • Or with AsyncContext#start(Runnable r)




                                                32
Asynchronous API usage styles


• startAsync()                  … dispatch()
   – Retry request after async wait
   – Filters re-applied if on DispatcherType.ASYNC

• startAsync()                … dispatch(path)
   – Use specific Servlet handling after async wait

• startAsync()             … complete()
   – Generate response asynchronously
                                                      33
Asynchronous API usage styles


• startAsync(req,res) … dispatch()
   – Retry request after async wait
   – Wrappers are kept
   – RequestDispatcher#forward target used

• startAsync(req,res) … dispatch(path)
   – Specific Servlet handling after async wait

• startAsync(req,res) … complete()
   – Generate wrapped response asynchronously     34
Asynchronous API
Timeout

• Timeouts
   – AsyncContext#setAsyncTimeout(long ms)
   – By default error dispatch on timeout

• Listeners
   – AsyncListener#OnTimeout
   – AsyncListener#OnComplete



                                             35
Security
Annotations to define security constraints

• @ServletSecurity used to define access control
  constraints
• Can specify constraint for all HTTP methods via the
  @HttpConstraint
• Or specify constraint for specific HTTP methods via the
  @HttpMethodConstraint
• If both specified in the @ServletSecurity, the
  @HttpConstraint applies to those methods not
  specifically specified via the @HttpMethodConstraint

                                                            36
Security
Example

@ServletSecurity((httpMethodConstraints = {
@HttpMethodConstraint(value = "GET",
rolesAllowed = "R1"),
@HttpMethodConstraint(value = "POST",
rolesAllowed = "R1",
transportGuarantee =
TransportGuarantee.CONFIDENTIAL)
})
public class Example5 extends HttpServlet {
}                                             37
Security
Programmatic container authentication and logout

• HttpServletRequest#login(String username,
  String password)
   – Replacement for FBL
   – Application supervises credential collection
• HttpServletRequest#authenticate(HttpServle
  tResponse)
   – Application initiates container mediated authentication
     from a resource that is not covered by any
     authentication constraints
   – Application decides when authentication must occur
                                                               38
Security
Programmatic container authentication and logout

• Integration of additional container authentication
  modules via Servlet Profile of JSR 196 recommended
• HttpServletRequest#logout




                                                       39
Miscellaneous Features / API enhancements


• Session tracking cookie configuration
  – Via web.xml
  – Programmatic via
    javax.servlet.SessionCookieConfig
• Support for HttpOnly cookie attribute
  – Example:
    servletContext.getSessionCookieConfig().
    setHttpOnly(true)
• Default error page
                                               40
Miscellaneous Features / API enhancements (contd)


• ServletRequest#getServletContext
• ServletRequest#getDispatcherType
• Servlet[Request|
  Response]Wrapper#isWrapperFor
• HttpServletResponse#getStatus
• HttpServletResponse#getHeader
• HttpServletResponse#getHeaders
• HttpServletResponse#getHeaderNames

                                                    41
Miscellaneous Features / API (contd)
File upload

•   ServletRequest#getParts
•   ServletRequest#getPart
•   @MultipartConfig
•   Changes to web.xml




                                       42
Summary


• Major revision since Servlet 2.4
• Comprehensive set of new features enable modern style
  of web applications and greatly increases developer
  productivity
• Simplifies assembly of large applications from reusable
  components




                                                            43
Resources


• http://jcp.org/en/jsr/summary?id=315
• https://glassfish.dev.java.net
• http://java.sun.com/javaee




                                         44
Q&A




      45
<Insert Picture Here>




Servlet 3.0, Asynchronous, Easy extensible

Rajiv Mordani
rajiv.mordani@oracle.com

Contenu connexe

Tendances

Learn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c AdministrationLearn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c AdministrationRevelation Technologies
 
Weblogic 11g admin basic with screencast
Weblogic 11g admin basic with screencastWeblogic 11g admin basic with screencast
Weblogic 11g admin basic with screencastRajiv Gupta
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
Weblogic Administration Managed Server migration
Weblogic Administration Managed Server migrationWeblogic Administration Managed Server migration
Weblogic Administration Managed Server migrationRakesh Gujjarlapudi
 
Oracle WebLogic Server Basic Concepts
Oracle WebLogic Server Basic ConceptsOracle WebLogic Server Basic Concepts
Oracle WebLogic Server Basic ConceptsJames Bayer
 
Oracle WebLogic: Feature Timeline from WLS9 to WLS 12c
Oracle WebLogic: Feature Timeline from WLS9 to WLS 12cOracle WebLogic: Feature Timeline from WLS9 to WLS 12c
Oracle WebLogic: Feature Timeline from WLS9 to WLS 12cfrankmunz
 
Introduction to java servlet 3.0 api javaone 2008
Introduction to java servlet 3.0 api javaone 2008Introduction to java servlet 3.0 api javaone 2008
Introduction to java servlet 3.0 api javaone 2008JavaEE Trainers
 
Coherence sig-nfr-web-tier-scaling-using-coherence-web
Coherence sig-nfr-web-tier-scaling-using-coherence-webCoherence sig-nfr-web-tier-scaling-using-coherence-web
Coherence sig-nfr-web-tier-scaling-using-coherence-webC2B2 Consulting
 
WebLogic Administration course outline
WebLogic Administration course outlineWebLogic Administration course outline
WebLogic Administration course outlineVybhava Technologies
 
Weblogic server administration
Weblogic server administrationWeblogic server administration
Weblogic server administrationbispsolutions
 
Oracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningOracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningMichel Schildmeijer
 
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...J V
 
Tomcat Optimisation & Performance Tuning
Tomcat Optimisation & Performance TuningTomcat Optimisation & Performance Tuning
Tomcat Optimisation & Performance Tuninglovingprince58
 
Advanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availabilityAdvanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availabilityBordin Kijsirijareonchai
 
WebLogic Deployment Plan Example
WebLogic Deployment Plan ExampleWebLogic Deployment Plan Example
WebLogic Deployment Plan ExampleJames Bayer
 

Tendances (20)

Learn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c AdministrationLearn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c Administration
 
Tomcatx performance-tuning
Tomcatx performance-tuningTomcatx performance-tuning
Tomcatx performance-tuning
 
Weblogic 11g admin basic with screencast
Weblogic 11g admin basic with screencastWeblogic 11g admin basic with screencast
Weblogic 11g admin basic with screencast
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Weblogic Administration Managed Server migration
Weblogic Administration Managed Server migrationWeblogic Administration Managed Server migration
Weblogic Administration Managed Server migration
 
Oracle WebLogic Server Basic Concepts
Oracle WebLogic Server Basic ConceptsOracle WebLogic Server Basic Concepts
Oracle WebLogic Server Basic Concepts
 
Oracle WebLogic 11g Topology
Oracle WebLogic 11g TopologyOracle WebLogic 11g Topology
Oracle WebLogic 11g Topology
 
Oracle WebLogic: Feature Timeline from WLS9 to WLS 12c
Oracle WebLogic: Feature Timeline from WLS9 to WLS 12cOracle WebLogic: Feature Timeline from WLS9 to WLS 12c
Oracle WebLogic: Feature Timeline from WLS9 to WLS 12c
 
Introduction to java servlet 3.0 api javaone 2008
Introduction to java servlet 3.0 api javaone 2008Introduction to java servlet 3.0 api javaone 2008
Introduction to java servlet 3.0 api javaone 2008
 
Coherence sig-nfr-web-tier-scaling-using-coherence-web
Coherence sig-nfr-web-tier-scaling-using-coherence-webCoherence sig-nfr-web-tier-scaling-using-coherence-web
Coherence sig-nfr-web-tier-scaling-using-coherence-web
 
WebLogic Administration course outline
WebLogic Administration course outlineWebLogic Administration course outline
WebLogic Administration course outline
 
Weblogic server administration
Weblogic server administrationWeblogic server administration
Weblogic server administration
 
WebLogic FAQs
WebLogic FAQsWebLogic FAQs
WebLogic FAQs
 
Oracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningOracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuning
 
Java EE 8
Java EE 8Java EE 8
Java EE 8
 
WLS
WLSWLS
WLS
 
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
 
Tomcat Optimisation & Performance Tuning
Tomcat Optimisation & Performance TuningTomcat Optimisation & Performance Tuning
Tomcat Optimisation & Performance Tuning
 
Advanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availabilityAdvanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availability
 
WebLogic Deployment Plan Example
WebLogic Deployment Plan ExampleWebLogic Deployment Plan Example
WebLogic Deployment Plan Example
 

En vedette

Sarah grier passport1
Sarah grier passport1Sarah grier passport1
Sarah grier passport1Janet Painter
 
Cregg Laws having+what+it+takes
Cregg Laws having+what+it+takesCregg Laws having+what+it+takes
Cregg Laws having+what+it+takesJanet Painter
 
Alex global+education
Alex global+educationAlex global+education
Alex global+educationJanet Painter
 
Healthcare Reform Seminar May 2010
Healthcare Reform Seminar May 2010Healthcare Reform Seminar May 2010
Healthcare Reform Seminar May 2010cliff_rudolph
 
leadership beyond words-nspra
leadership beyond words-nspraleadership beyond words-nspra
leadership beyond words-nspraBrianWoodland
 
JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0Arun Gupta
 

En vedette (7)

Sarah grier passport1
Sarah grier passport1Sarah grier passport1
Sarah grier passport1
 
Cregg Laws having+what+it+takes
Cregg Laws having+what+it+takesCregg Laws having+what+it+takes
Cregg Laws having+what+it+takes
 
Power Csba
Power CsbaPower Csba
Power Csba
 
Alex global+education
Alex global+educationAlex global+education
Alex global+education
 
Healthcare Reform Seminar May 2010
Healthcare Reform Seminar May 2010Healthcare Reform Seminar May 2010
Healthcare Reform Seminar May 2010
 
leadership beyond words-nspra
leadership beyond words-nspraleadership beyond words-nspra
leadership beyond words-nspra
 
JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0JavaOne India 2011 - Servlets 3.0
JavaOne India 2011 - Servlets 3.0
 

Similaire à Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010

Introduction to java servlet 3.0 api javaone 2009
Introduction to java servlet 3.0 api javaone 2009Introduction to java servlet 3.0 api javaone 2009
Introduction to java servlet 3.0 api javaone 2009JavaEE Trainers
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Arun Gupta
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technologyMinal Maniar
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsitricks
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsitricks
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servletssbd6985
 
ADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet TechnologyADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet TechnologyRiza Nurman
 
Java Servlets
Java ServletsJava Servlets
Java ServletsNitin Pai
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSPGary Yeh
 
Introduction tomcat7 servlet3
Introduction tomcat7 servlet3Introduction tomcat7 servlet3
Introduction tomcat7 servlet3JavaEE Trainers
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteTushar B Kute
 
Servlets Java Slides & Presentation
Servlets Java Slides & Presentation Servlets Java Slides & Presentation
Servlets Java Slides & Presentation Anas Sa
 
Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Rajesh Moorjani
 

Similaire à Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010 (20)

Introduction to java servlet 3.0 api javaone 2009
Introduction to java servlet 3.0 api javaone 2009Introduction to java servlet 3.0 api javaone 2009
Introduction to java servlet 3.0 api javaone 2009
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Servlets
ServletsServlets
Servlets
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
ADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet TechnologyADP - Chapter 2 Exploring the java Servlet Technology
ADP - Chapter 2 Exploring the java Servlet Technology
 
Servlets
ServletsServlets
Servlets
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
 
Introduction tomcat7 servlet3
Introduction tomcat7 servlet3Introduction tomcat7 servlet3
Introduction tomcat7 servlet3
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
 
19servlets
19servlets19servlets
19servlets
 
Servlets
ServletsServlets
Servlets
 
Servlets Java Slides & Presentation
Servlets Java Slides & Presentation Servlets Java Slides & Presentation
Servlets Java Slides & Presentation
 
Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00Jeetrainers.com coursejspservlets00
Jeetrainers.com coursejspservlets00
 

Plus de Arun Gupta

5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdfArun Gupta
 
Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019Arun Gupta
 
Machine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and KubernetesMachine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and KubernetesArun Gupta
 
Secure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using FirecrackerSecure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using FirecrackerArun Gupta
 
Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019Arun Gupta
 
Why Amazon Cares about Open Source
Why Amazon Cares about Open SourceWhy Amazon Cares about Open Source
Why Amazon Cares about Open SourceArun Gupta
 
Machine learning using Kubernetes
Machine learning using KubernetesMachine learning using Kubernetes
Machine learning using KubernetesArun Gupta
 
Building Cloud Native Applications
Building Cloud Native ApplicationsBuilding Cloud Native Applications
Building Cloud Native ApplicationsArun Gupta
 
Chaos Engineering with Kubernetes
Chaos Engineering with KubernetesChaos Engineering with Kubernetes
Chaos Engineering with KubernetesArun Gupta
 
How to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAMHow to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAMArun Gupta
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Arun Gupta
 
The Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteThe Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteArun Gupta
 
Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018Arun Gupta
 
Mastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv SummitMastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv SummitArun Gupta
 
Top 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's LandscapeTop 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's LandscapeArun Gupta
 
Container Landscape in 2017
Container Landscape in 2017Container Landscape in 2017
Container Landscape in 2017Arun Gupta
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftArun Gupta
 
Docker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersDocker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersArun Gupta
 
Thanks Managers!
Thanks Managers!Thanks Managers!
Thanks Managers!Arun Gupta
 
Migrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersMigrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersArun Gupta
 

Plus de Arun Gupta (20)

5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf
 
Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019
 
Machine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and KubernetesMachine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and Kubernetes
 
Secure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using FirecrackerSecure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using Firecracker
 
Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019
 
Why Amazon Cares about Open Source
Why Amazon Cares about Open SourceWhy Amazon Cares about Open Source
Why Amazon Cares about Open Source
 
Machine learning using Kubernetes
Machine learning using KubernetesMachine learning using Kubernetes
Machine learning using Kubernetes
 
Building Cloud Native Applications
Building Cloud Native ApplicationsBuilding Cloud Native Applications
Building Cloud Native Applications
 
Chaos Engineering with Kubernetes
Chaos Engineering with KubernetesChaos Engineering with Kubernetes
Chaos Engineering with Kubernetes
 
How to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAMHow to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAM
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
The Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteThe Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 Keynote
 
Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018
 
Mastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv SummitMastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv Summit
 
Top 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's LandscapeTop 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's Landscape
 
Container Landscape in 2017
Container Landscape in 2017Container Landscape in 2017
Container Landscape in 2017
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShift
 
Docker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersDocker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developers
 
Thanks Managers!
Thanks Managers!Thanks Managers!
Thanks Managers!
 
Migrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersMigrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to Containers
 

Dernier

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 

Dernier (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 

Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010

  • 1. 1
  • 2. <Insert Picture Here> Servlet 3.0, Asynchronous, Easy extensible Rajiv Mordani rajiv.mordani@oracle.com
  • 3. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 3
  • 4. Agenda • Overview • Ease of Development • Dynamic registration • Pluggability • Asynchronous Support • Security Enhancements • Miscellaneous 4
  • 5. Overview • Final release done in December 2009. • ~20 members in the expert group – Good mix of representation from major Java EE vendors, open source web container developers and framework authors • Main areas of focus – Ease of Development – Pluggability – Asynchronous support – Security 5
  • 6. Ease of Development • Focus on Ease of Development in the Servlet 3.0 API • Enhanced APIs to use new Java SE language features introduced since J2SE 5.0 • Annotations for declarative style of programming – web.xml optional • Generics for type safety in API where possible • Better defaults • Convention over configuration 6
  • 7. Ease of Development Use of annotations • Annotations to declare Servlets, Filters, Listeners and servlet security – @WebServlet – Define a Servlet – @WebFilter - Define a Filter – @WebListener – Define a Listener – @WebInitParam – Define init param – @MultipartConfig – Define file upload properties – @ServletSecurity – Define security constraints • Can use web.xml to override values specified in annotations 7
  • 8. Ease of Development Use of annotations (contd) • @WebServlet for defining a Servlet – Annotations MUST have at a minimum a URL pattern for the Servlet – All other attributes optional with reasonable defaults – For example, the default name of the Servlet is the fully qualified class name – Class MUST still extend HttpServlet – Method contracts for doGet, doPost (and others) derived from HttpServlet 8
  • 9. Servlet 2.5 example At least 2 files <!--Deployment /* Code in Java Class descriptor web.xml */ --> <web-app> package com.sun; <servlet> public clas s <servlet- MyServlet extend s name>MyServlet HttpServlet </servlet- { name> public void <servlet- class> doGet(HttpServletRequ 9
  • 10. Servlet 3.0 example @WebServlet(“/foo”) public class SimpleSample extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res) { } } 10
  • 11. Servlet 3.0 example @WebServlet(urlPatterns=“/foo”, name=”MyServlet”, asyncSupported=true) public class SimpleSample extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res) { } 11
  • 12. Dynamic Registration Register • Performed during ServletContext initialization • ServletContext#add[Servlet | Filter] – Overloaded versions take [Servlet | Filter] name and • Fully qualified [Servlet | Filter] class name or • Class <? extends [Servlet | Filter]> or • [Servlet | Filter] instance – User returned Registration handle to configure all aspects of [Servlet | Filter] 12
  • 13. Dynamic Registration Create and register • ServletContext#create[Servlet | Filter] – Takes Class<? Extends [Servlet | Filter]> argument – Supports resource injection by container – Returned [Servlet | Filter] instance may be fully customized before it is registered via the • ServletContext.add[Servlet | Filter] methods 13
  • 14. Dynamic Registration Lookup • ServletContext#get[Servlet | Filter]Registration – Takes [Servlet | Filter] name as argument – Returned Registration handle provides subset of configuration methods – May only be used to add initialization parameters and mappings – Conflict returned as • java.util.Set 14
  • 15. Dynamic Registration Register example ServletRegistration.Dynamic dynamic = servletContext.addServlet( "DynamicServlet", "com.mycom.MyServlet"); dynamic.addMapping("/dynamicServlet"); dynamic.setAsyncSupported(true); 15
  • 16. Dynamic Registration Lookup example ServletRegistration declared = servletContext.getServletRegistration("Decl aredServlet"); declared.addMapping("/declaredServlet"); declared.setInitParameter("param", "value"); 16
  • 17. Pluggability • Enable use of libraries and framework without boiler plate configuration in deployment descriptors – Put the burden on the framework developer • Modularize web.xml to allow frameworks to be self- contained within their own JAR file • Programmatic configuration APIs • Use of annotations 17
  • 18. Pluggability Motivation for web.xml modularization • Use of framework requires (possibly complex) configuration in web.xml • For example – Declare a controller Servlet – Logging and security Filters – Declare Listeners to perform actions at various points in the lifecycle of the application • Can get complex as dependencies increase • Frameworks also need to document all the configuration that needs to be done 18
  • 19. Pluggability web-fragment.xml • web-fragment.xml is descriptor for framework / library • Included in META-INF directory • Container responsible for discovering fragments and assembling the effective deployment descriptor • Almost identical to web.xml – Ordering related elements different • Only JAR files in WEB-INF/lib considered as fragments 19
  • 20. Pluggability web-fragment.xml <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> 20
  • 21. Pluggability Ordering • Compatible with JavaServer™ Faces • Fragments identified by <name> • web.xml may declare absolute ordering of fragments via <absolute-ordering> • Fragments may declare ordering preferences relative to other fragments via <ordering> with nested <before> and <after> – Ignored if <absolute-ordering> specified • Special <others/> element moves fragment to beginning or end of list of sorted fragments 21
  • 22. Pluggability Shared libraries • Support plugging in of container installed JAR files – Examples: JSF, JAX-WS, Spring • Libraries may provide implementation of ServletContainerInitializer • Looked up via the JAR Services API in JDK 6 • Invoked before any Listeners during the initialization of the application 22
  • 23. Pluggability Shared libraries (contd) • ServletContainerInitializer expresses interest in Classes via @HandlesTypes • Container discovers classes that match @HandlesTypes and passes them to ServletContainerInitializer • ServletContainerInitializer inspects passed in Classes and may register Servlets and Filters based on them 23
  • 24. Pluggability ServletContainerInitializer example @HandlesTypes(WebService.class) public class JAXWSInitializer implements ServletContainerInitializer { public void onStartup(Set<Class<?>> c, ServletContext ctx) { ctx.addServlet(“JAXWSServlet”, “com.sun.jaxws.JAXWSServlet”); } 24
  • 25. Pluggability Resource sharing • Static and JavaServer™ Pages (JSP) resources no longer confined to web application's document root • May be placed inside WEB-INF/lib/[*.jar]/META- INF/resources • Container must honor this new location when processing HTTP requests and calls to ServletContext#getResource[AsStream] • Resources in document root take precedence over those in bundled JAR files 25
  • 26. Pluggability Resource sharing example mywebapp.war packaging: /index.jsp /WEB-INF/lib/shared.jar!/META- INF/resources/shared.jsp Request for: http://localhost:8080/mywebapp/shared.jsp will be served from: /path/to/mywebapp/WEB- INF/lib/shared.jar!/META- INF/resources/shared.jsp 26
  • 27. Why Asynchronous Servlets? • Async Servlets are for: – Waiting for resources (eg JDBC connection) – Waiting for events (eg Chat) – Waiting for responses (eg web services) • Not for Async IO! – Requests mostly small (single packet) – Hard to asynchronously produce large responses – Async IO support waiting for NIO2 27
  • 28. Blocking waiting consumes resources • Web Application using remote web services – Handling 1000 requests / sec – 50% requests call remote web service – 500 threads in container thread pool • If remote web service is slow (1000ms) – Thread starvation in 1 second! – 50% of requests use all 500 threads 28
  • 29. Asynchronous API Enable asynchronous support • ServletRequest#isAsyncSupported() – True if ALL [Filter|Servlet]s support async in • the Filter chain • the RequestDispatch chain • Configured in – web.xml • <async-supported>true</async- supported> – With annotation • @WebServlet(asyncSupported=true) 29
  • 30. Asynchronous API Start asynchronous processing • AsyncContext ServletRequest#startAsync() – Called by [Filter|Servlet] – Response is NOT commited on return of: • Servlet.service(request,response) • Filter chain • AsyncContext ServletRequest#startAsync (ServletRequest req, ServletResponse res) 30
  • 31. Asynchronous API AsyncContext • AsyncContext#dispatch() – Called by your asynchronous handler – Schedule async dispatch:DispatcherType.ASYNC – Response generated by [Filter|Servlet] using: • container thread pool • JSP, JSF or other frameworks usable • JNDI, JTA, EJBs usable • AsyncContext#dispatch(String path) – Variation to async dispatch to specific Servlet 31
  • 32. Asynchronous API AsyncContext (contd) • AsyncContext#complete() – Called by your asynchronous handler – Signals Response has been generated • without [Filter|Servlet] dispatch • without Servlet features • Or with AsyncContext#start(Runnable r) 32
  • 33. Asynchronous API usage styles • startAsync() … dispatch() – Retry request after async wait – Filters re-applied if on DispatcherType.ASYNC • startAsync() … dispatch(path) – Use specific Servlet handling after async wait • startAsync() … complete() – Generate response asynchronously 33
  • 34. Asynchronous API usage styles • startAsync(req,res) … dispatch() – Retry request after async wait – Wrappers are kept – RequestDispatcher#forward target used • startAsync(req,res) … dispatch(path) – Specific Servlet handling after async wait • startAsync(req,res) … complete() – Generate wrapped response asynchronously 34
  • 35. Asynchronous API Timeout • Timeouts – AsyncContext#setAsyncTimeout(long ms) – By default error dispatch on timeout • Listeners – AsyncListener#OnTimeout – AsyncListener#OnComplete 35
  • 36. Security Annotations to define security constraints • @ServletSecurity used to define access control constraints • Can specify constraint for all HTTP methods via the @HttpConstraint • Or specify constraint for specific HTTP methods via the @HttpMethodConstraint • If both specified in the @ServletSecurity, the @HttpConstraint applies to those methods not specifically specified via the @HttpMethodConstraint 36
  • 37. Security Example @ServletSecurity((httpMethodConstraints = { @HttpMethodConstraint(value = "GET", rolesAllowed = "R1"), @HttpMethodConstraint(value = "POST", rolesAllowed = "R1", transportGuarantee = TransportGuarantee.CONFIDENTIAL) }) public class Example5 extends HttpServlet { } 37
  • 38. Security Programmatic container authentication and logout • HttpServletRequest#login(String username, String password) – Replacement for FBL – Application supervises credential collection • HttpServletRequest#authenticate(HttpServle tResponse) – Application initiates container mediated authentication from a resource that is not covered by any authentication constraints – Application decides when authentication must occur 38
  • 39. Security Programmatic container authentication and logout • Integration of additional container authentication modules via Servlet Profile of JSR 196 recommended • HttpServletRequest#logout 39
  • 40. Miscellaneous Features / API enhancements • Session tracking cookie configuration – Via web.xml – Programmatic via javax.servlet.SessionCookieConfig • Support for HttpOnly cookie attribute – Example: servletContext.getSessionCookieConfig(). setHttpOnly(true) • Default error page 40
  • 41. Miscellaneous Features / API enhancements (contd) • ServletRequest#getServletContext • ServletRequest#getDispatcherType • Servlet[Request| Response]Wrapper#isWrapperFor • HttpServletResponse#getStatus • HttpServletResponse#getHeader • HttpServletResponse#getHeaders • HttpServletResponse#getHeaderNames 41
  • 42. Miscellaneous Features / API (contd) File upload • ServletRequest#getParts • ServletRequest#getPart • @MultipartConfig • Changes to web.xml 42
  • 43. Summary • Major revision since Servlet 2.4 • Comprehensive set of new features enable modern style of web applications and greatly increases developer productivity • Simplifies assembly of large applications from reusable components 43
  • 45. Q&A 45
  • 46. <Insert Picture Here> Servlet 3.0, Asynchronous, Easy extensible Rajiv Mordani rajiv.mordani@oracle.com