Sample Client Source
Using the FTPish Sample
This sample is developed in Python and implements a client-side, command-line, application that presents a very similar interface to that of an FTP client. In this way users can connect to, get, put and delete resources in a JRS repository very easily and also navigate the API in a familiar manner.
Getting started
First of all, running the client with the -h or
--help parameter should provide you with some useful information,
such as:
$ python ftpish.py --help Usage: ftpish.py [options] [server-url] Options: --version show program's version number and exit -h, --help show this help message and exit -u USER User to log on as. -p PASSWORD Password for user to log on as.
The most common form to run the tool is to specify the Jazz user (-u) and then the server-url on the command line. If you do not specify the server-url you will need to use the connect command in the tool and if you do not specify the user then you will need to use the user command. To get a list of commands you can type help in the tool, as in:
$ python ftpish.py -u simon http://localhost:8082 jrs> help Documented commands (type help <topic>): ======================================== cd delete exit head list post put rmdir size user connect dir get help mkdir properties pwd set type jrs>
Obviously the commands "get", "head", "put", "post" and "delete" are pretty much what you would expect from the JRS REST API, and then the "size" and "type" are derived from their FTP client equivalents. The interesting behavior is in the "cd", "list" and "pwd" commnds which use the underlying Atom collections as folders. When you use the "cd" command the client performs a HEAD on the resource to ensure that it is a collection and then caches the URL as the current directory (this is the returned value from the "pwd" command). This also implies that any "cd" with a relative path name will try to resolve as relative from the current directory (note that relative operators such as "." and ".." are not supported).
jrs> cd /jazz/projects jrs> pwd /jazz/projects jrs> list CreateTestsProject System 2008-02-28T20:54:30-05:00 tests System 2008-02-28T20:54:30-05:00 IndexingAndQueryTests System 2008-02-28T20:54:30-05:00 testImageIndexer System 2008-02-28T20:54:40-05:00 testXmlIndexerHrefs System 2008-02-28T20:54:46-05:00 jrs>
Getting resources
Getting resources is generally simple, type "get" followed by the URL of the resource you wish to retrieve. You can also provide a local name if you wish, otherwise the client will try and deduce the filename from the URL. There are also commands to get the HEAD information which can be useful to see things like the last-modified date and/or etag value. The client also provides simple helper commands to retrieve just the content-type and size of a resource, these are provided in the same was as their FTP counterparts.
jrs> cd /jazz/projects jrs> pwd /jazz/projects jrs> help get syntax: get url [local-name] -- receive resource jrs> head SubscriptionTests Date: Mon, 03 Mar 2008 18:37:34 GMT Server: Jetty/5.1.x (Mac OS X/10.5.1 i386 java/1.5.0_13 Connection: close ETag: "_ugNfUeZpEdyY36uARUYYZQ" Last-Modified: Thu, 28 Feb 2008 20:57:48 EST Content-Type: application/atom+xml jrs> type SubscriptionTests application/atom+xml jrs> get SubscriptionTests Saving file SubscriptionTests
Note how the client "cd"-ed into the projects collection before performing the GET so that the request was considered relative to the current working collection.
Uploading resources
The following demonstrates the ability to PUT a resource as a stand-alone resource into the JRS repository, note that when you do a PUT we do a HEAD on the resource first to see if it exists and prompt you before you overwrite an existing one.
jrs> help put syntax: put filename url [content-type] -- put resource jrs> put test-resource-1 /jazz/resources/SubscriptionTests/test-resource-2 application/xml Created: /jazz/resources/SubscriptionTests/test-resource-2?revision=_h6gqAulREdyie406XoCBLg jrs> put test-resource-1 /jazz/resources/SubscriptionTests/test-resource-2 application/xml Resource "/jazz/resources/SubscriptionTests/test-resource-2" exists, overwrite (y/n)? y Updated: /jazz/resources/SubscriptionTests/test-resource-2?revision=_jMbk4ulREdyie406XoCBLg jrs> delete /jazz/resources/SubscriptionTests/test-resource-2 Deleted resource /jazz/resources/SubscriptionTests/test-resource-2
Note that the user realized they'd uploaded test-resource-1 to
test-resource-2 and proceded to delete the resource. If the content-type is not
specified, as is was in the example above, the client tries to deduce the
content-type from the local file name, this can sometimes fail and the default
in this case is application/octet-stream.





