Book Image

Alfresco 3 Web Services

Book Image

Alfresco 3 Web Services

Overview of this book

Alfresco 3 is the leading open source enterprise content management system that offers powerful features for interacting with the content in its repository from outside the system. These include the support for the Content Management Interoperability Services (CMIS) implementation, reusable web scripts, and a Web Services API. This is the first book to show you how to use Web Services in Alfresco. Packed with examples, you'll learn how to build applications using Alfresco remote APIs based on SOAP and REST. You'll see how to use different APIs and bindings such as WebServices, WebScripts, and CMIS. Alfresco 3 Web Services starts off by showing you the services exposed by the Alfresco Web Services API, and how the API fits into the Alfresco software architecture.You learn to develop your application firstly by setting up and testing your Java development environment using the Alfresco SDK in Eclipse IDE and secondly by associating the Alfresco source code and Javadocs in Eclipse.With the help of real world practical examples, you learn how to do things like create, sort, and call Web Scripts, and invoke remote calls to Alfresco repository. To get the most from the Web Services API, you need to know about the basics of the Content Manipulation Language (CML), and the book takes you through this.Examples such as the bookshop application show you how to sign in, change user sessions, get, remove and change public and private associated contents, manage a cart for your e-commerce application, and so on.Next, by implementing a Microsoft .NET application using the Alfresco Web Services API, you see how to perform operations against the repository from your .NET application.The book provides you with REST and SOAP concepts, their comparison, basics of the FreeMarker language, Atom Publishing Protocol, JavaScript controllers, and the Apache Chemistry project.By the end of this book, you will be able to put together your knowledge about CMIS and the Apache Chemistry toolkit to develop a complete working application that uses Alfresco, via CMIS, as a back-end storage. Last but not the least, this book also covers the WebServices security profiles— the best practices for Web Services to promote better interoperability.
Table of Contents (20 chapters)
Alfresco 3 Web Services
Credits
About the Authors
About the Reviewers
Preface
Free Chapter
1
Introducing the SOAP Web Services API

Using Alfresco Web Services


Provided you can access an instance of Alfresco running on the server host and listening on TCP port, you can retrieve all the WSDLs for the Alfresco Web Services by pointing a browser to the URL for each service, as detailed in the following table.

Each service provides a set of operations related by a common purpose, so that you may use only the ones that you are interested in:

Service name

Purpose

URL

AccessControlService

Manage permissions

http://host:port/alfresco/api/AccessControlService?WSDL

ActionService

Execute custom actions and rules

http://host:port/alfresco/api/ActionService?WSDL

AdministrationService

Manage users and groups

http://host:port/alfresco/api/AdministrationService?WSDL

AuthenticationService

Login and access session tickets

http://host:port/alfresco/api/AuthenticationService?WSDL

AuthoringService

Allows collaboration between users

http://host:port/alfresco/api/AuthoringService?WSDL

ContentService

Read and write content

http://host:port/alfresco/api/ContentService?WSDL

ClassificationService

Manage categories

http://host:port/alfresco/api/ClassificationService?WSDL

DictionaryService

Manage content models

http://host:port/alfresco/api/DictionaryService?WSDL

RepositoryService

Navigate, search, and manipulate nodes.

http://host:port/alfresco/api/RepositoryService?WSDL

Besides retrieving the WSDL documents online, using the URLs from the previous table, you can also find copies of the WSDLs as files in the Alfresco source tree. You can download a copy of the Alfresco source from the Subversion repository, as explained in the wiki page at http://wiki.alfresco.com/wiki/Alfresco_SVN_Development_Environment. The WSDL files can be found under root/projects/remote-api/source/wsdl in your copy of the source tree. In this folder, you can also find all the WSDL files related to the Web Services binding of the CMIS implementation of Alfresco that will be described in Chapter 13, The Web Services Binding. Another location where you can find a copy of the WSDL documents is inside the Alfresco SDK, in the lib/remote/wsdl folder. Downloading and installing the Alfresco SDK is the subject of the next section.

Using the Alfresco Web Services client SDK

If you are developing a remote application to contact Alfresco using Java, Alfresco provides you with a precompiled Web Services client stub. The client stub allows you to invoke the Alfresco SOAP Web Services from a remote Java application, using a set of Java interfaces.

The code that makes up this client stub is available as part of the Alfresco SDK. You can download the Alfresco SDK from the same location where you can download the rest of Alfresco software. You can always browse the following web page to discover the list of files that can be downloaded for the most recent version of Alfresco Community:

http://wiki.alfresco.com/wiki/Download_Community_Edition.

Click on the Custom Installs link and look for a file to download named something like alfresco-community-sdk-3.3.zip. Once you have unpacked it, you can load the SDK as a set of projects in the Eclipse IDE, which is explained as follows, or create a project in a different IDE, and add the libraries contained in the SDK as dependencies there.

The client stub code is contained in the alfresco-web-service-client-3.3.jar. The interfaces contained therein can be used from your client Java application, as depicted in the following diagram. The purpose of the various interfaces and their intended usage will be the subject of the upcoming chapters.

Setting up the Alfresco SDK

To develop your own Web Service client application using the Web Services API of Alfresco, you need to configure your development environment with the Alfresco SDK.

