63
Webmardi - 07.07.2015 at Lausann e

Content-centric architectures - case study : Apache Sling

Embed Size (px)

Citation preview

Page 1: Content-centric architectures - case study : Apache Sling

Webmardi - 07.07.2015

at Lausanne

Page 2: Content-centric architectures - case study : Apache Sling

Content-centric web architectures

Case study : Apache Sling

Page 3: Content-centric architectures - case study : Apache Sling

Fabrice HongMatthieu CornutTitouan Galopin

AEM team AEM team

Page 4: Content-centric architectures - case study : Apache Sling

Agenda

1. What is a CMS?2. Content-centric design3. Sling content delivery4. How Sling uses the JCR5. Demo

Page 5: Content-centric architectures - case study : Apache Sling

1.What is a CMS?

Page 6: Content-centric architectures - case study : Apache Sling

ContentManagement

System

Page 7: Content-centric architectures - case study : Apache Sling

Editable by the author=

Not managed by developer

Page 8: Content-centric architectures - case study : Apache Sling

The aim: let the authormanage as much things

as possible

Page 9: Content-centric architectures - case study : Apache Sling

What is really editableby the author?

Page 10: Content-centric architectures - case study : Apache Sling

The minimal CMS

Page 11: Content-centric architectures - case study : Apache Sling

The minimal CMS

Editable pages

Content edition

Page 12: Content-centric architectures - case study : Apache Sling

The minimal CMS

Editable pages

Content edition

id title body date

1 Accueil Bienvenue ... 07-07-15

... ... ... ...

Page 13: Content-centric architectures - case study : Apache Sling

The classical CMS

Page 14: Content-centric architectures - case study : Apache Sling

The classical CMSEditable pages organisedin categories

Content organisation

Page 15: Content-centric architectures - case study : Apache Sling

The classical CMSEditable pages organisedin categories

Content organisation

id parent title body date

1 NULL Accueil Bienvenue! 07-07-15

2 1 Sous-page ... 07-07-15

Page 16: Content-centric architectures - case study : Apache Sling

The enterprise CMS

Page 17: Content-centric architectures - case study : Apache Sling

The enterprise CMS

Editable types of content

Content type composition

Page 18: Content-centric architectures - case study : Apache Sling

The enterprise CMS

Editable types of content

Content type composition

Implementation ? Hum ...

Page 19: Content-centric architectures - case study : Apache Sling

The ideal way: nodes

Most generic storage method

Page 20: Content-centric architectures - case study : Apache Sling
Page 21: Content-centric architectures - case study : Apache Sling

when to use it ?

2. Content-centric design

Page 22: Content-centric architectures - case study : Apache Sling

structure

data

Who is the leader ?

structure

data

Page 23: Content-centric architectures - case study : Apache Sling
Page 24: Content-centric architectures - case study : Apache Sling
Page 25: Content-centric architectures - case study : Apache Sling

Back to IT

Predefine the structure Let the structure emerge

or

Page 26: Content-centric architectures - case study : Apache Sling

Ask yourself

Is it known in advance ?● The final result● The evolution

o consumerso the interfaceo the scale

Page 27: Content-centric architectures - case study : Apache Sling

Caching - ajax injection

Caching - SSI

CDN Caching - ajax injection

Add servers

Thin / Thick client

CDN Caching - ESI

! page loading, SEO

! dev env.

! business logic, SEO

! server price

Visitor number

Visitor location

Interactivity

Slow Backend integration

Evolutions Solutions Down sides

Page 28: Content-centric architectures - case study : Apache Sling

moreover, conditions are constantly evolving...

The right balance is not easy to choose

Page 29: Content-centric architectures - case study : Apache Sling

STRUCTURE FIRST in an impredictible ecosystem

or, how should we extend the house ?

Page 30: Content-centric architectures - case study : Apache Sling
Page 31: Content-centric architectures - case study : Apache Sling

DATA FIRST can be ambivalent

Page 32: Content-centric architectures - case study : Apache Sling

Apache Slinga content-centric web framework

Page 33: Content-centric architectures - case study : Apache Sling

Some history about Apache Sling● Initially : internal framework powering CQ5 (WCMS from Day Software)● 2007 - Donated to Apache Software foundation● 2009 - Graduated as Apache top level project● 2010 - Day Software aquired by Adobe. CQ5 renamed to AEM● Sling still used by AEM

Page 34: Content-centric architectures - case study : Apache Sling

Java Content Repository (JCR)

Stack

Apache Sling

Java Runtime Environement

Servlet Engine App Server (optional)OS

GI

Fra

mew

ork CMS App

Apache Felix

Apache Jackrabbit

Page 35: Content-centric architectures - case study : Apache Sling

And how you *should* leverage it

3. How Sling uses the JCR

Page 36: Content-centric architectures - case study : Apache Sling

Before all : some specs

Page 37: Content-centric architectures - case study : Apache Sling

A CMS data structure

Hierarchies can store nearly every logic in a natural and readable way

Page 38: Content-centric architectures - case study : Apache Sling

JCR features

“Content Repositories are the best of databases and file systems”

JCR 1.0 : JSR-170JCR 2.0 : JSR-283

Page 39: Content-centric architectures - case study : Apache Sling

