SlideShare a Scribd company logo
1 of 26
Servlet 3.0




              Minh Hoang TO

              Portal Team
Servlet 3.0 Specification


 - Java Specification Request JSR-315



 - Part of Java Enterprise Edition 6



 - Compliant servers:

    Apache Tomcat 7, JBoss AS 7, Jetty 8, GlassFish 3, ...




                     www.exoplatform.com - Copyright 2012 eXo Platform   2
Agenda

- Annotations

- Web Fragment

- Dynamic Registration

- Programmatic Login

- Asynchronous Servlet

- File Upload



                www.exoplatform.com - Copyright 2012 eXo Platform   3
Annotations


- Use annotations to declare servlet, filter, listener and specify metadata for the
declared component


@WebServlet
@WebFilter
@WebInitParam
@WebListener
@ServletSecurity
@HttpConstraint


- Servlet container detects annotated class and injects metadata into declared
components at deploy time




                       www.exoplatform.com - Copyright 2012 eXo Platform              4
Annotations

Declare servlet via deployment descriptor:

<servlet>
  <servlet-name>hello</servlet-name>
  <servlet-class>com.mto.presentation.HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
 <servlet-name>hello</servlet-name>
 <url-pattern>/greeting/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
 <servlet-name>hello</servlet-name>
<url-pattern>/sayhello/*</url-pattern>
</servlet-mapping>



                      www.exoplatform.com - Copyright 2012 eXo Platform   5
Annotations

Declare servlet via annotated class



@WebServlet
(
  name = “hello”,

    urlPatterns = {“/greeting/*“, “/sayhello/*“}
)
public class HelloServlet extends HttpServlet {

}




                           www.exoplatform.com - Copyright 2012 eXo Platform   6
Annotations

Declare filter via deployment descriptor:

<filter>
  <filter-name>hello</filter-name>
  <filter-class>com.mto.presentation.HelloFilter</filter-class>
</filter>

<filter-mapping>
 <filter-name>hello</filter-name>
 <url-pattern>/greeting/*</url-pattern>
</filter-mapping>

<filter-mapping>
 <filter-name>hello</filter-name>
<url-pattern>/sayhello/*</url-pattern>
</filter-mapping>



                       www.exoplatform.com - Copyright 2012 eXo Platform   7
Annotations

Declare filter via annotated class



@WebFilter
(
  name = “hello”,

    urlPatterns = {“/greeting/*“, “/sayhello/*“}
)
public class HelloFilter implements Filter {

}




                           www.exoplatform.com - Copyright 2012 eXo Platform   8
Annotations


- Type safe and less error-prone

- Facilitate work of developers

- No need to master XSD of deployment descriptor


BUT

- Frequent recompilation is a big obstacle




                       www.exoplatform.com - Copyright 2012 eXo Platform   9
Web Fragment


- Divide WEB-INF/web.xml into multiples META-INF/web-fragment.xml :

  1. Each web-fragment.xml is packed in a .jar artifact under WEB-INF/lib

  2. Web application components could be declared in web-fragment.xml

  3. Order of fragment processing is manageable




                     www.exoplatform.com - Copyright 2012 eXo Platform      10
Web Fragment


Filter configuration in a web.xml

<filter><filter-name>filterA</filter-name><filter-class>FilterA</filter-class></filter>
<filter><filter-name>filterB</filter-name><filter-class>FilterB</filter-class></filter>

<filter-mapping>
  <filter-name>filterA</filter-name>
  <url-pattern>/testWebFragment/*</url-pattern>
</filter-mapping>

<filter-mapping>
  <filter-name>filterB</filter-name>
  <url-pattern>/testWebFragment/*</url-pattern>
</filter-mapping>




                        www.exoplatform.com - Copyright 2012 eXo Platform             11
Web Fragment

META-INF/web-fragment.xml under filterA.jar

<web-fragment>
 <name>A</name>
 <filter><filter-name>filterA</filter-name><filter-class>FilterA</filter-class></filter>

 <filter-mapping>
  <filter-name>filterA</filter-name>
  <url-pattern>/testWebFragment/*</url-pattern>
 </filter-mapping>

 <ordering>
   <before>
     <others/>
   </before>
 </ordering>
</web-fragment>


                        www.exoplatform.com - Copyright 2012 eXo Platform             12
Web Fragment

META-INF/web-fragment.xml under filterB.jar

<web-fragment>
 <name>B</name>
 <filter><filter-name>filterB</filter-name><filter-class>FilterB</filter-class></filter>

 <filter-mapping>
  <filter-name>filterB</filter-name>
  <url-pattern>/testWebFragment/*</url-pattern>
 </filter-mapping>

 <ordering>
   <after>
    <name>A</name>
   </after>
 </ordering>
</web-fragment>


                        www.exoplatform.com - Copyright 2012 eXo Platform             13
Web Fragment

- Base to implement pluggable/extensible configuration


BUT


- Quite limit as relevant .jar artifacts must be under WEB-INF/lib




                       www.exoplatform.com - Copyright 2012 eXo Platform   14
Dynamic Registration

- Inject dynamically components, callbacks to ServletContext object on starting
the context

 Use cases:

 1. Inject a PortletProducerServlet servlet to ServletContext object of each web-
    application containing WEB-INF/portlet.xml

 2. Register callbacks for deploy/undeploy events on web applications containing
    gatein-resources.xml

- Prior to Servlet 3.0, dynamic registration has to handler native work to
containers (WCI project)

- Doable in a portable manner with Servlet 3.0




                       www.exoplatform.com - Copyright 2012 eXo Platform            15
Dynamic Registration

- As container starts, it detects all implementations of ServletContainerInitializer
thanks to java.util.ServiceLoader mechanism, then invokes the method onStartup
on each initializing ServletContext



public interface ServletContainerInitializer
{
  public void onStartup(Set<Class<?>> c, ServletContext ctx);
}



- Complex dynamic registration could be plugged to onStartup entry point




                       www.exoplatform.com - Copyright 2012 eXo Platform          16
Dynamic Registration

- Simple implementation for dynamic registration

public SimpleInitializer implements ServletContainerInitializer{
  public void onStartup(Set<Class<?>> c, ServletContext ctx)
  {
    if(“/sample”.equals(ctx.getContextPath())
    {
       //Code handling ClassLoader elided from example
      Class clazz = ctx.getClassLoader().loadClass(“abc.DynamicServlet”);
      ServletRegistration.Dynamic reg = ctx.addServlet(“dynamicServlet”, clazz);
      reg.addMapping(“/dynamic/*”);
    }
  }
}

- Declare fully-qualified name of implementation class in META-
INF/services/javax.servlet.ServletContainerInitializer


                      www.exoplatform.com - Copyright 2012 eXo Platform            17
Dynamic Registration


- Portable code for dynamic registration


BUT


- Class loading issues must be handled gracefully

- Container detects ServletContainerInitializer via service loader, so the .jar
containing ServletContainerInitializer must be visible to container 's bootstrap
class loader




                       www.exoplatform.com - Copyright 2012 eXo Platform           18
Programmatic Login

- Prior to Servlet 3.0, any authentication flow must pass through a redirect request
with predefined params

 1. j_security_check
 2. j_username
 3. j_password

Container intercepts that request and delegates to JAAS

- From Servlet 3.0

 request.login(“root”, “gtn”);

The whole authentication process could be managed in the scope of a single
request




                       www.exoplatform.com - Copyright 2012 eXo Platform          19
Asynchronous Servlet

- Use in server-push communication model:

   1. Client sends request for real time data such as: livescore, exchange rate
   2. Server queues the request as there is no event on real time data
   3. As there is update on real time data, server loops through queued request
     and respond to client



- Prior to Servlet 3.0, implementation of such communication model (using Servlet
API) is not scalable as request handling thread is not released during request
lifecycle.


- In Servlet 3.0, request handling thread could be released before the end of
request lifecycle




                      www.exoplatform.com - Copyright 2012 eXo Platform           20
Asynchronous Servlet
@WebServlet(
  name=”livescore”,
  asyncSupported=true,
  urlPatterns = {“/livescore/*”}
)
public class LivescoreServlet extends HttpServlet
{
   //Synchronization code elided from example
   public void doGet(HttpServletRequest req, HttpServletResponse res)
   {
      AsyncContext ctx = req.startAsync(req, res);
      //Thread handling request is released here but the res object is still alive
      queue.add(ctx);
   }

    //Typically event from a messaging service
    public void onServerEvent(EventObject obj)
    {
       //Loop over queue and send response to client
    }
}
                       www.exoplatform.com - Copyright 2012 eXo Platform             21
Asynchronous Servlet


<script type=”text/javascript”>

   var url = //url intercepted by livescore servlet
   var updateScore = function()
   {
       $.getJSON(url, function(data)
       {
          //Update HTML with received data
          setTimeout(updateScore, 1000);
       });
   };

   updateScore();
</script>




                       www.exoplatform.com - Copyright 2012 eXo Platform   22
Asynchronous Servlet

- Scalable threading model

BUT

- Header fields of HTTP protocol results in unnecessary network throughput

- WebSocket – better solution is going to appear in future version of Servlet
Specification




                      www.exoplatform.com - Copyright 2012 eXo Platform         23
File Upload

@WebServlet(
  name = “uploadServlet”, urlPatterns = {“/uploadFile/*”}
)
@MultipartConfig
public class UploadServlet extends HttpServlet
{
  public void doPost(HttpServletRequest req, HttpServletResponse res)
  {
    Collection<Part> parts = req.getParts();
    for(Part part : parts)
    {
       ….......
       part.write(System.getProperty(“java.io.tmpdir”) + “/” + part.getName());
       ….......
    }
  }
}


                       www.exoplatform.com - Copyright 2012 eXo Platform          24
File Upload




        <form action=”/uploadFile/ method=”post”>
           <input type=”file” name=”part_name”/>
           <input type=”submit” value=”Upload”/>
        </form>




                 www.exoplatform.com - Copyright 2012 eXo Platform   25
File Upload


- Nice API for uploading files


BUT


- Lack of public API to monitor upload progress




                       www.exoplatform.com - Copyright 2012 eXo Platform   26

More Related Content

What's hot

Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RSFahad Golra
 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session ManagementFahad Golra
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technologyvikram singh
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servletssbd6985
 
Soa installation
Soa installationSoa installation
Soa installationxavier john
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletFahmi Jafar
 
Servlet api &amp; servlet http package
Servlet api &amp; servlet http packageServlet api &amp; servlet http package
Servlet api &amp; servlet http packagerenukarenuka9
 
Servlets - filter, listeners, wrapper, internationalization
Servlets -  filter, listeners, wrapper, internationalizationServlets -  filter, listeners, wrapper, internationalization
Servlets - filter, listeners, wrapper, internationalizationsusant sahu
 
Html servlet example
Html   servlet exampleHtml   servlet example
Html servlet examplervpprash
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packagesvamsi krishna
 

What's hot (20)

Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RS
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session Management
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Tomcat
TomcatTomcat
Tomcat
 
Soa installation
Soa installationSoa installation
Soa installation
 
What is play
What is playWhat is play
What is play
 
JDBC
JDBCJDBC
JDBC
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES Servlet
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
 
JAX-WS Basics
JAX-WS BasicsJAX-WS Basics
JAX-WS Basics
 
Servlet
Servlet Servlet
Servlet
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Servlet api &amp; servlet http package
Servlet api &amp; servlet http packageServlet api &amp; servlet http package
Servlet api &amp; servlet http package
 
Servlets - filter, listeners, wrapper, internationalization
Servlets -  filter, listeners, wrapper, internationalizationServlets -  filter, listeners, wrapper, internationalization
Servlets - filter, listeners, wrapper, internationalization
 
Html servlet example
Html   servlet exampleHtml   servlet example
Html servlet example
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packages
 

Similar to Servlet 3.0

Java Portlet 2.0 (JSR 286) Specification
Java Portlet 2.0 (JSR 286) SpecificationJava Portlet 2.0 (JSR 286) Specification
Java Portlet 2.0 (JSR 286) SpecificationJohn Lewis
 
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010Jagadish Prasath
 
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
Java EE 6 = Less Code + More Power (Tutorial)  [5th IndicThreads Conference O...Java EE 6 = Less Code + More Power (Tutorial)  [5th IndicThreads Conference O...
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...IndicThreads
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortalJennifer Bourey
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/ServletSunil OS
 
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVCAnnotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVCJohn Lewis
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Arun Gupta
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technologyMinal Maniar
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jspAnkit Minocha
 
SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3Ben Abdallah Helmi
 
Apache Stratos Hangout VI
Apache Stratos Hangout VIApache Stratos Hangout VI
Apache Stratos Hangout VIpradeepfn
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Augemfrancis
 
Developing JSR 286 Portlets
Developing JSR 286 PortletsDeveloping JSR 286 Portlets
Developing JSR 286 PortletsCris Holdorph
 
SCWCD : Servlet web applications : CHAP 3
SCWCD : Servlet web applications : CHAP 3SCWCD : Servlet web applications : CHAP 3
SCWCD : Servlet web applications : CHAP 3Ben Abdallah Helmi
 
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
 
Building+restful+webservice
Building+restful+webserviceBuilding+restful+webservice
Building+restful+webservicelonegunman
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesbharathiv53
 

Similar to Servlet 3.0 (20)

Java Portlet 2.0 (JSR 286) Specification
Java Portlet 2.0 (JSR 286) SpecificationJava Portlet 2.0 (JSR 286) Specification
Java Portlet 2.0 (JSR 286) Specification
 
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
Java EE 6 - Deep Dive - Indic Threads, Pune - 2010
 
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
Java EE 6 = Less Code + More Power (Tutorial)  [5th IndicThreads Conference O...Java EE 6 = Less Code + More Power (Tutorial)  [5th IndicThreads Conference O...
Java EE 6 = Less Code + More Power (Tutorial) [5th IndicThreads Conference O...
 
Web sockets in Java
Web sockets in JavaWeb sockets in Java
Web sockets in Java
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVCAnnotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
Java servlets
Java servletsJava servlets
Java servlets
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3SCWCD : Servlet web applications : CHAP : 3
SCWCD : Servlet web applications : CHAP : 3
 
Apache Stratos Hangout VI
Apache Stratos Hangout VIApache Stratos Hangout VI
Apache Stratos Hangout VI
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
 
Developing JSR 286 Portlets
Developing JSR 286 PortletsDeveloping JSR 286 Portlets
Developing JSR 286 Portlets
 
SCWCD : Servlet web applications : CHAP 3
SCWCD : Servlet web applications : CHAP 3SCWCD : Servlet web applications : CHAP 3
SCWCD : Servlet web applications : CHAP 3
 
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
 
Building+restful+webservice
Building+restful+webserviceBuilding+restful+webservice
Building+restful+webservice
 
Day7
Day7Day7
Day7
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
 

More from Minh Hoang

Yolo Family TechTalk
Yolo Family TechTalkYolo Family TechTalk
Yolo Family TechTalkMinh Hoang
 
ElasticSearch Introduction
ElasticSearch IntroductionElasticSearch Introduction
ElasticSearch IntroductionMinh Hoang
 
Modularize JavaScript with RequireJS
Modularize JavaScript with RequireJSModularize JavaScript with RequireJS
Modularize JavaScript with RequireJSMinh Hoang
 
Zero redeployment with JRebel
Zero redeployment with JRebelZero redeployment with JRebel
Zero redeployment with JRebelMinh Hoang
 
Regular Expression
Regular ExpressionRegular Expression
Regular ExpressionMinh Hoang
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance TuningMinh Hoang
 
Gatein Presentation
Gatein PresentationGatein Presentation
Gatein PresentationMinh Hoang
 

More from Minh Hoang (7)

Yolo Family TechTalk
Yolo Family TechTalkYolo Family TechTalk
Yolo Family TechTalk
 
ElasticSearch Introduction
ElasticSearch IntroductionElasticSearch Introduction
ElasticSearch Introduction
 
Modularize JavaScript with RequireJS
Modularize JavaScript with RequireJSModularize JavaScript with RequireJS
Modularize JavaScript with RequireJS
 
Zero redeployment with JRebel
Zero redeployment with JRebelZero redeployment with JRebel
Zero redeployment with JRebel
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
Gatein Presentation
Gatein PresentationGatein Presentation
Gatein Presentation
 

Recently uploaded

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

Servlet 3.0

  • 1. Servlet 3.0 Minh Hoang TO Portal Team
  • 2. Servlet 3.0 Specification - Java Specification Request JSR-315 - Part of Java Enterprise Edition 6 - Compliant servers: Apache Tomcat 7, JBoss AS 7, Jetty 8, GlassFish 3, ... www.exoplatform.com - Copyright 2012 eXo Platform 2
  • 3. Agenda - Annotations - Web Fragment - Dynamic Registration - Programmatic Login - Asynchronous Servlet - File Upload www.exoplatform.com - Copyright 2012 eXo Platform 3
  • 4. Annotations - Use annotations to declare servlet, filter, listener and specify metadata for the declared component @WebServlet @WebFilter @WebInitParam @WebListener @ServletSecurity @HttpConstraint - Servlet container detects annotated class and injects metadata into declared components at deploy time www.exoplatform.com - Copyright 2012 eXo Platform 4
  • 5. Annotations Declare servlet via deployment descriptor: <servlet> <servlet-name>hello</servlet-name> <servlet-class>com.mto.presentation.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>/greeting/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>/sayhello/*</url-pattern> </servlet-mapping> www.exoplatform.com - Copyright 2012 eXo Platform 5
  • 6. Annotations Declare servlet via annotated class @WebServlet ( name = “hello”, urlPatterns = {“/greeting/*“, “/sayhello/*“} ) public class HelloServlet extends HttpServlet { } www.exoplatform.com - Copyright 2012 eXo Platform 6
  • 7. Annotations Declare filter via deployment descriptor: <filter> <filter-name>hello</filter-name> <filter-class>com.mto.presentation.HelloFilter</filter-class> </filter> <filter-mapping> <filter-name>hello</filter-name> <url-pattern>/greeting/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hello</filter-name> <url-pattern>/sayhello/*</url-pattern> </filter-mapping> www.exoplatform.com - Copyright 2012 eXo Platform 7
  • 8. Annotations Declare filter via annotated class @WebFilter ( name = “hello”, urlPatterns = {“/greeting/*“, “/sayhello/*“} ) public class HelloFilter implements Filter { } www.exoplatform.com - Copyright 2012 eXo Platform 8
  • 9. Annotations - Type safe and less error-prone - Facilitate work of developers - No need to master XSD of deployment descriptor BUT - Frequent recompilation is a big obstacle www.exoplatform.com - Copyright 2012 eXo Platform 9
  • 10. Web Fragment - Divide WEB-INF/web.xml into multiples META-INF/web-fragment.xml : 1. Each web-fragment.xml is packed in a .jar artifact under WEB-INF/lib 2. Web application components could be declared in web-fragment.xml 3. Order of fragment processing is manageable www.exoplatform.com - Copyright 2012 eXo Platform 10
  • 11. Web Fragment Filter configuration in a web.xml <filter><filter-name>filterA</filter-name><filter-class>FilterA</filter-class></filter> <filter><filter-name>filterB</filter-name><filter-class>FilterB</filter-class></filter> <filter-mapping> <filter-name>filterA</filter-name> <url-pattern>/testWebFragment/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>filterB</filter-name> <url-pattern>/testWebFragment/*</url-pattern> </filter-mapping> www.exoplatform.com - Copyright 2012 eXo Platform 11
  • 12. Web Fragment META-INF/web-fragment.xml under filterA.jar <web-fragment> <name>A</name> <filter><filter-name>filterA</filter-name><filter-class>FilterA</filter-class></filter> <filter-mapping> <filter-name>filterA</filter-name> <url-pattern>/testWebFragment/*</url-pattern> </filter-mapping> <ordering> <before> <others/> </before> </ordering> </web-fragment> www.exoplatform.com - Copyright 2012 eXo Platform 12
  • 13. Web Fragment META-INF/web-fragment.xml under filterB.jar <web-fragment> <name>B</name> <filter><filter-name>filterB</filter-name><filter-class>FilterB</filter-class></filter> <filter-mapping> <filter-name>filterB</filter-name> <url-pattern>/testWebFragment/*</url-pattern> </filter-mapping> <ordering> <after> <name>A</name> </after> </ordering> </web-fragment> www.exoplatform.com - Copyright 2012 eXo Platform 13
  • 14. Web Fragment - Base to implement pluggable/extensible configuration BUT - Quite limit as relevant .jar artifacts must be under WEB-INF/lib www.exoplatform.com - Copyright 2012 eXo Platform 14
  • 15. Dynamic Registration - Inject dynamically components, callbacks to ServletContext object on starting the context Use cases: 1. Inject a PortletProducerServlet servlet to ServletContext object of each web- application containing WEB-INF/portlet.xml 2. Register callbacks for deploy/undeploy events on web applications containing gatein-resources.xml - Prior to Servlet 3.0, dynamic registration has to handler native work to containers (WCI project) - Doable in a portable manner with Servlet 3.0 www.exoplatform.com - Copyright 2012 eXo Platform 15
  • 16. Dynamic Registration - As container starts, it detects all implementations of ServletContainerInitializer thanks to java.util.ServiceLoader mechanism, then invokes the method onStartup on each initializing ServletContext public interface ServletContainerInitializer { public void onStartup(Set<Class<?>> c, ServletContext ctx); } - Complex dynamic registration could be plugged to onStartup entry point www.exoplatform.com - Copyright 2012 eXo Platform 16
  • 17. Dynamic Registration - Simple implementation for dynamic registration public SimpleInitializer implements ServletContainerInitializer{ public void onStartup(Set<Class<?>> c, ServletContext ctx) { if(“/sample”.equals(ctx.getContextPath()) { //Code handling ClassLoader elided from example Class clazz = ctx.getClassLoader().loadClass(“abc.DynamicServlet”); ServletRegistration.Dynamic reg = ctx.addServlet(“dynamicServlet”, clazz); reg.addMapping(“/dynamic/*”); } } } - Declare fully-qualified name of implementation class in META- INF/services/javax.servlet.ServletContainerInitializer www.exoplatform.com - Copyright 2012 eXo Platform 17
  • 18. Dynamic Registration - Portable code for dynamic registration BUT - Class loading issues must be handled gracefully - Container detects ServletContainerInitializer via service loader, so the .jar containing ServletContainerInitializer must be visible to container 's bootstrap class loader www.exoplatform.com - Copyright 2012 eXo Platform 18
  • 19. Programmatic Login - Prior to Servlet 3.0, any authentication flow must pass through a redirect request with predefined params 1. j_security_check 2. j_username 3. j_password Container intercepts that request and delegates to JAAS - From Servlet 3.0 request.login(“root”, “gtn”); The whole authentication process could be managed in the scope of a single request www.exoplatform.com - Copyright 2012 eXo Platform 19
  • 20. Asynchronous Servlet - Use in server-push communication model: 1. Client sends request for real time data such as: livescore, exchange rate 2. Server queues the request as there is no event on real time data 3. As there is update on real time data, server loops through queued request and respond to client - Prior to Servlet 3.0, implementation of such communication model (using Servlet API) is not scalable as request handling thread is not released during request lifecycle. - In Servlet 3.0, request handling thread could be released before the end of request lifecycle www.exoplatform.com - Copyright 2012 eXo Platform 20
  • 21. Asynchronous Servlet @WebServlet( name=”livescore”, asyncSupported=true, urlPatterns = {“/livescore/*”} ) public class LivescoreServlet extends HttpServlet { //Synchronization code elided from example public void doGet(HttpServletRequest req, HttpServletResponse res) { AsyncContext ctx = req.startAsync(req, res); //Thread handling request is released here but the res object is still alive queue.add(ctx); } //Typically event from a messaging service public void onServerEvent(EventObject obj) { //Loop over queue and send response to client } } www.exoplatform.com - Copyright 2012 eXo Platform 21
  • 22. Asynchronous Servlet <script type=”text/javascript”> var url = //url intercepted by livescore servlet var updateScore = function() { $.getJSON(url, function(data) { //Update HTML with received data setTimeout(updateScore, 1000); }); }; updateScore(); </script> www.exoplatform.com - Copyright 2012 eXo Platform 22
  • 23. Asynchronous Servlet - Scalable threading model BUT - Header fields of HTTP protocol results in unnecessary network throughput - WebSocket – better solution is going to appear in future version of Servlet Specification www.exoplatform.com - Copyright 2012 eXo Platform 23
  • 24. File Upload @WebServlet( name = “uploadServlet”, urlPatterns = {“/uploadFile/*”} ) @MultipartConfig public class UploadServlet extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse res) { Collection<Part> parts = req.getParts(); for(Part part : parts) { …....... part.write(System.getProperty(“java.io.tmpdir”) + “/” + part.getName()); …....... } } } www.exoplatform.com - Copyright 2012 eXo Platform 24
  • 25. File Upload <form action=”/uploadFile/ method=”post”> <input type=”file” name=”part_name”/> <input type=”submit” value=”Upload”/> </form> www.exoplatform.com - Copyright 2012 eXo Platform 25
  • 26. File Upload - Nice API for uploading files BUT - Lack of public API to monitor upload progress www.exoplatform.com - Copyright 2012 eXo Platform 26