Upload
carsten-ziegeler
View
12.297
Download
2
Tags:
Embed Size (px)
Citation preview
& OSGi, Scripting RESTWeb Development with Apache SlingCarsten Ziegeler | Day [email protected]
2
About Carsten Ziegeler
2
• Member of the Apache Software Foundation– Sling, Felix, Cocoon, Portals, Sanselan, Excalibur,
Incubator– PMC: Felix, Portals, Cocoon, Incubator, Excalibur (Chair)
• RnD Team at Day Software• Article/Book Author, Technical Reviewer, Speaker• JSR 286 Spec Group (Portlet API 2.0)
3
Agenda– ApacheSling1 Motivation2 Content and JCR3 Web and REST4 Scripting5 OSGi6 Outlook
3
4
1 Motivation1 Motivation
4
5
• Publish huge amount of information– Different types– Highly dynamic– Different output formats
• Web 2.0 ready– Collaboration and integration
• Fast changing requirements– Rapid prototyping and development– Dynamic, extensible but maintainable
5
WebChallenges
6
• Publish huge amount of information– Different types– Highly dynamic– Different output formats
• Web 2.0 ready– Collaboration and integration
• Fast changing requirements– Rapid prototyping and development– Dynamic, extensible but maintainable
6
WebChallenges
JCR
RESTROA
OSGi
Scripting
7
• Web framework• Java content repository (JCR)• ROA / REST• Scripting inside• OSGi• Apache Open Source project
– http://incubator.apache.org/sling
7
5th Winner JAX Innovation Award 2008
ApacheSling – TheFun isBack
8
: Example ApacheSling Powered Site
9
2 Content/JCR2 Content/JCR
9
10
Content is Important• Apache Sling makes handling content easy• Java content repository (JCR)
– Several different sources possible
• Direct mapping: URL -> content– Configurable– http://myserver.domain/products/sling.html
• Flexible rendering
10
11
Content Repository
11
• Generic application data store• Structured and unstructured content• Support small and large-scale data• Locking, transactions, versioning, observation
and searching
12
JCR – JSR 170• Content Repository for Java technology API• (Java) Standard
– Supported by many vendors– Used by many products and projects– Several open source solutions
• How do you connect to a CR?• How do you interact with a CR?
12
JSR 283 – Version 2.0 – scheduled for 2009
13
SampleApplication• Digital Asset Management
– Hierarchical storage of pictures– Upload– Tagging– Searching– Automatic thumbnail generation
13
Poor man's flickr...
14
Content Repository Features• Hierarchical content
– Nodes and properties
• Structured– Nodetypes and typed properties
• And/or unstructured• Fine and coarse-grained
14
15
SampleContent Structure
15
Basel
City
Europe
Travel Family
Amsterdam
2007
Weddings
2008
Photo
Photo
Photo
Photo
16
Content Repository Features• Query (XPath, SQL)• Export/Import (XML)• Referential Integrity• Authentication• Access Control• Versioning• Observation• Locking and Transactions (JTA)
16
17
Comparison• File System
– Hierarchical, unstructured
• Database– Structured– Referential integrity, transactions
• Content Repository– Advantages of a FS and a database– Plus observation, versioning etc.
17
18
) (Content Repository JCR – JSR 170
18
19
TheRepository Model• Repository: one (or more) workspaces• Workspace contains a tree of items• Item: Node or property• Nodes provide the content structure
– May have children
• Actual data is stored as values of properties• Types and namespaces!
Implementation of JCR 19
20
C o n te n t R e p o s i to r y
W o r k s p a c e A
ab
c
i
gh
j k
= Node
= Property
Root
ed
6.02x1023
„Once upon a time..“ -25
true
Nodesand Properties
Implementation of JCR
20
21
ApacheJackrabbit• JSR 170 reference implementation• Apache TLP since 2006• Several releases• JCR 2.0 RI later this year• Additional components
22
Leverage thestandard node types• Type hierarchy • Content hierarchy
22
nt:hierarchyNode
nt:folder
nt:file
nt:linkedFile
nt:resource
23
: Modeling Content Types
23
my:resource > nt:resource- width, height (long)- format (string)
my:photo > nt:file- description (string)- location (string)- tags (string[])
my:album > nt:folder- description (string)- date (date)
my:tag- name (string)- description (string)
24
: Modeling Content Hierarchies
24
Basel
City
Europe
Travel Family
Amsterdam
2007
Weddings
2008
Photo
Photo
Photo
Photo
25
3 ROA and REST3 ROA and REST
25
26
ResourceOriented Architecutre• Piece of information is a resource
– News entry, product, photo...– (Descriptive) URI
• Stateless– Request contains all relevant information
• Use HTTP– Methods (GET, POST) for operations
26
27
REST with ApacheSling• Default behaviour for GET• Creating/Updating content through POST
– Default behaviour
• Additional operations/method• Resource-first request processing!
27
28
Resource• Sling's abstraction of the thing addressed by
the request URI– Usually mapped to a JCR node– File system, database...
• Properties of resources– Path, e.g. JCR Item path– Type, e.g. JCR node type– Metadata, e.g. last modification date
28
29
- Resource first Request Processing
/products/sling.print.a4.html
Resource Path Selectors Extension
29
• URI Decomposition••
– Resource and representation
• Content retrieved from repository• Rendering based on content type
30
Basic Request Processing Steps• URI decomposition• Resolve the resource
– Source: request URI
• Resolve rendering script– Source: resource type– Scripts are wrapped by a generic script servlet
• Create rendering chain– Configurable (servlet) filters– Rendering servlet
• Invoke rendering chain30
31
ResourceResolver• Gateway for resources• Abstracts the path resolution• Abstracts access to the persistence layer(s)• Configurable
– Mappings (Multi-site mgmt, beautify paths)
• Tasks:– Finding Resources– Getting Resources– Simplification of Query Execution
31
32
- Resource First Request Processing
Resource Resolver
Script Resolver
Script
request
response
Resource (resource type)
32
33
4 Scripting4 Scripting
33
34
Scripting Inside• It's your choice
– JSP, servlet, ESP– javax.script (Apache BSF)– own script handlers
• Scripts stored in OSGi bundles or repository
• Scripts are searched at configurable locatiosn
• Default servlets (or scripts)– JSON, XML– Registerable– Fallback / Last Ressort
34
35
Script Resolving I• Path to script is built from ...
– Configured search paths ( /apps, /libs )– Resource type converted to path ( my/photo )– Selector string ( print/a4)– Request method & MIME Type
• GET --> Request URL Extension ( html )• else --> Method Name ( POST, PUT, ... )
35
36
Script Resolving Example• URI: /products/sling.print.a4.html• Resource: /products/sling• Resource Type: myapp:product• Script for GET:
– /apps/myapp/product/print/a4/html.*
• Script for POST:– /libs/myapp/product/print/a4/POST.*
36
37
Script Resolving II• Scripts are searched by best matching
– /apps/myapp/product/print/a4/html.*– /libs/myapp/product/print/a4/html.*– /apps/myapp/product/html.*– /libs/myapp/product/html.*
• Resource has a type and a super type– Script inheritance– Default script (JSON...)
37
38
Powerful Scripting with Includes I
38
Resource Resolver
Script Resolver
Script
Request: /albums/travel.html
response
Resource, resource type: my:Album
Script: /libs/my/Album/html.jsp
Generates main htmlsling:include with selectors
39
Script (/libs/my/Album/html.jsp)
Powerful Scripting with Includes II
<sling:include resource="<%= current %>" addSelectors="tree"/>…
Script Resolver
Request: /albums/travel.html
response
Script
Script: /libs/my/Album/tree.html.jsp
40
5 OSGi5 OSGi
40
41
: RuntimeFramework Requirements• Modularization – Modularity is key
– Manage growing complexity– Support dynamic extensibility
• Lifecycle Management• Configuration Management• Dependency Management
– Modules– Services
• Dynamic System Changes41
42
.. .. OSGi in 5 ehm 1Minute• Specification of a framework• Module concept (bundles) with lifecycle• Simple but powerful component model
– Lifecycle management– Publish/Find/Bind service registration
• Dynamic!• Uses the concept of bundles
42
43
AnOSGi Bundle• Leverages the Java packaging mechanism:
JAR files• Contains Java classes and resources• Additional meta-data
– Implicit dependencies to other bundles– Package imports/exports
43
44
Services• OSGi offers an API to register services
– Service is registered by its interface name(s)– Implementation is bundle private– Several components for same service possible
(from different bundles)
• Bundles can query services– By interface names– With additional filters
44
45
TheOSGi Core• Minimal but sufficient API for services
– Minimal overhead: Good for simple bundles– No support for component management– No support for configuration management– Requires sometimes a lot of Java coding
• Additional (optional) OSGi extensions– Declarative Service Specification – Configuration Admin Service Specification
45
Dynamic Services• OSGi Declarative Services Specification
– XML Configuration • Contained in bundle
– Publishing services– Consuming services
• Policy (static,dynamic), cardinality (0..1, 1..1, 0..n)
– Default configuration– Service Lifecycle management
• Various Implementations– Apache Felix SCR 46
Config Admin andMetatype• OSGi Config Admin
– Configuration Manager– Persistence storage– API to retrieve/update/remove configs– Works with Declarative Services
• OSGi Metatype Service– Description of bundle metadata– Description of service configurations
• Various Implementations– Apache Felix 47
ApacheFelix• Top-level project (March 2007)
• Healthy and diverse community• OSGi R4 (R4.1) implementation
– Framework (frequent releases)– Services (continued development)– Moving towards upcoming R4.2
• Tools– Maven Plugins, Web Console, iPojo
• New sub project– Karaf : Runtime Environment (Service Mix)
48
ApacheSling Runtime• Uses Apache Felix• Runtime: Apache Sling Launchpad
– Might be merged with Felix Karaf
• Two flavours– Standalone Java Application– Web application
• But Sling can be deployed in any OSGi framework!
49
50
StandaloneJavaApplication• One single executable JAR file• Small Launcher• Starts OSGi Framework (Apache Felix)• Uses Jetty in an OSGi Bundle
50
51
WebApplication• Extends Standalone Application
– Replaces Command Line Support with a Servlet
• Uses a Bridge to connect Sling to the Servlet Container
51
52
Factsabout Sling• Sling API
– No reference to JCR API– Uses resource abstraction
• Highly modular and runtime configurable– OSGi framework– Everything is a OSGi bundle
• ConfigAdmin, Declarative Services, Metatype• Felix Web Console
52
53
Modules
scripting/*
scripting/api
jcr/resource
jcr/jackrabbit
jcr/api sling/core
Sling API
sling/servlets-* sling/threads
sling/i18n
sling/adapter
sling/servlet-resolver
sling/event
sling/scheduler
sling/bundleresource
commons/* Maven 2 Plugins osgi/*
53
54
6 Outlook6 Outlook
54
55
Current State• Apache Sling is in the Apache Incubator• Second Release: RSN! :)• Demo Applications• Increasing interest -> Increasing community• Graduating from the incubator to a TLP
– sling.apache.org
55
56
Development• Easy to get started
– Add content, add script, add more content
• Very flexible and dynamic• Tooling
– Maven Plugins– Apache Felix SCR Plugin– Additional Sling Plugins– But not tied to Maven of course :)
56
57
...And remember• (Nearly) Everything is content
– Application content– HTML pages, CSS and JavaScript files, static
images– Documentation, resource bundles, etc.– With versioning, export/import, full text search,
etc.
57
58
• Publish huge amount of information– Different types– Highly dynamic– Different output formats
• Web 2.0 ready– Collaboration and integration
• Fast changing requirements– Rapid prototyping and development– Dynamic, extensible but maintainable
58
...Manage theWebChallenges
59
... : with ApacheSling Stateof theArt• Modularity and dynamics (OSGi)• Content Management (JCR)• Resource oriented architecture (REST)• Scripting inside
59
60
!ApacheSling – TheFun isBack• Web Framework• Java Content Repository• REST• Scripting inside• OSGi• Apache Open Source project• Check it out today!
60
61
!Thanks for your attention
Q&A