SlideShare una empresa de Scribd logo
1 de 16
REST... with Peace
Content Management with Apache Sling




                 1
The Problem (abstract)
• Store large amounts of different types of content
• Associate meta data to content
• Access control
• Search for stuff
• Get notified on changes
• ...and all that in a lightweight fashion
   sounds familiar, huh? :-)



                                             2
                                                  REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
JCR: Some History
• The content management market was fragmented heavily:
   many vendors, many implementations

• Users were locked in to specific solutions
• Even the most fundamental concept of content management was not
   standardized: the content repository

• The Content Repository for Java API was proposed in JSR 170 by Day
   Software, finalized in 2005

• JCR 2.0 in 2009, API released as an OSGI bundle
   JCR 1.0: http://jcp.org/en/jsr/detail?id=170

  JCR 2.0: http://jcp.org/en/jsr/detail?id=283
                                                  3
                                                      REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
JCR in a Nutshell
• A hierarchical model for storing structured and unstructured content in
   content repositories

• Conformance Level 1:
 • reading, nodes and properties, XPath queries, export
• Conformance Level 2:
 • write, references and referential integrity, access control, import
• Optional features:
 • versioning, transactions, SQL queries, locking, observation
                                        4
                                                    REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
Apache Jackrabbit
• Implements all features of JCR 1.0 and 2.0
• Actively developed, current version is 2.2.4



   http://jackrabbit.apache.org/




• Uses a mix of database (Apache Derby) and filesystem persistence by default


                                        5
                                                 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
a Bit of REST
• It‘s all about resources
• Focused on data, not actions (unlike SOAP, RPC)                                                                                         !")&"#"*+,-$*(