Before starting to develop an application that uses the Alfresco Web Services, you need the following prerequisites:

  • Java JDK 1.5 (Sun implementation)

  • An IDE application to write your own source code for your application

The most common known IDEs used in the community are Eclipse and NetBeans. In this book, we will use Eclipse for all the examples and screenshots, but you can use any other IDEs.

The steps to set up your development environment using Eclipse IDE are as follows:

  1. 1. Download the latest updated version of Java JDK 1.6 from the Sun website.

  2. 2. Install Java JDK 1.6.

  3. 3. Download the latest version of the Eclipse IDE from http://eclipse.org.

  4. 4. Install Eclipse IDE.

  5. 5. Extract the Alfresco SDK package previously downloaded.

  6. 6. Import all the projects from the extracted Alfresco SDK projects from the root folder in your workspace in your IDE, in the following way:

  7. 7. Right-click on the Package Explorer, and click on Import....

  8. 8. Expand the General folder.

  9. 9. Select Existing Projects into Workspace, and press the Next button

  10. 10. Now on the Select Root Directory field, you can browse to select the root folder of the extracted Alfresco SDK.

  11. 11. Click on the Finish button to import all the projects in your Eclipse Workspace.

  12. 12. Make sure that the Java compiler compliance level is set at least to 5.0 from Windows | Preferences | Java | Compiler.

Now we have imported all the projects provided by the Alfresco SDK in to our workspace.

In order to have Alfresco source code and Java docs configured properly in Eclipse, we need to associate source code packages, related to Alfresco libraries, in the following way:

  1. 1. Right-click on the SDK AlfrescoEmbedded project.

  2. 2. Click on Properties.

  3. 3. Click on Java Build Path.

  4. 4. Click on Libraries.

  5. 5. Expand alfresco-repository-3.3.jar.

  6. 6. Select Source attachment.

  7. 7. Click on the Edit... button.

  8. 8. Click on the External File... button.

  9. 9. Browse to and select this file: Alfresco SDK/src/alfresco-repository-src.zip.

  10. 10. Repeat all the previous steps for the following libraries:

    Alfresco SDK Project

    Library

    Source code package

    SDK AlfrescoEmbedded

    alfresco-repository-3.3.jar

    alfresco-repository-src.zip

    SDK AlfrescoEmbedded

    alfresco-core-3.3.jar

    alfresco-core-src.zip

    SDK AlfrescoEmbedded

    alfresco-remote-api-3.3.jar

    alfresco-remote-api.zip

    SDK AlfrescoEmbedded

    alfresco-web-client-3.3.jar

    alfresco-web-client-src.zip

    SDK AlfrescoRemote

    alfresco-web-service-client-3.3.jar

    alfresco-web-service-client-src.zip

If you want Javadocs, you also need to associate Javadocs archives:

  1. 1. Right-click on the SDK AlfrescoEmbedded project.

  2. 2. Click Properties.

  3. 3. Click on Java Build Path.

  4. 4. Click on Libraries.

  5. 5. Expand alfresco-repository-3.3.jar.

  6. 6. Select the Javadoc location.

  7. 7. Click the Edit... button.

  8. 8. Click the Javadoc in archive button.

  9. 9. Click the External file button.

  10. 10. Click the Browse... button for the Archive path field.

  11. 11. Browse to and select the Alfresco SDK/doc/alfresco-repository-doc.zip file.

In the same way as source code packages, repeat all the previous steps for all the following Javadoc archives:

Alfresco SDK project

Library

Archive package

SDK AlfrescoEmbedded

alfresco-repository-3.3.jar

alfresco-repository-doc.zip

SDK AlfrescoEmbedded

alfresco-core-3.3.jar

alfresco-core-doc.zip

SDK AlfrescoEmbedded

alfresco-remote-api-3.3.jar

alfresco-remote-api-doc.zip

SDK AlfrescoEmbedded

alfresco-web-client-3.3.jar

alfresco-web-client-doc.zip

SDK AlfrescoRemote

alfresco-web-service-client-3.3.jar

alfresco-web-service-client-doc.zip

The most important projects that we will use in this book are:

  • SDK AlfrescoEmbedded

  • SDK AlfrescoRemote

SDK AlfrescoEmbedded will be used to show you how to implement a Java-backed Web Script using the Foundation Services API of Alfresco.

SDK AlfrescoRemote will be used to show you how to implement your own Web Services client stub in your custom application. In this way, we can invoke remote calls to the repository using the Content Manipulation Language (CML).

Testing the Web Services client

Once you have set up the SDK in Eclipse, as explained in the previous section, you can run a sample program to verify that it is working correctly. In order to perform this test, make sure that you have installed Alfresco and that it is running. We are going to assume that it is listening for an incoming connection on the host localhost, port 8080.

From within Eclipse, expand the SDK FirstWebServiceClient project, and look for the source code file named FirstWebServiceClient.java. Right-click on the file, and select Run As | Java Application. The program should start up and, after a couple of seconds, print out the following to the console window:

Content Length: 43

Now, browse the Company Home space using the Alfresco Explorer (http://localhost:8080/alfresco) and check that a file has been created there with a name like Web Services sample (long number here).

Note

If your server is not listening on port 8080 of the localhost, which is the default port, you need to modify the file source/alfresco/webserviceclient.properties, contained in the sample, and change the value of the repository.location property according to your server's hostname and port.