Flex SDK Developer Guide

Document created by resplin Employee on Jun 6, 2015
Version 1Show Document
  • View in full screen mode

{{Obsolete}}

This functionality was removed from Alfresco in 5.0.b.


Introduction


The Alfresco Flex SDK contains classes that allow full access to the capabilities of Alfresco repository via Web Scripts.

This document gives developer level instructions on how to use this API, specifically calling a Web Script from Flex and authenticating a repository user.  


Executing a Web Script from Flex


1. Construct an instance of WebScriptService

The class WebScriptService extends the Flex object HTTPSerivce and operates in a similar manner.

When constructing an instance of WebScriptService several parameters are available:


  • url - the full URL of the Web Script to execute
  • method - the HTTP method that the web script should be executed with (eg: GET, PUT, DELETE ..)
  • onSuccess - the event handler function called when the web script successfully executes (optional)
  • onFailure - the event handler function called when the web script fails during execution (optional)
  • ticketRequired - indicates whether a valid Alfresco ticket should be passed when the web script is called (optional, default value true)
  • alwaysTunnelGetMethod - indicates whether the web script service should always tunnel all methods as GET or whether it should send requests as POST's if specified (optional, default is true)



2. Set Success/Failure event functions

If these where not set during creation then they should be done so now.  The fault event handler does not need to be specified, but if it isn't then an application error is raised with the error service.



3. Set valid ticket 

If the web script you are calling required a valid ticket to be sent then a ticket should be set on thw web script service instance.  This ticket will be appended to the URL in a manner that the Web Script framework will understand.

If no ticket is specified, but a valid ticket is expected then the WebScriptService instance will ask the Authentication Service for the current user's ticket.



4. Execute Web Script

Call the execute method to call the web script.  Any parameters passed to this method will be appended to the executed URL as normal URL parameters.



5. Handle Success/Failure

On failure the onFailure event handler function will be called.  The failure event will, apart from the usual event information, contain the related error message string.

On success the onSuccess event handler function will be called.  The success event extends the standard ResultEvent class and the result property contains the result of the web script and is navigatable using the normal dot notation.



Example:




...

   // Create the web script object
   var url:String = 'http://myserver:8080/alfresco/service/api/login';
   var webScript:WebScriptService = new WebScriptService(url, WebScriptService.GET, onLoginSuccess, onLoginFailure, false);
  
   // Build the parameter object
   var params:Object = new Object();
   params.u = 'admin';
   params.pw = 'admin';
 
   // Execute the web script
  webScript.execute(params);

...

public function onLoginSuccess(event:SuccessEvent):void
{
   // Get the ticket from the results
   this._ticket = event.result.ticket;
}

public function onLoginFailure(event:FailureEvent):void
{  
   // Get the error details from the failure event
   var code:String = event.fault.faultCode;
   var message:String = event.fault.faultString;
   var details:String = event.fault.faultDetail;

   ...
}

Authentication Service


The AuthenticationService is a singleton service class that provides a convenient way to authenticate a user against the Alfresco repository using the Web Script API and manage the resulting user's ticket.


public function login(userName:String, password:String):void

The login method takes the provided user credentials and authenticates then against the Alfresco repository.  If the users credentials are authenticated successfully the a ticket is returned and stored and the LoginCompleteEvent event is raised.

If the login fails the onLoginFailure even is raised.



public function get ticket():String
public function get userName():String

Once a user has successfully logged in then the ticket and userName properties of the authentication service will contain the ticket and user name information for the that logged in user.


public function logout():void

The logout method invalidates the current ticket with the repository.

3.0

Attachments

    Outcomes