• CRUD via HTTP                                                                                      !"#$%&'"(


                                                                                                                                          !")&"#"*+,-$*(
• Distinguishes between (abstract) resources and
   (concrete) representations

• Probably HTTP‘s most overlooked feature:
   content negotiation based on HTTP headers (e.g. Accept, Accept-Language)

   Roy Fielding‘s thesis: http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm



                                                                     6
                                                                                      REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
Apache Sling
• REST-based framework on top of Apache Jackrabbit
• Apache top-level project since 2009
• OSGI-driven (Apache Felix)                                                      http://sling.apache.org/site/index.html


• Scripting (JSP, SS-JS, Scala), open to other languages
• Can be deployed standalone or inside a servlet container, Launchpad is ready-
   to-run

• Convention-over-configuration
• What it‘s not: a full-featured, „classic“ web application framework
                                          7
                                                     REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
The Content Model
• Everything evolves around resources, nodes and properties
• Sling allows you to store structured or unstructured content anywhere you
   want:

   curl   -F"foo=bar“ http://localhost:8080/repo
   curl   -F“foo=baz“ -F“sling=rocks“ http://localhost:8080/repo
   curl   -F“andAnotherThing=true“ http://localhost:8080/repo/
   curl   -X DELETE http://localhost:8080/repo



• Resource types give structure to content:
   curl -F"sling:resourceType=sling:Folder" $SAURL/repo




                                                          8
                                                                   REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
How Does it Work?
• Data-centric, resource-first approach
• Simply put:

                                                 012$),(3-'$45$
                  %&'$(&)*+(,&$                                                               "&-(&)&1
      !"#$                         "&)*+(,&$     (&)6$'5-&$.12$
                      -.'/$                                                                    '.9*1$
                                                 (&76$8&'/*2$




• There‘s more: wrapping and decorating resources


                                         9
                                               REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
Defining Resource Types
• Two options for defining resource types:
 • Imperative: via Java                       [wcmpp:resource]
                                                - title
                                                                     > nt:folder, sling:Resource
                                                             (string) mandatory
                                                - state        (string) mandatory

 • Declarative:
                                                + changelog        (wcmpp:changelog) autocreated
                                                + tags          (wcmpp:tags) autocreated
                                                + content        (nt:file) version

                                              [wcmpp:tags]             > nt:folder, sling:Resource
   • CND (Compact Node Definition)               +*                (nt:base) = wcmpp:tag

                                              [wcmpp:tag]              > nt:base, sling:Resource


   • XML, JSON (Sling)                        [wcmpp:changelog]
                                                + item
                                                                  > sling:OrderedFolder
                                                              (wcmpp:changelogentry)

                                              [wcmpp:changelogentry] > nt:folder, sling:Resource

• Allows for an exact definition of the          - text       (string) mandatory


   content model                              [wcmpp:image]              > wcmpp:resource




• Supports sub-classing, mixins
                                         10
                                                   REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
URL Decomposition
• Sling has a smart method of decomposing URLs to find the right resource
   representation:

   http://bar.org/repository/path/to/resource.tidy.2.json/in/side


                      resource path          selectors extension suffix


• URL decomposition is Sling‘s way of Content Negotiation
• Advantage: you don‘t need to mess around with HTTP headers

                                      11
                                                REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
Servlets and Scripts
• Two methods of adding servlets and scripts:           (well, truth being told, scripts are servlets as well)



 1. Register as OSGI services
                                            sling.servlet.*:
                                            paths, resourceTypes, selectors,
                                            extensions, methods, prefix
   a. using SCR annotations
                                            * @scr.service interface="javax.servlet.Servlet"
                                            * @scr.property name="sling.servlet.resourceTypes" value="wcmpp/feed"

   b. using code (not Sling-ful)            * @scr.property name="sling.servlet.methods" value="GET"




 2. Store in /apps                          path component derived from resource type,
                                            e.g. a GET handling server-side JavaScript for
                                            resource type cms/images needs to be stored in
                                            /apps/cms/images/GET.esp



• Servlet registration is more fine-grained
                                       12
                                                             REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
Queries
• JCR supports XPath (deprecated with JCR 2.0) and SQL (JCR 2.0) queries
• Via Java:
   Resource resource = request.getResource();
   Session session = repository.login();
   QueryManager qmngr = session.getWorkspace().getQueryManager();
   
 
   Query query = qmngr.createQuery("//element(*, wcmpp:image)", "xpath");
   NodeIterator result = query.execute().getNodes();


• Using the query servlet:
   http://localhost:8080/repo.query.json?statement=//
   *[@jcr:primaryType='wcmpp:image']&property=jcr:content/jcr:mimeType



 • Parameters: offset, rows, property
                                                      13
                                                                     REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
Access Control
• Privilege based access-control model, based on JCR
• Pre-defined privileges are applied to nodes using specific selectors:
 • modifyAce, acl, deleteAcl
                                           You need to register users before setting privileges:
• Privileges:                              curl -F:name=cag -Fpwd=password -FpwdConfirm=password -Fanyproperty=value
                                           http://localhost:8080/system/userManager/user.create.html

 • jcr:read, jcr:write, jcr:all
 • jcr:modifyProperties, jcr:addChildNodes, jcr:modifyAccessControl,
    jcr:nodeTypeManagement, ...
    curl -FprincipalId=cag -Fprivilege@jcr:read=granted http://localhost:8080/test/node.modifyAce.html


                                               14
                                                                   REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
Listening to Events
• A repository sends low-level events:
     •    TOPIC_RESOURCE_ADDED, TOPIC_RESOURCE_REMOVED, TOPIC_RESOURCE_CHANGED,
          TOPIC_RESOURCE_PROVIDER_ADDED


• You‘d typically filter these generic events and transform them into application
         specific events
 /**
  * @scr.component immediate="true"
  * @scr.service interface="org.osgi.service.event.EventHandler"
  * @scr.property name="event.topics" valueRef="org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_ADDED"
  */
                                                             String propPath = (String) event.getProperty(SlingConstants.PROPERTY_PATH);
 public class MyHandler implements EventHandler {
                                                             String propResType = (String) event.getProperty(SlingConstants.PROPERTY_RESOURCE_TYPE);
                                                             if (propPath.startsWith("/tmp/dropbox") && propResType.equals("nt:file")) {
     public void handleEvent(Event event) { }
                                                                final Dictionary<String, Object> props = new Hashtable<String, Object>();
                                                                props.put(EventUtil.PROPERTY_JOB_TOPIC, JOB_TOPIC);
 }
                                                                props.put("resourcePath", propPath);
                                                                Event dropboxJobEvent = new Event(EventUtil.TOPIC_JOB, props);
                                                                eventAdmin.sendEvent(dropboxJobEvent);
                                                             }


                                                                     15
                                                                                         REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
<eop>
        Thank you for your attention.
                Questions?

           Claus Augusti <claus@formatvorlage.de>
           Frontend Architect 1&1 Development Hosting




                      Kudos to the Apache Foundation.You guys *ROCK* :-)

                               16
                                            REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de

Más contenido relacionado

Último

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Último (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Destacado

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Destacado (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

REST... with Peace. Content Management with Apache Sling

  • 1. REST... with Peace Content Management with Apache Sling 1
  • 2. The Problem (abstract) • Store large amounts of different types of content • Associate meta data to content • Access control • Search for stuff • Get notified on changes • ...and all that in a lightweight fashion sounds familiar, huh? :-) 2 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 3. JCR: Some History • The content management market was fragmented heavily: many vendors, many implementations • Users were locked in to specific solutions • Even the most fundamental concept of content management was not standardized: the content repository • The Content Repository for Java API was proposed in JSR 170 by Day Software, finalized in 2005 • JCR 2.0 in 2009, API released as an OSGI bundle JCR 1.0: http://jcp.org/en/jsr/detail?id=170 JCR 2.0: http://jcp.org/en/jsr/detail?id=283 3 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 4. JCR in a Nutshell • A hierarchical model for storing structured and unstructured content in content repositories • Conformance Level 1: • reading, nodes and properties, XPath queries, export • Conformance Level 2: • write, references and referential integrity, access control, import • Optional features: • versioning, transactions, SQL queries, locking, observation 4 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 5. Apache Jackrabbit • Implements all features of JCR 1.0 and 2.0 • Actively developed, current version is 2.2.4 http://jackrabbit.apache.org/ • Uses a mix of database (Apache Derby) and filesystem persistence by default 5 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 6. a Bit of REST • It‘s all about resources • Focused on data, not actions (unlike SOAP, RPC) !")&"#"*+,-$*( • CRUD via HTTP !"#$%&'"( !")&"#"*+,-$*( • Distinguishes between (abstract) resources and (concrete) representations • Probably HTTP‘s most overlooked feature: content negotiation based on HTTP headers (e.g. Accept, Accept-Language) Roy Fielding‘s thesis: http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm 6 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 7. Apache Sling • REST-based framework on top of Apache Jackrabbit • Apache top-level project since 2009 • OSGI-driven (Apache Felix) http://sling.apache.org/site/index.html • Scripting (JSP, SS-JS, Scala), open to other languages • Can be deployed standalone or inside a servlet container, Launchpad is ready- to-run • Convention-over-configuration • What it‘s not: a full-featured, „classic“ web application framework 7 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 8. The Content Model • Everything evolves around resources, nodes and properties • Sling allows you to store structured or unstructured content anywhere you want: curl -F"foo=bar“ http://localhost:8080/repo curl -F“foo=baz“ -F“sling=rocks“ http://localhost:8080/repo curl -F“andAnotherThing=true“ http://localhost:8080/repo/ curl -X DELETE http://localhost:8080/repo • Resource types give structure to content: curl -F"sling:resourceType=sling:Folder" $SAURL/repo 8 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 9. How Does it Work? • Data-centric, resource-first approach • Simply put: 012$),(3-'$45$ %&'$(&)*+(,&$ "&-(&)&1 !"#$ "&)*+(,&$ (&)6$'5-&$.12$ -.'/$ '.9*1$ (&76$8&'/*2$ • There‘s more: wrapping and decorating resources 9 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 10. Defining Resource Types • Two options for defining resource types: • Imperative: via Java [wcmpp:resource] - title > nt:folder, sling:Resource (string) mandatory - state (string) mandatory • Declarative: + changelog (wcmpp:changelog) autocreated + tags (wcmpp:tags) autocreated + content (nt:file) version [wcmpp:tags] > nt:folder, sling:Resource • CND (Compact Node Definition) +* (nt:base) = wcmpp:tag [wcmpp:tag] > nt:base, sling:Resource • XML, JSON (Sling) [wcmpp:changelog] + item > sling:OrderedFolder (wcmpp:changelogentry) [wcmpp:changelogentry] > nt:folder, sling:Resource • Allows for an exact definition of the - text (string) mandatory content model [wcmpp:image] > wcmpp:resource • Supports sub-classing, mixins 10 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 11. URL Decomposition • Sling has a smart method of decomposing URLs to find the right resource representation: http://bar.org/repository/path/to/resource.tidy.2.json/in/side resource path selectors extension suffix • URL decomposition is Sling‘s way of Content Negotiation • Advantage: you don‘t need to mess around with HTTP headers 11 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 12. Servlets and Scripts • Two methods of adding servlets and scripts: (well, truth being told, scripts are servlets as well) 1. Register as OSGI services sling.servlet.*: paths, resourceTypes, selectors, extensions, methods, prefix a. using SCR annotations * @scr.service interface="javax.servlet.Servlet" * @scr.property name="sling.servlet.resourceTypes" value="wcmpp/feed" b. using code (not Sling-ful) * @scr.property name="sling.servlet.methods" value="GET" 2. Store in /apps path component derived from resource type, e.g. a GET handling server-side JavaScript for resource type cms/images needs to be stored in /apps/cms/images/GET.esp • Servlet registration is more fine-grained 12 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 13. Queries • JCR supports XPath (deprecated with JCR 2.0) and SQL (JCR 2.0) queries • Via Java: Resource resource = request.getResource(); Session session = repository.login(); QueryManager qmngr = session.getWorkspace().getQueryManager(); Query query = qmngr.createQuery("//element(*, wcmpp:image)", "xpath"); NodeIterator result = query.execute().getNodes(); • Using the query servlet: http://localhost:8080/repo.query.json?statement=// *[@jcr:primaryType='wcmpp:image']&property=jcr:content/jcr:mimeType • Parameters: offset, rows, property 13 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 14. Access Control • Privilege based access-control model, based on JCR • Pre-defined privileges are applied to nodes using specific selectors: • modifyAce, acl, deleteAcl You need to register users before setting privileges: • Privileges: curl -F:name=cag -Fpwd=password -FpwdConfirm=password -Fanyproperty=value http://localhost:8080/system/userManager/user.create.html • jcr:read, jcr:write, jcr:all • jcr:modifyProperties, jcr:addChildNodes, jcr:modifyAccessControl, jcr:nodeTypeManagement, ... curl -FprincipalId=cag -Fprivilege@jcr:read=granted http://localhost:8080/test/node.modifyAce.html 14 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 15. Listening to Events • A repository sends low-level events: • TOPIC_RESOURCE_ADDED, TOPIC_RESOURCE_REMOVED, TOPIC_RESOURCE_CHANGED, TOPIC_RESOURCE_PROVIDER_ADDED • You‘d typically filter these generic events and transform them into application specific events /** * @scr.component immediate="true" * @scr.service interface="org.osgi.service.event.EventHandler" * @scr.property name="event.topics" valueRef="org.apache.sling.api.SlingConstants.TOPIC_RESOURCE_ADDED" */ String propPath = (String) event.getProperty(SlingConstants.PROPERTY_PATH); public class MyHandler implements EventHandler { String propResType = (String) event.getProperty(SlingConstants.PROPERTY_RESOURCE_TYPE); if (propPath.startsWith("/tmp/dropbox") && propResType.equals("nt:file")) { public void handleEvent(Event event) { } final Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(EventUtil.PROPERTY_JOB_TOPIC, JOB_TOPIC); } props.put("resourcePath", propPath); Event dropboxJobEvent = new Event(EventUtil.TOPIC_JOB, props); eventAdmin.sendEvent(dropboxJobEvent); } 15 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de
  • 16. <eop> Thank you for your attention. Questions? Claus Augusti <claus@formatvorlage.de> Frontend Architect 1&1 Development Hosting Kudos to the Apache Foundation.You guys *ROCK* :-) 16 REST... with Peace - Content Management with Apache Sling / Claus Augusti / claus@formatvorlage.de

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n