Felix HTTP
Paving the road to the future
 and Jan Willem Janssen Marcel Offermans
SSID: Felix
Password: felixdemo
Browse t...
Jan Willem
Janssen
Software architect at Luminis Technologies
Currently working on PulseOn and Amdatu
Committer and PMC me...
Marcel
Offermans
Director at Luminis Technologies, Fellow at Luminis
Currently working on Amdatu
Apache Member, Committer ...
Agenda
Modular Web Applications
Current State
Available Extensions
The New Specification
New extensions
Future Work
Wrap Up
Modular Web
Applications
Modular
Architectures
High Cohesion, Low Coupling
Separation of Concerns
Maintainable Code
Reusable, Composable
Deployments
Compose modules into different deployments
Low bandwidth by just sending changed modules
Fast deployments by b...
Current State
Explicit
RegistrationpublicinterfaceHttpService{
voidregisterServlet(Stringalias,Servletservlet,
DictionaryinitParams,Http...
Servlets
httpService.registerServlet("/hello",newHttpServlet(){
@Override
publicvoiddoGet(HttpServletRequestreq,HttpServle...
ResourceshttpService.registerResources("/site","/resources",null/*httpContext*/);
$catresources/hello
HelloApacheConworld,...
HttpContext
Provides secure access to servlets and resources.
Layer of abstraction for resource loading.
publicinterfaceHt...
Web Application
Specification
Part of the OSGi Enterprise Specification, chapter 128.
Web Application Bundle (WAB) are ext...
Available
Extensions
Whiteboard
don't call us, we'll call you!
Register your Servletin the service registry and add a property called
aliascont...
Filters
Just like Servlets, these can be registered whiteboard style
or use explicit registration:
the ExtHttpServiceservi...
Amdatu Web
Resources
of the open source project (Apache Licensed).Part Amdatu.org
X-Web-Resource-Version:1.1
X-Web-Resourc...
Demo
request a static resource called /amdatu‑resources
...
Amdatu Web
REST
Extensive support for based on industry standards.REST endpoints
JAX-RS based annotation support.
Includes...
Demo@Path("/rest")
@Description("ProvidesademoRESTendpoint")
publicclassDemoRestEndpoint{
privateStringm_response="HelloWo...
Self-
documenting
Endpoints
Swagger is a library that creates documentation for endpoints based on
JAX-RS annotations plus...
The new
specification
Whiteboard
No longer an extension
No explicit registration
Specify HttpService to be used
Example
Dictionaryprops=newHashtable();
props.put("osgi.http.whiteboard.servlet.pattern","/slidemgr");
props.put("osgi.htt...
(A)synchronous
Servlets
Servlet 3.0 API
Support wildcard one or more patterns
Process work outside the servlet lifecycle
Example code
classWorkerServletextendsHttpServlet{
protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp){
fina...
Example registration
Dictionaryprops=newHashtable();
props.put("osgi.http.whiteboard.servlet.pattern","/worker/*");
props....
Filters
Full support
Example
Dictionaryprops=newHashtable();
props.put("osgi.http.whiteboard.filter.pattern","/*");
props.put("osgi.http.whiteb...
Listeners
Full support
All events
Example
finalCountDownLatchlatch=newCountDownLatch(1);
ServletContextListenercontextListener=newServletContextListener(){
...
Custom Error
Pages
By error code
By exception
Example
Dictionaryprops=newHashtable();
props.put("osgi.http.whiteboard.servlet.errorPage",
newString[]{"500","java.io.IOE...
New extensions
WebSockets
“Real-time”
Binary or text-based
Two-way communication
RFC 6455
Example
//Client-side
varwsConn=newWebSocket("ws://"+window.location.host+"/servlet",["my-protocol"]);
wsConn.onmessage=fu...
Demo
Multi-user Etch A Sketch
SPDY
Let's make the web faster
Session layer on top of SSL
Reduce bandwidth & lower latency
Push multiple resources in a r...
Application
Session
Presentation
Transport
How SPDY fits in the OSI layer model.
SPDY vs WebSockets
SPDY WebSockets
Goal optimize HTTP 2-way communication
Upgradeability transparent needs works
Secure? ✔...
Demo
HTTP vs SPDY
Future Work
Finalize support for new HttpService specification
Upgrade to Jetty 9
Allow “new style” WebSockets (JSR 356) to be used
Im...
Wrap Up
New/updated specifications
New features, functionality & improvements
Available extensions
Build modular web applications
Questions?
Links
felix.apache.org
luminis-technologies.com
bndtools.org
amdatu.org
bitbucket.org/marrs/apachecon2014-felix-http
Upcoming SlideShare
Loading in …5
×

Felix HTTP - Paving the road to the future

2,108 views
1,934 views

Published on

Developing modular web-based applications is easy using the HTTP-service implementation of Apache Felix. It hides the complexity and boilerplate code needed to get your servlets and filters up and running in no-time. With the recent effort in aligning the HTTP-service with the latest servlet specifications, new functionality like asynchronous servlets and filters will be supported out-of-the-box.
In this presentation we will not only talk about the new features provided by the Felix HTTP-service implementation, but also demonstrate how to use them in your project. In addition, we talk about upcoming improvements to the Felix HTTP-service, like native support for SPDY and WebSockets.

Slide sources and example code: https://bitbucket.org/marrs/apachecon2014-felix-http/

Published in: Software
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,108
On SlideShare
0
From Embeds
0
Number of Embeds
741
Actions
Shares
0
Downloads
15
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Felix HTTP - Paving the road to the future

  1. 1. Felix HTTP Paving the road to the future  and Jan Willem Janssen Marcel Offermans SSID: Felix Password: felixdemo Browse to: http://10.61.0.161:8080/
  2. 2. Jan Willem Janssen Software architect at Luminis Technologies Currently working on PulseOn and Amdatu Committer and PMC member at Apache Felix and Apache ACE
  3. 3. Marcel Offermans Director at Luminis Technologies, Fellow at Luminis Currently working on Amdatu Apache Member, Committer and PMC member at Apache ACE and Apache Felix
  4. 4. Agenda Modular Web Applications Current State Available Extensions The New Specification New extensions Future Work Wrap Up
  5. 5. Modular Web Applications
  6. 6. Modular Architectures High Cohesion, Low Coupling Separation of Concerns Maintainable Code Reusable, Composable
  7. 7. Deployments Compose modules into different deployments Low bandwidth by just sending changed modules Fast deployments by being able to update running applications
  8. 8. Current State
  9. 9. Explicit RegistrationpublicinterfaceHttpService{ voidregisterServlet(Stringalias,Servletservlet, DictionaryinitParams,HttpContexthttpContext); voidregisterResources(Stringalias,Stringname, HttpContexthttpContext); voidunregister(Stringalias); HttpContextcreateDefaultHttpContext(); }
  10. 10. Servlets httpService.registerServlet("/hello",newHttpServlet(){ @Override publicvoiddoGet(HttpServletRequestreq,HttpServletResponseresp){ resp.setContentType("text/plain"); resp.getWriter().write("HelloApacheConworld!"); } },null/*initParams*/,null/*httpContext*/); invoke the /hello servlet ...
  11. 11. ResourceshttpService.registerResources("/site","/resources",null/*httpContext*/); $catresources/hello HelloApacheConworld,I'mastaticresource! request a static resource called hello ...
  12. 12. HttpContext Provides secure access to servlets and resources. Layer of abstraction for resource loading. publicinterfaceHttpContext{ booleanhandleSecurity(HttpServletRequestrequest, HttpServletResponseresponse); URLgetResource(Stringname); StringgetMimeType(Stringname); }
  13. 13. Web Application Specification Part of the OSGi Enterprise Specification, chapter 128. Web Application Bundle (WAB) are extended Java EE WAR files. They have optional JSP support. Integration with OSGi BundleContextand service registry.
  14. 14. Available Extensions
  15. 15. Whiteboard don't call us, we'll call you! Register your Servletin the service registry and add a property called aliascontaining its endpoint. For more information: http://www.osgi.org/wiki/uploads/Links/whiteboard.pdf
  16. 16. Filters Just like Servlets, these can be registered whiteboard style or use explicit registration: the ExtHttpServiceservice from Felix HTTP the WebContainerservice from PAX Web
  17. 17. Amdatu Web Resources of the open source project (Apache Licensed).Part Amdatu.org X-Web-Resource-Version:1.1 X-Web-Resource:/amdatu-resources;resources X-Web-Resource-Default-Page:index.html,/doc=javadoc.html Include-Resource:resources=resources/basic
  18. 18. Demo request a static resource called /amdatu‑resources ...
  19. 19. Amdatu Web REST Extensive support for based on industry standards.REST endpoints JAX-RS based annotation support. Includes support for Jackson mappings. Self-documenting endpoints with Swagger.
  20. 20. Demo@Path("/rest") @Description("ProvidesademoRESTendpoint") publicclassDemoRestEndpoint{ privateStringm_response="HelloWorld!"; @GET@Produces(MediaType.TEXT_PLAIN) @Description("Givesaplaintextresponse") publicStringgetPlainResponse(){ returnm_response; } @POST@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Description("Allowsonetosettheresponsetoreturn") publicvoidsetResponse( @FormParam("response")@DefaultValue("Defaultresponse")StringnewResponse){ m_response=newResponse; } }
  21. 21. Self- documenting Endpoints Swagger is a library that creates documentation for endpoints based on JAX-RS annotations plus some extras. Go to Swagger documentation
  22. 22. The new specification
  23. 23. Whiteboard No longer an extension No explicit registration Specify HttpService to be used
  24. 24. Example Dictionaryprops=newHashtable(); props.put("osgi.http.whiteboard.servlet.pattern","/slidemgr"); props.put("osgi.http.whiteboard.target","(http.service=demo)"); context.registerService(Servlet.class.getName(),newSlideManager(),props);
  25. 25. (A)synchronous Servlets Servlet 3.0 API Support wildcard one or more patterns Process work outside the servlet lifecycle
  26. 26. Example code classWorkerServletextendsHttpServlet{ protectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp){ finalAsyncContextasyncContext=req.startAsync(req,resp); asyncContext.start(newDeepThought(asyncContext)); } } // classDeepThoughtimplementsRunnable{ privateAsyncContextm_context=//... publicvoidrun(){ //...dosomehardwork... TimeUnit.DAYS.sleep(356L*7500000L); HttpServletResponseresponse=(HttpServletResponse)asyncContext.getResponse(); response.setStatus(SC_OK); response.getWriter().printf("42"); asyncContext.complete(); } }
  27. 27. Example registration Dictionaryprops=newHashtable(); props.put("osgi.http.whiteboard.servlet.pattern","/worker/*"); props.put("osgi.http.whiteboard.servlet.asyncSupported","true"); context.registerService(Servlet.class.getName(),newWorkerServlet(),props);
  28. 28. Filters Full support
  29. 29. Example Dictionaryprops=newHashtable(); props.put("osgi.http.whiteboard.filter.pattern","/*"); props.put("osgi.http.whiteboard.filter.dispatcher", newString[]{"REQUEST","INCLUDE","FORWARD"}); context.registerService(Filter.class.getName(),newSecurityFilter(),props);
  30. 30. Listeners Full support All events
  31. 31. Example finalCountDownLatchlatch=newCountDownLatch(1); ServletContextListenercontextListener=newServletContextListener(){ publicvoidcontextDestroyed(ServletContextEventevent){} publicvoidcontextInitialized(ServletContextEventevent){ latch.countDown(); } }; Dictionaryprops=newHashtable(); props.put("osgi.http.whiteboard.context.select","DEFAULT"); context.registerService(ServletContextListener.class.getName(),contextListener,props); assertTrue("HttpServicenotreadyintime?!",latch.await(5,TimeUnit.SECONDS)); //continuewithyouritest...
  32. 32. Custom Error Pages By error code By exception
  33. 33. Example Dictionaryprops=newHashtable(); props.put("osgi.http.whiteboard.servlet.errorPage", newString[]{"500","java.io.IOException"}); context.registerService(Servlet.class.getName(),newMyErrorHandlingServlet(),props);
  34. 34. New extensions
  35. 35. WebSockets “Real-time” Binary or text-based Two-way communication RFC 6455
  36. 36. Example //Client-side varwsConn=newWebSocket("ws://"+window.location.host+"/servlet",["my-protocol"]); wsConn.onmessage=function(event){ vardata=event.data; //dosomethingwithdata } //Server-side,registeredat"/servlet" classMyWebSocketServletextendsWebSocketServlet{ publicWebSocketdoWebSocketConnect(HttpServletRequestrequest,Stringprotocol){ if("my-protocol".equals(protocol)){ returnnewWebSocket.OnTextMessage(){ publicvoidonOpen(Connectionconn){} publicvoidonClose(intcode,Stringreason){} publicvoidonMessage(Stringdata){} }; } returnnull; } }
  37. 37. Demo Multi-user Etch A Sketch
  38. 38. SPDY Let's make the web faster Session layer on top of SSL Reduce bandwidth & lower latency Push multiple resources in a request Basis of HTTP 2.0
  39. 39. Application Session Presentation Transport How SPDY fits in the OSI layer model.
  40. 40. SPDY vs WebSockets SPDY WebSockets Goal optimize HTTP 2-way communication Upgradeability transparent needs works Secure? ✔ (mandatory) ✔ (if needed) Two-way? ✔ / ✘ ✔ Multiplexed ✔ ✘ Prioritized ✔ ✘
  41. 41. Demo HTTP vs SPDY
  42. 42. Future Work
  43. 43. Finalize support for new HttpService specification Upgrade to Jetty 9 Allow “new style” WebSockets (JSR 356) to be used Improved support for SPDY
  44. 44. Wrap Up
  45. 45. New/updated specifications New features, functionality & improvements Available extensions Build modular web applications
  46. 46. Questions?
  47. 47. Links felix.apache.org luminis-technologies.com bndtools.org amdatu.org bitbucket.org/marrs/apachecon2014-felix-http

×