"; */ ?>


Jul 08

Install rtGui on Ubuntu

rtorrent project logortGui is a web based front end for rTorrent – the Linux command line BitTorrent client. It’s written in PHP and uses XML-RPC to communicate with the rTorrent client.

There are several guides on how to install rtGui on Ubuntu or just POL (Plain Old Linux), but all of them seem to be missing one or two things to make them complete.

Here I went from scratch, step by step to install rtGui on Ubuntu (actually KUbuntu, and to be more specific linuxMCE but it would not matter in this case, since this guide is for any more or less recent Ubuntu distro). I tried to make this guide as complete as possible so it does not miss any installation steps, and if you have any questions/comments, you are welcome to post them in comments section. Now sit back, relax and… let’s get to work! :)

Step 1.  Install PHP with XML-RPC and a SCGI apache module:

sudo apt-get install php5 php5-xmlrpc libapache2-mod-scgi

Step 2. Edit Apache default server config:

sudo vi /etc/apache2/sites-enabled/000-default

(If you are using linuxMCE, edit /etc/apache2/sites-enabled/pluto file instead)
Add the following lines, above the last “</VirtualHost>” (or download example from http://rtgui.googlecode.com/files/000-default ):

LoadModule scgi_module /usr/lib/apache2/modules/mod_scgi.so

Restart apache:

sudo apache2ctl restart

Step 3. Create .rtorrent.rc file – see http://libtorrent.rakshasa.no/browser/trunk/rtorrent/doc/rtorrent.rc?rev=latest or download example from http://rtgui.googlecode.com/files/.rtorrent.rc and save to your home directory – ~/.rtorrent.rc

* make sure .rtorrent.rc has this line:

scgi_port =

Step 4. Create directories for rtorrent to use, and change the ownership to the user that runs rtorrent:

mkdir /Torrents /Torrents/Downloading /Torrents/Downloading/rtorrent.session
/Torrents/Complete /Torrents/TorrentFiles /Torrents/TorrentFiles/Auto
chown username /Torrents /Torrents/Downloading /Torrents/Downloading/rtorrent.session
/Torrents/Complete /Torrents/TorrentFiles /Torrents/TorrentFiles/Auto

* here “username” is the user who will run rtorrent 

Step 5. Instal XML-RPC library:

sudo apt-get install libxmlrpc-c3-dev
sudo apt-get install libxmlrpc-c3

Step 6. Install latest version of both – libtorrent & rtorrent:

NOTE: Depending on packages installed on the system, you might need these dependencies:

sudo apt-get install libncurses5-dev libsigc++-2.0-dev libcurl4-openssl-dev build-essential

Download latest version (X.Y.Z) of libtorrent from http://libtorrent.rakshasa.no/downloads/ into /usr/local/ directory:

wget http://libtorrent.rakshasa.no/downloads/libtorrent-X.Y.Z.tar.gz
sudo tar xvf libtorrent-X.Y.Z.tar.gz
cd libtorrent-0.11.1
sudo ./configure
sudo make
sudo make install

Download rtorrent latest version (X.Y.Z) from http://libtorrent.rakshasa.no/downloads/ in /usr/local/ directory.

wget http://libtorrent.rakshasa.no/downloads/rtorrent-X.Y.Z.tar.gz
sudo tar xvf rtorrent-X.Y.Z.tar.gz
cd rtorrent-X.Y.Z
sudo ./configure --with-xmlrpc-c
sudo make
sudo make install

* make sure  you configure rtorrent with “–with-xmlrpc-c” option

After the above 6 steps we are ready to install rtGui (and other GUIs for rtorrent: wTorrent, etc..)

Step 7. Install rtGui:

Download rtgui from http://code.google.com/p/rtgui/downloads/list
Extract files to webserver directory:

sudo tar xvzf ~/rtgui-0.2.3.tgz -C /var/www

* 0.2.3 is the current version at the moment of writing

You can edit “/var/www/rtgui/config.php” if you’d like to change rtGui default settings. Most of the time you don’t have to.

*** Step 8. Start rtorrent:


Step 9. Done! :) Open your browser, and go to http://localhost/rtgui/

*** (!) Since rtGui talks to rtorrent via XML-RPC gateway, rtorrent has to be started – otherwise rtGui has nobody to talk to :) In case rtorrent is not started when you accessing rtGui via web browser, you would get:

