
Atom Publishing Plugin
Table of Contents [-]
Introduction #
The Goal of this Web Plugin is to expose a subset of Liferay Portal's services using AtomPub to allow for the creation of read-write mashups. These mashups can read data from the portal and also interact with it by creating or modifying existing content.
Blogs and the Web Content have been integrated within the AtomPub web plugin, but every entity that has been built with Liferay Service Builder can be easily integrated as well. This web allows an AtomPub client (which may be part of a Mashup) to list blog entries or web content, create new blogs/web content and update or remove existing blogs/web content.
The “AtomPub web plugin” provides the following URL which can be used to browse the available workspaces and collections. It is also possible to use a regular browser, such as Firefox, to read the list of blog entries. For example given the following blog entries created through Liferay Portal UI:
These blogs can also be obtained as an Atom feed using the following URL:
http://localhost:8080/atompub-web/atom/blogs?companyId=10111&groupId=10130
Which Firefox is able to interpret and show as in the following screenshot:
Using the atompub-web plugin #
To test the atompub-web plugin, we'll first need a REST Client. You can download a free REST Client by downloading the REST Client GUI here: http://code.google.com/p/rest-client/downloads/list
Right click the downloaded jar and run the application by opening it with Java(TM) Platform SE Binary.
As an example lets add a new Blog Entry using the REST Client GUI.
URL: http://localhost:8080/atompub-web/atom/blogs?companyId=1&groupId=18
For the Method tab
Select POST for the HTTP Method
For the Body tab
Body Content Type: Select "application/atom+xml" for Content-type Select UTF-8 for Content
And add this text In the text box
<?xml version='1.0'?> <entry xmlns='http://www.w3.org/2005/Atom'> <title>Atom Pub Blog 1</title> <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> <updated>2003-12-13T18:30:02Z</updated> <author><name>Joe Bloggs</name></author> <content>Hello world!</content> </entry>
For the Auth tab:
Select BASIC for Auth Type.
And enter your Liferay Portal screenname and password.
Now clicking the green arrows creates a new blog entry!
For a list of Blogs, we could use the following URL:
http://localhost:8080/atompub-web/atom/blogs?companyId=1&groupId=18
The browser is using the GET HTTP method to obtain a list of all blog entries, but it's also possible to use the other three main HTTP methods, POST, PUT and DELETE, to add new entries, update them and delete them directly. The screenshot shows in the lower side the resulting HTTP headers including the etag headers which allows for conditional GETs for very high scalability.
You can also select to view a specific blog entry by using this URL where 11017 is the ID of the blog entry:
http://localhost:8080/atompub-web/atom/blogs/11017?companyId=10111&groupId=10130
Using this same tool we can also test updating the entry using a PUT. The following screenshot shows how the body of the PUT request is an XML text with the entry details in Atom format. The server answers with 204 HTTP return code to specify that the entry has been updated correctly.
For Web Content, replace "/blogs/" with "/web_content/" in the URLs.
An AtomPub client can also be implemented in JavaScript, which becomes a very useful component for building read-write mashups.
jQuery.ajax({ type: "POST", url: 'http://localhost:8080/atompub-web/atom/blogs?companyId=10111&groupId=10135', username: 'test', password: 'test', processData: false, contentType: 'application/atom+xml', dataType: "xml", data: body, cache: false, success: function(msg){ callback.onSuccess('conseguido'); }, error: function (msg){ callback.onFailure(); } });
Security #
Basic authentication has been implemented for this plugin, so you may need to introduce your credentials for some actions. The userName can be your screenName, your emailAddress or your userId in your Liferay Portal.