Effective Web Application Development with Apache Sling
Total Page:16
File Type:pdf, Size:1020Kb
Effective Web Application Development with Apache Sling Effective Web Application Development with Apache Sling Robert Munteanu ApacheCon Core Europe 2015 http://robert.muntea.nu @rombert Who I am DA!"#$ (OSS A%obe Experience Apache Sling Manager Mantis$* Apache Sling M+l+n Connector for Apache Jackrabbit Mantis$* Apache Feli& M+l+n Connector for Review $oar% Speaker.currentSpeaker().interrupt(); http://robert.muntea.nu @rombert Agenda ● Quick facts and figures ● Conceptual ,oundation) ● Building block) ● Building Sling application) http://robert.muntea.nu @rombert Quick fact" and figure" Quick facts and figures http://robert.muntea.nu @rombert Quick fact" and !igure" 200& 200. 200/ 2012 1re-Apache incubation *01 3ersion 7 http://robert.muntea.nu @rombert High-level View o! the Code Source: OpenHub http://robert.muntea.nu @rombert 'evel of activit( Source5 OpenHub Source: statu)7apache7org http://robert.muntea.nu @rombert Community involvement Source: Mar'mail http://robert.muntea.nu @rombert &onceptual foundation" Conceptual ,oundations http://robert.muntea.nu @rombert &onceptual foundation" RES*-based #SGi-powere% Content4%riven Apache Scripting in)ide http://robert.muntea.nu @rombert Apache Open Source Project 1. 2 1 . (eli& Arie) ServiceMi& Commons 9 : 1 2 Geronimo "ackrabbit Derb+ *i'a http://robert.muntea.nu @rombert ,ES--ba"ed ;blog;<0=7html Blog3iewController ;blog; BlogLi)tController ; HomeController ; SlingMainServlet ;blog ;blog;hello-worl% http://robert.muntea.nu @rombert &ontent$driven blog hello-world jcr:content images some-cat.jpg other-cat.jpg http://robert.muntea.nu @rombert &ontent$driven some-cat.jpg - 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 http://robert.muntea.nu @rombert Scripting in"ide "SP http://robert.muntea.nu @rombert Scripting in"ide libs blogapp welcome.jsp welcome json.html http://robert.muntea.nu @rombert )S.i powered ● Provi)ion and %eplo+ bundle) ● Con,igure, regi)ter and loo'up services ● Eventing ● Web Con)ole http://robert.muntea.nu @rombert /uilding bloc " Buil%ing blocks http://robert.muntea.nu @rombert Serving a re0ue"t 8E* /blog;welcome7html ??? ;blog;welcome m+blog;blog7groov+ http://robert.muntea.nu @rombert ,e"ource Type" blog [blogapp/listing] hello-world jcr:content [blogapp/blog/content] images some-cat.jpg other-cat.jpg http://robert.muntea.nu @rombert Script re"olution GET /blog.html Type: blogapp/listing Extension: html Method: GET /libs/blogapp/listing.jsp /libs/blogapp/listing/html.jsp @SlingServlet(resourceTypes=”blogapp/listing”,...) http://robert.muntea.nu @rombert ,e0ue"t selector" GET /blog.rss.xml Type: blogapp/listing Extension: xml Selector: rss Method: GET /libs/blogapp/listing/rss.html http://robert.muntea.nu @rombert ,e"ource Provider" "CR MongoD$ ; ;content; ;content;comment) (S ;log) Ca)sandra http://robert.muntea.nu @rombert 1&, http://robert.muntea.nu @rombert 1&, Implementation" Apache Jackrabbit Oa' http://robert.muntea.nu @rombert /uilding Sling Application" Building Sling Applications http://robert.muntea.nu @rombert 1&, Modeling images some-cat.jpg (ile upload renditions #bservation small.jpg ripple.jpg annotations AC0) initial-review http://robert.muntea.nu @rombert 1&, 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 http://robert.muntea.nu @rombert Everything i" a Re"ource Ever+thing is a resource http://robert.muntea.nu @rombert ,eading from the repo"itor( @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 } } http://robert.muntea.nu @rombert ,eading from the repo"itor( 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(); http://robert.muntea.nu @rombert Another templating language3 ● Secure b+ %e,ault – ASS protection ● Batteries not included to encourage separation o, concern) ● Batural templating b+ blending in HTM05 document) http://robert.muntea.nu @rombert Sightl( <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> http://robert.muntea.nu @rombert Sightly server$"ide logic /* logic.js */ use(function() { return { hi: “hello, world” } }) /* Logic.java */ public class Logic{ public String getHi() { return “Hello, world” } } http://robert.muntea.nu @rombert E4ten"ion" ● Thread Pools and Scheduled Tas') ● I1Dn ● Caching ● Models ● 6ealth Check) ● Eventing http://robert.muntea.nu @rombert SlingQuer( 8et the closest (older parent $(resource).parents("sling:Folder").last(); 8et the secon% child o, each resource $(resource1, resource2).children(":eq(1)"); Find children named en or de $(resource).children("#en, #de") http://robert.muntea.nu @rombert Deployment ● Single executable Jar or War ,ile – the Sling launchpad ● Con,iguration %e,ined in multiple text ,iles, de,ining bundles, con,iguration> variables, boot)trap comman%)> etc http://robert.muntea.nu @rombert Provi"ioning 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 http://robert.muntea.nu @rombert Web Con"ole – Development help http://robert.muntea.nu @rombert Web Con"ole – runtime con!iguration http://robert.muntea.nu @rombert -ooling ● Maven 1lugin) ● Bundle %eployment ● Launchpa% creation ● Maven Archetypes ● IDE *ooling ● Eclip)e ● Netbeans (e&ternalF http://robert.muntea.nu @rombert ,e"ource" ● http:/;sling.apache.org; ● http:/;Gackrabbit7apache.org; ● http:/;www7)lideshare.net;rombertw http://robert.muntea.nu @rombert.