Webscripts in an Alfresco REST Architecture
-
Upload
alfresco-software -
Category
Technology
-
view
11.629 -
download
1
description
Transcript of Webscripts in an Alfresco REST Architecture
Using Web Scripts in aREST-based Architecture
Richard ImSolutions Engineer
www.alfresco.com
See the recorded webinar here:http://snurl.com/webscripts
* What is REST? * What is a Web Script? * Common uses of Web Scripts * Review a Web Script for UI components * Review a Web Script for data retrieval * Sample.
Agenda:
See the recorded webinar here:http://snurl.com/webscripts
Acronym for: Representational State Transfer
● An architectural style. Systems following these principles referred to as 'RESTful'
● Resources are URL-Addressable. Easy utilizing HTTP Methods: GET, POST, PUT, DELETE.
● “REST strictly refers to a collection of network architecture principles which outline how resources are defined and addressed.
● The term is often used in a looser sense to describe any simple interface which transmits domain-specific data over HTTP without an additional messaging layer such as SOAP or session tracking via HTTP cookies.”
What is REST?
See the recorded webinar here:http://snurl.com/webscripts
Key Rest Principles
● Application state and functionality are abstracted into resources
● Every resource is uniquely addressable using a universal syntax for use in hypermedia links
● All resources share a uniform interface for the transfer of state between client and resource, consisting of
•A constrained set of well-defined operations
•A constrained set of content types, optionally supporting code on demand
● A protocol which is: Client-server, Stateless, Cacheable, Layered
The Principles of REST
See the recorded webinar here:http://snurl.com/webscripts
REST v. SOAP WS
● Cacheable representations, leading to improved response time.
● Less dependencies: i.e. no SOAP
● No need for a resource directory
● More scalable. No session state maintenance required across servers.
● Exchange of Resources, rather than Methods – Nouns v. Verbs
REST Web Services
See the recorded webinar here:http://snurl.com/webscripts
REST & Alfresco = Web Scripts
● From 2.1 onward – ideally to open it up to more channels: Office, Portal, Websites
● Ease of use and lightweight: Javascript, Templates
● Multi use: create your own API, new UI components, widgets, expose features.
● Cross language and cross platform data.
● MVC – Alfresco Repository (Model), Javascript (Controller), Freemarker (View).
Alfresco Web Scripts
See the recorded webinar here:http://snurl.com/webscripts
Alfresco Web Scripts
Web Script REST DispatcherWeb Script REST Dispatcher
Web Script REST InfrastructureWeb Script REST Infrastructure
ContentServices
RenditionServices FreeMarker
RepositorySearch
NavigationSecurity
HTML, ATOM, RSS, JSONURL
JavaScript
2
3
5
4
61
● Content
● Metadata
● User Interface Components
● Queries
See the recorded webinar here:http://snurl.com/webscripts
What makes a Web Script?
● XML Descriptor file: define your resource
● Javascript: Controller with access to various content services
• Search: Search the repository and format the result any way needed.
• Create: Add content into the repository.
• Navigate: See what is in the repository
• Security: Make sure you have the permissions to access
● Freemarker: Representation/Response, format can be XML, JSON, HTML
Alfresco Web Scripts cont...
See the recorded webinar here:http://snurl.com/webscripts
XML Descriptor: docActions.get.desc.xml
● XML Descriptor file: define your resource and HTTP method (naming convention)
● url: Define your resource and any parameters needed to execute
● Level of authentication required to run
● Optionally define whether a transaction is required.
● Can define a default format to fall back to incase format is not defined when executing.
Alfresco Web Scripts Example
<webscript> <shortname>Document Actions (Office Add-In)</shortname> <description>Used by the Office Add-In to perform actions on managed documents</description> <url>/office/docActions</url> <authentication>user</authentication> <transaction>required</transaction></webscript>
See the recorded webinar here:http://snurl.com/webscripts
// Client has requested server-side action/* Inputs */var runAction = args.a;
/* Outputs */var resultString = "Action failed", resultCode = false;
// Is this action targetting a document?var docNodeId = args.n;if ((docNodeId != "") && (docNodeId != null)){ var docNode = search.findNode("workspace://SpacesStore/" + docNodeId); if (docNode != null && docNode.isDocument) { try { if (runAction == "makepdf") { resultString = "Could not convert document"; var nodeTrans = docNode.transformDocument("application/pdf"); if (nodeTrans != null) { resultString = "Document converted"; resultCode = true; } }...
Javscript Controller: docActions.get.js
Alfresco Web Scripts Example
See the recorded webinar here:http://snurl.com/webscripts
Alfresco Web Scripts cont...JSON ATOM
HTML
See the recorded webinar here:http://snurl.com/webscripts
OK Great, now how do I apply this in a REST Architecture?
● Can be applied in a DM or WCM Deployment, in similar fashion
● Customize a completely different UI (i.e. Flex, HTML, Portal). (Web Scripts feature, not necessarily REST)
● Use Alfresco in your own app without exposing them to Alfresco. You will get the performance and reliability of all Alfresco services but abstract it from the user's perspective. Data API
● Serve content to users through Alfresco ASRs
● Provide data to other services whether they're written in .NET, PHP, Java, etc.
Web Scripts and REST Architecture
See the recorded webinar here:http://snurl.com/webscripts
Office Plugin
● Implemented in mini browser window
● All actions available through REST API
•HTML Response for UI
•Other json for responses to update UI and data retrieval.
● Core services accessible through plug-in
•Doc management
•Workflow
•Search
RESTful UI
See the recorded webinar here:http://snurl.com/webscripts
Portlets/Gadgets● Allow users access through a
portal like iGoogle.
● Since Web Scripts are jsr-168 compliant, just have to make portal aware.
● Popular portals: Jboss Portal, Liferay
● All data transmitted through json, xml, html, through custom REST API
RESTful UI
See the recorded webinar here:http://snurl.com/webscripts
Sample DM Architecture
● Client access Alfresco Web Scripts Directly
•UI Web Scripts, Office Plugin Web Scripts, etc.
● Or...Layer another application in between.
•Webapp access Alfresco using RESTful API to retrieve data: XML, JSON, HTML
● Can scale and cluster this environment
•Your webapp
•Alfresco ECM server
RESTful DM
AlfrescoECM Server
Your Webapp
See the recorded webinar here:http://snurl.com/webscripts
Sample Customer DM Architecture
● Customer uses Alfresco as DAM
● Manages all contents internally with Alfresco with custom UI and actions.
● Same data then pushed out through transfer to serve internet
•Webapp utilizes Web Scripts to get data from DMZ Alfresco
•Able to perform transformations on images
•Can download transformed or original.
● Serves worldwide user base.
RESTful DM
AlfrescoECM
Server
Your Webapp
AlfrescoECM
Server
Firewall
See the recorded webinar here:http://snurl.com/webscripts
Sample WCM Architecture● Create your content on Alfresco WCM Server
(Authoring)
● Content (XML files, etc.) deployed to runtime
● Web Scripts on the Alfresco Runtime serves your webapp:
•Data Acess API
•HTML, JSON, XML, RSS, ATOM, etc. Your choice
•Supports cached results.
•Use for searching, navigation, or dynamic page assembly.
● Add more runtimes: load balance
RESTful WCM
AlfrescoWCM Server
Your Webapp
AlfrescoRuntime
Firewall
AlfrescoRuntime
AlfrescoRuntime
See the recorded webinar here:http://snurl.com/webscripts
Links
● Alfresco Content Community Developer Toolbox: http://tinyurl.com/6yajvj
• http://wiki.alfresco.com/wiki/RESTful_API
• http://wiki.alfresco.com/wiki/RESTful_API_Reference
• http://wiki.alfresco.com/wiki/Surf_Platform
•http://wiki.alfresco.com/wiki/3.0_REST_API
Useful Links
See the recorded webinar here:http://snurl.com/webscripts
03.04.08
Q&A and Resources● Resources:
● Developer Toolbox: http://tinyurl.com/6yajvj
● RESTful API: wiki.alfresco.com/wiki/RESTful_API
● RESTful API Ref: wiki.alfresco.com/wiki/RESTful_API_Reference
● Alfresco SURF: wiki.alfresco.com/wiki/Surf_Platform
● Alfresco 3.0 REST API: wiki.alfresco.com/wiki/3.0_REST_API
● Join the Content Community: alfresco.com/community/register
● Developer Challenge: alfresco.com/partners/programme/webscripts/
● Join the Alfresco Facebook Group● facebook.com/group.php?gid=6063383762
● Nominate Alfresco in the Packt CMS Awards
● http://tinyurl.com/68og3p
See the recorded webinar here:http://snurl.com/webscripts
03.04.08
See the recorded webinar
See the recorded webinar here:http://snurl.com/webscripts