How do Sling uses the JCR ?

Page 40: Content-centric architectures - case study : Apache Sling

titleauthor

news list content

navigation

footer

edit

Example : online newspaper website

Page 41: Content-centric architectures - case study : Apache Sling

Services

Controller

Templates

Url MappingUrl Mapping

● Mapping news?id=23 -> newsController

● Get / store content from database

● Map content to template vars

● Select template

● CRUD

● Access Control Management

● Versioning

Services

Controller

Templates

DatabaseDatabase

Server

Static

Standard web framework

Web Client

In Sling, it will be entirely in database

Page 42: Content-centric architectures - case study : Apache Sling

Typical content

● Page organisation● Internal page structure● Authoring content

Page 43: Content-centric architectures - case study : Apache Sling

But also:

Validation rules

Rendition scripts Jobs

Java

Page 44: Content-centric architectures - case study : Apache Sling

The answer to life, the universe and everything

The JCR

In a Sling application :● Externalize what does not require java skills

o rapid testing / developing / demoso visualisation (in opposition to JAR content)

● Leverage JCR features

Page 45: Content-centric architectures - case study : Apache Sling

Practical for development

news-list

news1news2

Filesystemmappable

● Human readable● IDE friendly● VCS friendly

Page 46: Content-centric architectures - case study : Apache Sling

JCR (Apache Jackrabbit)

And Sling ?

Apache Sling

Java Runtime Environement

Servlet Engine App Server (optional)OS

GI

Fra

mew

ork CMS App

events, search, versioning, access control

?

Page 47: Content-centric architectures - case study : Apache Sling

How a Sling application *should* interact with the JCR ?

4. Sling Content Delivery

Page 48: Content-centric architectures - case study : Apache Sling

Services

Controller

Templates

Url MappingUrl Mapping

Services

Controller

Templates

Database

Server

Static logic

Standard webapp

Web Client

Database

Page 49: Content-centric architectures - case study : Apache Sling

Server

Web Client

REST API

binding

Sling idea

Java Content Repository (JCR)

REST:● CRUD ops. for each nodes

○ GET, POST, PUT, DELETE ● Cacheable● Stateless / scalable

Templates /ComponentsContent

Page 50: Content-centric architectures - case study : Apache Sling

Server

Web Client

REST API

binding

Sling idea

Java Content Repository (JCR)

Templates /ComponentsContent

Content first !

website/news.jsp?id=341

website/news/webmardi/2015_07_07-sling.html

Page 51: Content-centric architectures - case study : Apache Sling

How to write in database ?

<form method="POST"><input type="text" name="title"/>

<input type="text" name="content"/>

<input type="submit" name="save"/>

</form>

Security ? Binding Logic ?

Access Control Management

Event observation

Servlet / Filters

OSGI Services

● REST force server side simplicity● Boilerplate layers replaced by safeguards● Everything that is externalized in JCR is interoperable

Page 52: Content-centric architectures - case study : Apache Sling

The client chose the representation

Page 53: Content-centric architectures - case study : Apache Sling

content

news-list

news1

news2

components

news

news.jsp

.content.xml

titlecontentof type

refers

Server

news-list/news2.htmlnews-list/news2.small.html

Content representation

small.jsp

Web Client

path selector extension (additional discriminator for servlet)

Sling rendering resolution

Page 54: Content-centric architectures - case study : Apache Sling

news.esp

<div class="newsTitle"><%= currentNode.title %>

</div><div>

<div class="newsContent">

<%= currentNode.content %>

</div>

<% sling.include("./author", "replaceSelectors=quickLink") %>

</div>

Page 55: Content-centric architectures - case study : Apache Sling

Scriptable in

● JSP● ESP● Groovy● Ruby● Velocity

Page 56: Content-centric architectures - case study : Apache Sling

More resilient to external evolution ?

Page 57: Content-centric architectures - case study : Apache Sling

Caching - ajax injection

Caching - SSI

CDN Caching - ajax injection

Add servers

Thin / Thick client

CDN Caching - ESI

! page loading, SEO

! dev env.

! business logic, SEO

! server price

Visitor number

Visitor location

Interactivity

Slow Backend integration

Evolutions Solutions Down sides

Page 58: Content-centric architectures - case study : Apache Sling

Component inclusion

newsList

news1

news2

Application Server Web ServerC

DN

other content

Switzerland

Cach

e

China

Application includes Server side includes Ajax includes

ajax or html includeajax or html include

Page 59: Content-centric architectures - case study : Apache Sling

Conditions for ambivalence

Must be flexible on:

where components are included

how to the components is represented

content-centric -> independence of components :each component is responsible for loading its data and dependencies

newsList/news1.htmlnewsList/news1.jsonnewsList/news1.small.html

Page 60: Content-centric architectures - case study : Apache Sling

Extreme example

Sling Dynamic Include allows to switch dynamically between :● Server side include● Edge side include● Ajax include

Page 61: Content-centric architectures - case study : Apache Sling

5. Demo

Page 62: Content-centric architectures - case study : Apache Sling

Summary

● Structure first or Data firsto One shot project / Evolutive systemo relation with agilty ?

● Go along with the technologyo leverage JCR featureso leverage sling REST approach

Page 63: Content-centric architectures - case study : Apache Sling