Warning: file_get_contents(http://localhost/RPC2) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /var/www/rtgui/functions.php on line 10

This is because there is nobody listening on port 5000 – remember the line “scgi_port =″ in .rtorrent.rc? We have configured rtorrent with ” –with-xmlrpc-c” option, hence when rtorrent is up and running it will listen on “scgi_port” (in this case 5000) and will be able to handle XML-RPC requests/responses.

Happy rTorrenting!

Jul 08

Spring Web Application Context Visibility

spring framework logoWhile developing a Web App using Spring little things can take a lot of time to resolve. At the end they may appear to be very simple, and you may ask your self “how could I not think of it before – it is so obvious!”. Well, yea, it is obvious, but you just have to know it! One of the places that helps you to solve the “obvious” (and not so obvious), so you do not have to spin your wheels is, with no doubts, the spring forum. However you need to know the right search criteria to find what you need.

Here I just want to share something small but important about the visibility of Spring Contexts in a Web App.

Looking at org.springframework.web.servlet.DispatcherServlet API notice this:

“A web application can define any number of DispatcherServlets. Each servlet will operate in its own namespace, loading its own application context with mappings, handlers, etc. Only the root application context as loaded by ContextLoaderListener, if any, will be shared.”

This brings an interesting point – in a Spring Web App you have one root application context which is private, and many dispatcher servlet application contexts which are children of the root application context:


In the above, everything that is defined in “contextConfigLocation” is your root application context. Every “dispatcher-servlet-number-x” (“dispatcher-servlet-number-1”, “dispatcher-servlet-number-2”, etc..) would represent a child application context which will see (have the visibility to) all the beans from the parent (root) context, but will not see any of the beans defined by its siblings – another dispatcher servlet contexts.

The only gotcha in the above visibility is BeanFactoryPostProcessor / BeanPostProcessor (s) – like “PropertyPlaceholderConfigurer” for example. These guys apply ONLY to beans in its own context. For example, if you have PropertyPlaceholderConfigurer defined in the root application context, none of root’s children will be able to use it (see) the ${properties}.

Here is the semi-official version “why” from Juergen (Spring Lead Developer):

“PropertyPlaceholderConfigurer is an implementation of the BeanFactoryPostProcessor interface: This interface and its sibling BeanPostProcessor just apply to the BeanFactory that defines them, that is, to the application context that defines them.

If you combine multiple config files into a single contextConfigLocation, a PropertyPlaceholderConfigurer defined in any of the files will apply to all of the files, because they are loaded into a single application context.

However, a DispatcherServlet has its own application context, just using the root web application context as parent. Therefore, it needs to define its own BeanFactoryPostProcessors and/or BeanPostProcessors, in this case its own PropertyPlaceholderConfigurer.”

Happy Springing!

May 08

Generate XSD from XML

There are several tools out there to create (or to infer) an XSD schema from XML document. I liked trang command line tool the most. Found it first when reading about Spring web services in Spring in Action book (very good book btw).

Here are four simple steps how to create XSD from XML* using trang:

Step 1. Get trang

Download trang.zip from here (at the moment of writing “trang-20030619.zip”)

Step 2. Extract it

Use “unzip trang-version.zip”, or just winzip/winrar/7z etc.. if on windows

Step 3. Make an alias

This step is optional, but makes it extremely easy to run the tool with a single command. Make an alias to the “trang.jar” by (in my case Ubuntu/Linux) editing “~/.bashrc” and adding the following:

# execute trang.jar (create XSD from XMLs)
alias xml2xsd='java -jar ~/soft/utils/trang/trang-20030619/trang.jar'

above “~/soft/utils/trang” is the directory where “trang” was unzipped to.

Step 4. Create XSD from XML

Let’s look at the XML file we need an XSD for:

$ ls -l
total 4
-rw-r--r-- 1 user group 357 2008-05-28 15:38 holiday-request.xml
$ cat holiday-request.xml
<?xml version="1.0" encoding="UTF-8"?>
<holidayRequest xmlns="http://mycompany.com/hr/schemas">

now run the tool against it:

$ xml2xsd holiday-request.xml hr.xsd
$ cat hr.xsd
<?xml version=”1.0″ encoding=”UTF-8″?>
<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema” elementFormDefault=”qualified” targetNamespace=”http://mycompany.com/hr/schemas” xmlns:schemas=”http://mycompany.com/hr/schemas”>
  <xs:element name=”HolidayRequest”>
        <xs:element ref=”schemas:Holiday”/>
        <xs:element ref=”schemas:Employee”/>
  <xs:element name=”Holiday”>
        <xs:element ref=”schemas:StartDate”/>
        <xs:element ref=”schemas:EndDate”/>
  <xs:element name=”StartDate” type=”xs:NMTOKEN”/>
  <xs:element name=”EndDate” type=”xs:NMTOKEN”/>
  <xs:element name=”Employee”>
        <xs:element ref=”schemas:Number”/>
        <xs:element ref=”schemas:FirstName”/>
        <xs:element ref=”schemas:LastName”/>
  <xs:element name=”Number” type=”xs:integer”/>
  <xs:element name=”FirstName” type=”xs:NCName”/>
  <xs:element name=”LastName” type=”xs:NCName”/>



* – NOTE: “trang” can create an XSD from multiple XML documents, not just one.

List of other tools to use as an alternative to trang:

XSD away, Good Luck!