Presentation is loading. Please wait.

Presentation is loading. Please wait.

Amsterdam What is new in Servlet 3.0 ApacheCon 2009.

Similar presentations


Presentation on theme: "Amsterdam What is new in Servlet 3.0 ApacheCon 2009."— Presentation transcript:

1 Amsterdam What is new in Servlet 3.0 ApacheCon 2009

2 Who is Filip Apache Tomcat committer ASF Member Part of the servlet expert group SpringSource Inc employee

3 Agenda Walk through of features and specification changes in JSR 315 Features, APIs and other information may still change!

4 Versions Servlet/ JSP Spec Tomcat versionJDK Version 2.5 2.1 6.0.xJDK 1.5+ 2.4 2.0 5.0.x, 5.5.xJDK 1.4+ 2.3 1.2 4.1.xJDK 1.3+ 2.2 1.1 3.3.xJDK 1.2+ (?)

5 Versions Servlet/ JSP Spec Tomcat versionJDK Version 3.0 2.1? 7.0.x Java SE 6 (JDK/JRE 1.6) Servlet 3.0 Will Require Java 6

6 Asynchronous Processing One of the major improvements Most containers already have 'some sort of implementation' Tomcat offers the CometProcessor interface

7 Asynchronous Processing What is it? Decouple container request thread from ServletRequest/ServletResponse objects

8 Asynchronous Processing What is it NOT? Non blocking servlet IO implementation – This was briefly discussed – Backwards compatibility challenges – Very complex programming model

9 Asynchronous Processing What we do today doFilter(Request req, Response res, FilterChain chain) { //pre filter actions chain.doFilter(req,res); //post filter action } service(Request req, Response res) { //read request //write response } Request,Response recycled Request,Response recycled(no filter)

10 Asynchronous Processing Backwards compatibility? Servlet/Filters are non asynchronous by default – Asynchronous processing requires explicit support in code – Currently done using annotation – Still determining other ways of enabling

11 Asynchronous Processing Enabling asynchronous processing @WebFilter(asyncSupported=true) public class MyFilter { } @WebServlet(asyncSupported=true) public class MyServlet { }

12 Asynchronous Processing Initiating an asynchronous request interface javax.servlet.ServletRequest { AsyncContext startAsync(); AsyncContext startAsync(Request,Response); } throws IllegalStateException if isAsyncSupported() returns false

13 Asynchronous Processing javax.servlet.AsyncContext Similarities to CometEvent in Tomcat – Wraps request/response objects – Can dispatch the request to a URL – Can request a container thread to execute a task – Can notify container that the request is complete

14 Asynchronous Processing Asynchronous example service(Request req, Response res) { AsyncContext actx = req.startAsync(); Runnable runnable = new Runnable() { public void run() { Message m = jmsTemplate.receive(); res.write(m); req.complete(); } }; executor.submit(runnable); }

15 Asynchronous Processing Defensive programming service(Request req, Response res) { if (req.isAsyncSupported()) { AsyncContext actx = req.isAsyncStarted()? req.getAsyncContext(): req.startAsync();... } else {... }

16 Asynchronous Processing Forwarding to a content generator interface javax.servlet.AsyncContext { void dispatch(); void dispatch(String path); void dispatch(ServletContext ctx, String path) } dispatches to a container thread

17 Asynchronous Processing Forwarding to a content generator service(Request req, Response res) { final AsyncContext actx = req.startAsync(); Runnable runnable = new Runnable() { public void run() { Message m = jmsTemplate.receive(); req.setAttribute(“quote”,m); actx.dispatch(“/stock/quote.jsp”); } }; executor.submit(runnable); }

18 Asynchronous Processing Receiving Container Events interface javax.servlet.AsyncListener { void onComplete(AsyncEvent event); void onTimeout(AsyncEvent event); }

19 Asynchronous Processing That's enough for now! A detailed paper on asynchronous processing – Has been submitted to ApacheCon US 2009 CFP

20 Web Fragments Ability to submit web.xml fragments with JAR packaged libraries Can be disabled using true

21 Web Fragments mylib.jar/META-INF/web-fragment.xml MyServlet MyServlet *.tsp

22 Web Fragments Ordering of web fragments Absolute ordering – web.xml - Relative ordering – web-fragment.xml -

23 Web Fragments Ordering is name based MyWebFragment1 MyWebFragment2

24 Pluggability Programatically add - Servlets - Filters To a ServletContext Can only be done during the ServletContext initialization phase – contextInitialized() method of ServletContextListener

25 Pluggability Adding Servlets & Filters interface javax.servlet.ServletContext { FilterRegistration addFilter( String filterName, String|Class filterClass); ServletRegistration addServlet( String servletName, String|Class servletClass); }

26 Pluggability Registration objects interface Servlet/Filter-Registration{ setDescription(String); setInitParameter(String name,Object value); setInitParameters(Map p); setAsyncSupported(boolean supported); addMappingForUrlPatterns(...); }

27 Annotations New annotations added – @WebServlet (must extend HttpServlet) – @WebFilter (must implement Filter) – @WebInitParam (both servlets/filters) – @WebListener ServletContextListener (& attr listener) HttpSessionListener (& attr listener) ServletRequestListener (& attr listener)

28 Security New methods interface HttpServletRequest{ login(HttpServletResponse resp); login(String username, String password); logout(); }

29 Security Allow a login to happen on a non constrained request Sensitive to the response being committed – In order to set a session cookie, when configured

30 File Upload Is being considered for addition Challenge: Servlet 3.0 doesn't have non blocking IO – Removes the usefulness of having yet another file upload API Based on javax.activation – That is part of Java SE 6

31 Session Cookie Configuration Configure the session cookie interface javax.servlet.SessionCookieConfig { setName(String name); setSecure(boolean isSecure); setHttpOnly(boolean isHttpOnly); setPath(String path); setDomain(String domain); setComment(String comment); }

32 Timeline Originally planned June 2009 May be pushed to September 2009 – JEE spec needs more time

33 Questions and Answer


Download ppt "Amsterdam What is new in Servlet 3.0 ApacheCon 2009."

Similar presentations


Ads by Google