Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Effective Web Application Development with Apache Sling

827 views

Published on

Apache Sling is an innovative web framework built on top of the Java Content Repository (JCR), that uses OSGi for its component model and fosters RESTful application design.

This talk shows how Sling integrates various standard-based technologies, like OSGi and the Content Repository API for Java to create a coherent framework for web application development. We will walk through the development of a simple application with minimal effort and demonstrate how to productize the resulting application.

We will pay special attention to some approaches which are not yet part of mainstream development, such as using OSGi for dependecy injection and JCR for persistence.

Published in: Software
  • My friend sent me a link to to tis site. This awesome company. They wrote my entire research paper for me, and it turned out brilliantly. I highly recommend this service to anyone in my shoes. ⇒ www.HelpWriting.net ⇐.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Effective Web Application Development with Apache Sling

  1. 1. http://robert.muntea.nu @rombert Effective Web Application Development with Apache Sling Effective Web Application Development with Apache Sling Robert Munteanu ApacheCon Core Europe 2015
  2. 2. http://robert.muntea.nu @rombert Who I am  $DAYJOB  Adobe Experience Manager  Apache Sling  Apache Jackrabbit  Apache Felix  FOSS  Apache Sling  MantisBT  Mylyn Connector for MantisBT  Mylyn Connector for Review Board Speaker.currentSpeaker().interrupt();
  3. 3. http://robert.muntea.nu @rombert Agenda ● Quick facts and figures ● Conceptual foundations ● Building blocks ● Building Sling applications
  4. 4. http://robert.muntea.nu @rombert Quick facts and figures Quick facts and figures
  5. 5. http://robert.muntea.nu @rombert Quick facts and figures 2007 incubation 2009 TLP 2014 Version 7 200x Pre-Apache
  6. 6. http://robert.muntea.nu @rombert High-level View of the Code Source: OpenHub
  7. 7. http://robert.muntea.nu @rombert Level of activity Source: OpenHub Source: status.apache.org
  8. 8. http://robert.muntea.nu @rombert Community involvement Source: Markmail
  9. 9. http://robert.muntea.nu @rombert Conceptual foundations Conceptual foundations
  10. 10. http://robert.muntea.nu @rombert Conceptual foundations REST-based Content-driven OSGi-powered Scripting insideApache
  11. 11. http://robert.muntea.nu @rombert Apache Open Source Project 4 Aries 1 ServiceMix 7 Commons 17 Felix 3 Geronimo 6 Jackrabbit 1 Derby 2 Tika
  12. 12. http://robert.muntea.nu @rombert REST-based /blog/ /blog/{0}.html / BlogViewController BlogListController HomeController SlingMainServlet/ /blog /blog/hello-world
  13. 13. http://robert.muntea.nu @rombert Content-driven blog hello-world images jcr:content some-cat.jpg other-cat.jpg
  14. 14. http://robert.muntea.nu @rombert Content-driven - jcr:primaryType = app:asset - jcr:title = Some Cat - jcr:description = A longer description of this picture of a cat - jcr:created = 2014-06-03T00:00:00.000+02:00 - jcr:lastUpdated = 2014-06-03T11:00:00.000+02:00 - tags = [Animal, Cat, Color] - width = 400 - height = 600 some-cat.jpg
  15. 15. http://robert.muntea.nu @rombert Scripting inside JSP
  16. 16. http://robert.muntea.nu @rombert Scripting inside libs blogapp welcome.jsp welcome json.html
  17. 17. http://robert.muntea.nu @rombert OSGi powered ● Provision and deploy bundles ● Configure, register and lookup services ● Eventing ● Web Console
  18. 18. http://robert.muntea.nu @rombert Building blocks Building blocks
  19. 19. http://robert.muntea.nu @rombert Serving a request GET /blog/welcome.html /blog/welcome myblog/blog.groovy ???
  20. 20. http://robert.muntea.nu @rombert Resource Types blog [blogapp/listing] hello-world images jcr:content [blogapp/blog/content] some-cat.jpg other-cat.jpg
  21. 21. http://robert.muntea.nu @rombert Script resolution GET /blog.html Type: blogapp/listing Extension: html Method: GET /libs/blogapp/listing/html.jsp @SlingServlet(resourceTypes=”blogapp/listing”,...) /libs/blogapp/listing.jsp
  22. 22. http://robert.muntea.nu @rombert Request selectors GET /blog.rss.xml Type: blogapp/listing Extension: xml Selector: rss Method: GET /libs/blogapp/listing/rss.html
  23. 23. http://robert.muntea.nu @rombert Resource Providers JCR MongoDB FS Cassandra / /content/ /content/comments /logs
  24. 24. http://robert.muntea.nu @rombert JCR
  25. 25. http://robert.muntea.nu @rombert JCR Implementations Apache Jackrabbit Oak
  26. 26. http://robert.muntea.nu @rombert Building Sling Applications Building Sling Applications
  27. 27. http://robert.muntea.nu @rombert JCR Modeling images File uploadsome-cat.jpg renditions small.jpg ripple.jpg Observation annotations initial-review ACLs
  28. 28. http://robert.muntea.nu @rombert JCR Modeling etc rendition ripple - orientation = /etc/rendition/ripple/options↵ /orientation/vertical - antialiasing = true - edges = /etc/rendition/ripple/options/↵ edges/wrap - wave type = /etc/rendition/ripple/options/↵ wave_type/simple - period = 20 - amplitude = 5
  29. 29. http://robert.muntea.nu @rombert Everything is a Resource Everything is a resource
  30. 30. http://robert.muntea.nu @rombert Reading from the repository @SlingServlet(resourceTypes = "blogapp/listing", extensions = "xml", methods = "GET") public class RSSFeedServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { // actual implementation } }
  31. 31. http://robert.muntea.nu @rombert Reading from the repository Resource res = request.getResource(); ValueMap properties = ↵ res.adaptTo(ValueMap.class); String title = properties.get(“jcr:title”,↵ “Missing”); Post post = res.adaptTo(Post.class); title = post.getTitle();
  32. 32. http://robert.muntea.nu @rombert Another templating language? ● Secure by default – XSS protection ● Batteries not included to encourage separation of concerns ● Natural templating by blending in HTML5 documents
  33. 33. http://robert.muntea.nu @rombert Sightly <h4 class="card--${card.itemprop['customStyle']}"> ${card.itemprop['description'] </h4> <div data-sly-list=”${resource.listChildren}”> <article data-sly-resource=”${childResource}”/> </div> <section data-sly-include=”template.html”/> <div data-sly-use.logic=”logic.js”> ${logic.hi} </div>
  34. 34. http://robert.muntea.nu @rombert Sightly server-side logic /* logic.js */ use(function() { return { hi: “hello, world” } }) /* Logic.java */ public class Logic{ public String getHi() { return “Hello, world” } }
  35. 35. http://robert.muntea.nu @rombert Extensions ● Thread Pools and Scheduled Tasks ● I18n ● Caching ● Models ● Health Checks ● Eventing
  36. 36. http://robert.muntea.nu @rombert SlingQuery Get the closest Folder parent $(resource).parents("sling:Folder").last(); Get the second child of each resource $(resource1, resource2).children(":eq(1)"); Find children named en or de $(resource).children("#en, #de")
  37. 37. http://robert.muntea.nu @rombert Deployment ● Single executable Jar or War file – the Sling launchpad ● Configuration defined in multiple text files, defining bundles, configuration, variables, bootstrap commands, etc
  38. 38. http://robert.muntea.nu @rombert Provisioning model [feature name=main] [variables] io.version=1.4 [configurations] org.apache.jackrabbit.....SegmentNodeStoreService name="Default NodeStore" repository.home="sling/oak/repository" [artifacts startLevel=5] commons-io/commons-io/${io.version}/jar commons-fileupload/commons-fileupload/1.3.1/jar
  39. 39. http://robert.muntea.nu @rombert Web Console – Development help
  40. 40. http://robert.muntea.nu @rombert Web Console – runtime configuration
  41. 41. http://robert.muntea.nu @rombert Tooling ● Maven Plugins ● Bundle deployment ● Launchpad creation ● Maven Archetypes ● IDE Tooling ● Eclipse ● Netbeans (external)
  42. 42. http://robert.muntea.nu @rombert Resources ● http://sling.apache.org/ ● http://jackrabbit.apache.org/ ● http://www.slideshare.net/rombertw

×