Hatherly.com

Blog



iPlayer in MythTV (the Easy Way)

Posted on December 1, 2008 by Adam under MythTV

I use MythTV as a media centre in my lounge, not to record TV, but purely for browsing and playing my collection of mp3s, and occasionally playing downloaded video clips. It also allows me to read rss feeds and their linked web pages using a remote from the comfort of my sofa.

One of the things I have wanted to be able to do for a while is use mythtv to watch BBC iPlayer content. There has been some attempts at making mythtv plugins for this purpose, but they have always been rather complicated to set up which has always put me off.

I discovered however, that the BBC has added rss feeds of the iplayer programmes to each of the pages in the iPlayer, so I decided to see if it would be possible to use these to get at the content frmo mythtv. These feeds on the BBC site are actually Atom feeds rather than rss feeds, and unfortunately mythnews (the rss plugin for mythtv) doesn’t support atom feeds. Luckily I found a handy online utility that will do an on-the-fly conversion from atom to rss: http://atom2rss.semiologic.com/ Using that I managed to create some new entries in mythnews that let me see the listings of iPlayer programmes for various channels.

So far so good, but when I select one of the items using the remote, it opens a mythbrowser window, but it gives a message saying that our version of flash is out of date and there is no easy way of upgrading it using the link provided. Luckily some helpful person has solved this one: http://www.nabble.com/Re%3A-Mythbrowser-0.21-flash-p16200963s15552.html

So now I was able to choose a programme and open a browser window, and the player appears. The next problem is that the programme does not play automaticaly, but you get a “Click to Play” prompt, and you need to click play to start the playback. As I am using a simple media centre remote for this, and don’t want to use a mouse that is a problem.

To solve this one, I had a look at what the other iplayer plugin had done: http://www.mythtv.org/wiki/index.php/BBC_iPlayer. I realised there is a package called xautomation that can be used to script mouse movements and clicks, so I decided to make use of this to click play for me. First, I used synaptic (or apt-get) to get the xautomation package. You can test it by opening a terminal and typing:

echo mousemove 10 10 | xte

Your mouse pointer should move to the top left of the screen.
So, now I opened the iplayer page in mythbrowser and worked out the x and y co-ordinates of the play button. I then created a small shell script to move to the correct position, click, then move the mouse out of the way:

#!/bin/bash
echo mousemove 200 560 | xte
sleep 1
echo mouseclick 1 | xte
sleep 1
echo mousemove 9999 9999 | xte

So, now I had a script to click the play button, I needed to associate it with a keypress on my remote control. Rather than so something to mythtv to get it to trap the event, I decided to use irexec which is a simple utility that comes with lirc (the remote control utility). So, I edited my ~/.lircrc file, and added:

begin
    remote = mceusb
    prog = irexec
    button = LiveTV
    config = /home/adam/Scripts/iplayerStartPause.sh
    repeat = 0
    delay = 0
end

I needed to make sure irexec was running as a daemon when my server starts up (irexec –daemon). Now, whenever I press the “LiveTV” button on my remote (I was not using that button previously) my script gets executed and the mouse moves and clicks in the correct place.

So, now I have the ability to browse iplayer programme listings, select one and play it. I need to do some more work to add the ability to make the video full-screen, alter volume, etc, but for now it is great to be able to watch iplayer programmes from my sofa without having to fire up the laptop or PC 🙂



  |  Leave a comment


Ubuntu Gnome Application Menu Missing

Posted on September 8, 2008 by Adam under Ubuntu

I have had a rather annoying problem on my Ubuntu box for the last few days. Not sure how it happened, but my application menu suddenly stopped working. Whenever I clicked on the menu I just got a tiny grey box with nothing in it where the menu should have been.

After a lot of googling with no success, I finally stumbled on a post that mentioned some files in ~/.config/. When I had a look in there, there was a subdirectory called menus which contained a file called applications.menu. I had a look at that file, and sure enough it was empty. After having a quick look at my other Ubuntu box I noticed that box had no applications.menu, so I deleted the empty file and hey presto!



  |  16 Comments


Handy Shell Commands

Posted on March 20, 2008 by Adam under Ubuntu

I thought I would share some commands and small single line bash scripts I have found useful in the past:

AWK

Output every 50th line from a file into a new file :

cat infile.csv | awk ' (NR % 50) == 0 { print $0 } ' > outfile.csv

Print the 13th column (space delimited):

awk ' { print $13} '

Print the 13th column (colon delimited):

awk -F":" '{ print $13 }'

Find

Recursive Grep (starting from current directory):

find . -name "*" -exec grep -i "searchValue" {} /dev/null ;

Compare files in two directories (-N for new files, -a for forcing ASCII, and -r for recursing subdirectories):

diff -Nuar dir1 dir2

Find all files under /dir older than 7 days, and delete them:

find /dir -type f -mtime +7 | xargs rm -f

Do a global search and replace from “html” to “shtml” across all html files in the current directory and all subdirectories:

find . -name "*.html" -exec perl -pi -e 's/.html/.shtml/g' {} ;

Rename all html files to shtml files in the current directory and all subdirectories:

find . -name "*.html" | while read f
do
mv ./"$f" "${f%html}shtml";
done

Find the largest files and directories on your hard disc (starting from the current directory):

du -k * | sort -nr | more

List Hardware in your machine:

sudo lshw


  |  Leave a comment


Using Printers in Linux Without a Linux Driver

Posted on February 17, 2008 by Adam under Ubuntu

I recently bought a Lexmark X4550 all-in-one printer, scanner and copier. What I didn’t realise before I bought it is that Lexmark are horribly bad at providing Linux support for their printers. After speaking to their support people and finding out that the printer really doesn’t have any linux drivers and is unlikely to have any in the near future I began looking into ways of getting it to print.

The solution I came up with is a bit nasty, and not something you will probably want to do unless you really really want to get things printing from Linux.

Here’s how it works:

1) Install Innotek VirtualBox? (or some other virtualisation tool)

2) Create a new Windows virtual machine (I used Windows 2000 – I had a spare license I got free with an old PC and am not using)

3) Install the printer driver software on your windows virtual machine

4) Install GPL Ghostscript in your Windows VM – available here: http://sourceforge.net/projects/ghostscript/

5) Install “PrintFile” in your Windows VM – available here: http://hem1.passagen.se/ptlerup/prfile.html

6) Create a network share on your Linux machine and map to it from your Windows VM so it has a drive letter (e.g. K:)

7) Create a directory in this shared directory that you will monitor for new print jobs (e.g. K:printspool)

8 ) Run PrintFile and configure it as follows:

Set “enable spooler function” to ticked
Click the “Conversion” button
Tick Enable Conversion for PostScript? Files
In the program box enter the path of your ghostscript installation
In the Parameters box enter the following:
-Ic:gstoolsgs8.61;c:gstoolsgs8.61fonts -dSAFER -dBATCH -dNOPAUSE
-sDEVICE=mswinpr2 -dGraphicsAlphaBits=4 -sOutputFile=”spool&p” &i -c quit
(All on one line)
Click OK, then Save and the close the PrintFile

9) Create a new batch file in your Windows VM containing the following:

“C:Program FilesPrintFileprfile32.exe” /s:K:printspool*.ps
(Where K:printspool is the spool directory you want to monitor)

10) Run your batch file and it will start monitoring your directory for new jobs to print

11) In your Linux PC you can now print from any application – in the print dialog tick the “print to file” box and save your print job in the shared print spool directory that is being monitored by your windows machine.

Not a neat solution I admit, but it works 🙂



  |  Leave a comment


Using RSync to backup from Windows to Linux

Posted on January 21, 2008 by Adam under Ubuntu

I have a laptop running Windows Vista and a PC running Ubuntu Linux. When I take photos I generally transfer them to my laptop initially, but I wanted a simple way of keeping a copy of all the photos on the linux box too as a backup. Linux boxes have a great tool for data synchronisation called rsync. rsync is a very powerful tool that can copy across only files that have been modified, and is even clever enough only to copy the differences between the files rather than the whole file. It can also compress the file before transferring it and decompress it at the other end seamlessly to improve network performance.

To use rsync to backup from the windows laptop however, I first needed to find a windows rsync server application. Luckily there is a very nice free application called DeltaCopy , which is bascically the linux rsync with a windows wrapper around it (using cygwin). I found it was easy to install and runs as a service in Windows. You can get DeltaCopy from here: http://www.aboutmyip.com/AboutMyXApp/DeltaCopy.jsp

Most versions of linux come with rsync included by default, so the linux end was easy to set up. I created a small script to run the actual synchronisation, and added it to cron so that it runs every hour and checks for new Photos on the laptop. You can see the script below:

 #!/bin/bash
 if [ ! -f "/tmp/synchronising" ]
 then
   echo "Running" > /tmp/synchronising
   rsync --verbose --progress --stats --compress --recursive --times 192.168.10.101::Photos /home/adam/Photos > /home/adam/Scripts/synchronisation.log
   rm -f /tmp/synchronising
 fi

Another good article on how to use rsync can be found here: http://everythinglinux.org/rsync/



  |  2 Comments


Video Editing in Ubuntu

Posted on December 6, 2007 by Adam under Ubuntu

This post is a record of the tools I have used in Ubuntu Linux (7.04, Feisty Fawn) to capture and edit digital video, as well as transcode, author and burn it onto DVD.

Software

The main pieces of software I used were:

  • DVGrab – Utility for grabbing digital video from a DV camcorder
  • Kino – Video calture and editing tool
  • Kdenlive – Non-linear video editing tool
  • Cinelerra – Another video editing tool. Installation instructions are available here: https://help.ubuntu.com/community/CinelerraOnFeistyAMD64
  • VLC Media Player – Very powerful video player, decoder, encoder, streamer, etc.
  • Tovid – Very handy tool for transcoding any video format into DVD format. Instructions on how to install this are available here: http://tovid.wikia.com/wiki/Installing_tovid/Ubuntu
  • mplayer – Video player and transcoding tool (used by Tovid)
  • faad – Audio decoder, useful for working with Divx/XVid files
  • DVDStyler – DVD Menu creator and burning tool. I had to compile from source and I also had to get the wxsvg library – this tutorial helped: http://ubuntuforums.org/showthread.php?t=482761
  • QDVDAuthor – A slightly more advanced DVD menu editor, but a bit more difficult to get to grips with than DVDStyler

Transcode an mp4 (xvid) video into DVD format

Using tovid (adding subtitles when found):

Widescreen:

tovid -overwrite -pal -dvd -wide -quality 8 -autosubs -in "Video.mp4" -out "Video.mp4.tovid_encoded"

Normal:

tovid -overwrite -pal -dvd -quality 8 -autosubs -in "Video.mp4" -out "Video.mp4.tovid_encoded"

If the audio extraction fails, extract it separately and re-multiplex as follows:

faad -o outputfile.wav Video.mp4
nice -n 0 ffmpeg -i outputfile.wav -vn -ab 224k -ar 48000 -ac 2 -acodec ac3 -y ./Video.mp4.tovid_encoded/audio.ac3
mplex -V -f 8 -o
    ./Video.mp4.tovid_encoded.mpg
    ./Video.mp4.tovid_encoded/video.m2v
    ./Video.mp4.tovid_encoded/audio.ac3

Transcode a Matroska (mtk) file into DVD format

Do the initial extraction using tovid as per the steps shown above. When I did this the audio extraction failed, so I did it like this (I’m sure there is a easier way however):
Note – for the first step you will need to install the mkvtoolnix package from synaptic.

mkvextract tracks Video.mkv 2:audio.aac
faad -o outputfile.wav audio.aac
nice -n 0 ffmpeg -i output.wav -vn -ab 224k -ar 48000 -ac 2 -acodec ac3 -y audio.ac3
mplex -V -f 8 -o Video.mpg video.m2v audio.ac3 


  |  Leave a comment


Installing and configuring Ubuntu 7.04

Posted on November 27, 2007 by Adam under Ubuntu

This is a record of how I configured Ubuntu Linux 7.04 (Feisty Fawn) to run on my PC. This is purely for my own reference in case I need to reinstall it in the future, but it may be of use to other people who have similar hardware.

My hardware is as follows:

  • CPU: AMD Athlon 64 3000+
  • Graphics: ATI Radeon 9550
  • Wireless: Belkin 802.11g (Broadcom BCM4306 chipset)
  • Sound: Realtek AC’97 (on motherboard)
  • Video Capture: Conexant BtPCI
  • Webcam: Logitech Quickcam
  • Hard Drive: IDE
  • Other: iPod Nano, USB Memory Stick
  • Printer: Epson Stylus Photo 915
  • Printer: Lexmark All-in-one X4550

The good news:

The basics were detected fine and worked straight away once I installed Ubuntu. My video card was detected, I got a decent screen resolution, and the sound worked. Also, my memory stick worked, and I could browse the files on my iPod. I could also see files on the NTFS partition of my hard drive, but they were read-only.

Wherever possible I am sticking to versions of apps and libraries in the Ubuntu Feisty Universe (using Synaptic).

The bad news:

  • My wireless card didn’t work (luckily I had a wireless bridge I was able to borrow to plug into a wired port until I got it working).
  • The 3D effects (Compiz/Beryl) did’t work – no 3d acceleration.
  • Adobe flash player wouldn’t work because there is no 64 bit version 🙁

3D acceleration

To start with there was some acronyms to deal with. ATI offer a Linux driver on their web site, but it is not fully open source. It referred to as the fglrx driver. I didn’t have much luck with this driver – after installing it I still couldn’t get the 3D acceleration to work. There is an open source driver that seems to be referred to as the SGI driver, or just the “open source driver” – in the end this one worked for me.
There are lots of posts in forums that discuss ways of making it work, but it was this forum that had the answer that worked on my system: http://www.howtoforge.com/ubuntu_feisty_beryl_ati_radeon

I do still get a problem when I first start up my PC. I have to manually restart Beryl and the Emerald theme manager by typing:
(beryl &) &
(emerald &) &

Flash Player

To get flash working in firefox, I had to use something called npwrapper to allow a 64bit firefox to run a 32bit plugin. The tutorial that I found worked was this one: http://ubuntuforums.org/showthread.php?t=341727 Make sure you follow the instructions carefully and don’t skip any steps.

Wireless Network

I struggled to get my Belkin wireless card working before giving up and buying a Netgear card instead 🙂 The worked fine with the madwifi drivers that come with Ubuntu, but I did have a problem with the link dropping every so often. It appears to be a bug described here: https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/64173

Webcam

Haven’t had a chance to try this out yet.

Printing

My Epson printer was detected and showed up correctly as an Epson Stylus Photo 915, but when I tried to print the colours didn’t come out correctly. To fix it I installed the gutenprint driver – http://www.linuxprinting.org/show_driver.cgi?driver=gutenprint&fromprinter=Epson-Stylus_Photo_915

With the Lexmark printer I had more problems – it seems there is no Linux driver for the X4550. I spoke to the Lexmark technical support people and they apologised but confirmed it is not supported 🙁

Other Apps

Some other useful apps I installed:

  • Java – I had some difficulties with the versions of Java available using Synaptic, so I downloaded the binary installer for Java 6 from the Sun website and that seems to work fine.
  • IDE: Eclipse – The version of Eclipse available in Synaptic is 3.2 so not the latest, but seems to work ok.
  • IDE: Netbeans – I had a problem running this that it transpires is a problem with all swing apps when using Beryl. The only way around it at present seems to be switching back to another window manager like metacity. I tried the latest daily builds of Java 6 and even Java 7 but they all seem to have the same problem. The only workaround (of sorts) I have found is the rather clever idea of running a nested X session within the current one. Details are available here: http://www.vikrammohan.com/blog/2006/12/31/how-to-make-java-swing-work-on-beryl-with-aiglx/
  • Instant Messenger: Pidgin – A slightly newer version of Gaim. I got this one from their website, only Gaim is available in Synaptic. The sound didn’t work at first but I followed the instructions here to fix it: http://modfree.org/index.php?topic=458.msg5125 . Also, I wanted support for the sametime protocol, which meant that before compiling I had to install the libpurple-meanwhile and libpurple-meanwhile-dev packages.
  • Password Safe – This is an app I used to use on Windows and find really useful. I found that it can be run in Wine – details here: http://appdb.winehq.org/appview.php?iVersionId=8739 . Wine is also not available in Synaptic as far as I can tell, so follow these instructions to add it: http://www.winehq.org/site/download-deb
  • Browser: Firefox – Installed by default
  • Email: Thunderbird – Available in Synaptic
  • Launcher: Katapult – Available in Synaptic
  • Video Editing – I will do a separate post on this topic..
  • Podcasts – Podnova client – available from http://www.podnova.com/subscriptions/download/
  • Photo Management – Desktop Flickr Organiser. Great tool for viewing and editing your online Flickr photo collection. Available from http://code.google.com/p/dfo/
  • Album Cover Art – A clever little script you can use to display your albums in the Nautilus file manager with their cover art: http://ubuntuforums.org/showthread.php?t=486359
  • Cover Art Downloader – A handy tool for adding cover art to your music collection: http://www.unrealvoodoo.org/hiteck/projects/albumart/ . An extra step was required to make it work in Feisty: http://ubuntuforums.org/showthread.php?p=2809331
  • Screenlets – nifty little widgets to show clocks, CPU meters, calendars etc on the desktop: http://tombuntu.com/index.php/2007/08/24/osx-like-widgets-with-ubuntu-screenlets-and-compiz-fusion/

Themes

Once you have switched in the 3d effects in the appearances settings, you then have the option of two different kinds of window decorations (and therefore two different types of themes): GTK or Emerald. Switching between these and configuring them however is a bit of a pain. I came across this page which explains how to install some packages to make it all a lot easier: http://www.linuxquestions.org/questions/fedora-35/cant-get-berylemerald-theme-working-629177/

To get themes I found this site was the best: http://www.gnome-look.org



  |  1 Comment


Recording Real Audio Streams

Posted on September 30, 2007 by Adam under Ubuntu

Recording a real audio stream can be done in Linux fairly easily. The basic process is to play the stream and instead of sending the audio to your sound card you send it to a virtual sound card which saves it as a wav file. You can then encode it as an mp3 for later listening.

To do this you will need three apps installed:

  • mplayer – you will use this to play the stream
  • vsound – this is the virtual sound driver that will send the output to a wav file
  • lame – this is the mp3 encoder you will use to encode the wav file to an mp3

You can now use a simple script to record a stream and convert it to mp3. The below script takes two parameters – the first being the URL of the stream to record, and the second the filename of the mp3 to output

Script:

#/bin/bash
echo Recording stream: $1
echo To filename: $2
/usr/local/bin/vsound -f outputfile.wav /usr/bin/mplayer $1
/usr/bin/lame -v --nohist outputfile.wav $2


  |  Leave a comment


Jackrabbit on Sun App Server 7

Posted on June 29, 2007 by Adam under Jackrabbit, Java

Following on from my earlier post about how to get Jackrabbit working on WebSphere, I also faced some difficulties getting Jackrabbit to run with Sun App Server 7. I think a lot of the difficulties stem from the fact that App Server 7 had a very early implementation of the connector specification – the later versions of the app server seem to be a lot easier to set up. So here is what worked for me:

1) Configure Endorsed Libraries

Before you can deploy on Sun App Server 7 you need to configure the server instance to use a newer version of the SAX parser rather than the one built into JDK1.4. To do this carry out the following steps:

  • In the admin console, click the server instance you want to deploy under
  • Click the JVM Setting tab
  • Click the JVM Options link
  • In the blank JVM Option box at the top, enter:
  •    -Djava.endorsed.dirs=<server_root>/lib/endorsed
    

    Where <server_root> is the path of your server instance directory

  • Apply the changes to the instance
  • Now create an endorsed directory in the server’s lib directory (matching the path specified above
  • Copy recent version of xercesImpl.jar and xalan.jar into your new endorsed directory

You can get more information about ‘endorsed’ libraries here:
http://java.sun.com/j2se/1.4.2/docs/guide/standards/
http://wiki.apache.org/cocoon/EndorsedLibsProblem

2) Edit resource adapter deployment descriptors

Because App Server 7 only supports version 1.0 of the connector spec you will need to edit your ra.xml deployment descriptor slightly to make it deploy. Also, there is no way of configuring your connector in the admin console, so you need to include all the relevant config in the ra.xml and sun-ra.xml files.

So, to make it work with app server 7, carry out the following steps:

  • Download the jackrabbit-jca-1.3.rar file from the jackrabbit site (or the latest version if newer)
  • Unzip the contents to a directory
  • Find the ra.xml file inside the META-INF directory
  • Edit it to read as follows:
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    
    <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE connector PUBLIC
            '-//Sun Microsystems, Inc.//DTD Connector 1.0//EN'
            'http://java.sun.com/dtd/connector_1_0.dtd'>
        <connector>
          <display-name>Jackrabbit JCR Adapter</display-name>
          <vendor-name>Apache.org</vendor-name>
          <spec-version>1.0</spec-version>
          <eis-type>JCR Adapter</eis-type>
          <version>1.0</version>
          <license>
            <description>ASF</description>
            <license-required>false</license-required>
          </license>
          <resourceadapter>
            <managedconnectionfactory-class>org.apache.jackrabbit.jca.JCAManagedConnectionFactory
                </managedconnectionfactory-class>
            <connectionfactory-interface>javax.jcr.Repository</connectionfactory-interface>
            <connectionfactory-impl-class>org.apache.jackrabbit.jca.JCARepositoryHandle
                </connectionfactory-impl-class>
            <connection-interface>javax.jcr.Session</connection-interface>
            <connection-impl-class>org.apache.jackrabbit.jca.JCASessionHandle
                </connection-impl-class>
            <transaction-support>XATransaction</transaction-support>
            <config-property>
              <config-property-name>HomeDir</config-property-name>
              <config-property-type>java.lang.String</config-property-type>
              <config-property-value> Your repository home directory here 
                  </config-property-value>
            </config-property>
            <config-property>
              <config-property-name>ConfigFile</config-property-name>
              <config-property-type>java.lang.String</config-property-type>
              <config-property-value> Your repository config file here 
                  </config-property-value>
            </config-property>
            <reauthentication-support>false</reauthentication-support>  
          </resourceadapter>
        </connector>
  • Now, create a sun-ra.xml file in the same directory containing the following:
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    
    <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE sun-connector PUBLIC
              '-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Connector 1.0//EN'
              'http://www.sun.com/software/sunone/appserver/dtds/sun-connector_1_0-0.dtd'>
        <sun -connector>
          <resource -adapter jndi-name=" Your JNDI Name Here " max-pool-size="20" steady-pool-size="2"
              max-wait-time-in-millis="300000" idle-timeout-in-seconds="5000">
          </resource>
        </sun>
  • Now, re-zip the directory and name it jackrabbit-jca-1.3.rar (or whatever the original filename was)

3) Deploy the resource adapter

  • In the admin console, select the sever instance you want, and click Applications > Connector Modules
  • Click Deploy
  • Click browse, locate your newly edited rar file and click OK
  • On the next page make sure the name you give the app matches the JNDI name you configured in sun-ra.xml, click OK
  • You will probably also have to copy the jar files that were included in the rar file into the server’s lib directory
  • Restart your server instance

4) Make use of your repository

  • You should now be able to make use of your repository using code something like this:
  • InitialContext  ctx = new InitialContext ();
    repository = (Repository) ctx.lookup(" Your JNDI Name Here ");
    SimpleCredentials cred = new SimpleCredentials("login","password".toCharArray());
    Session session = repository.login(cred, null);
    Workspace workspace = session.getWorkspace();
    

    Potential Problems

    I thought I would mention some of the problems I had setting this up so you can avoid making similar mistakes.

    Firstly, make sure your repository.xml is correct, and especially make sure that you have the LoginModule element included – something like:

    1
    2
    3
    
    <loginmodule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
                    <param name="anonymousId" value="anonymous"/>
            </loginmodule>


      |  Leave a comment


    Jackrabbit on WebSphere

    Posted on June 10, 2007 by Adam under Jackrabbit, Java

    I had quite a few problems initially deploying Jackrabbit on Websphere 5.1, so I thought I would document the process to help anyone else who wants to deploy on this environment. I did this using jackrabbit 1.3 on Websphere 5.1, so I can’t guarantee it will work the same on other versions.

    Admittedly I did not know much about using the JCA (Java Connector Architecture) before I started, so I attribute some of my difficulties to my own ignorance.
    If you are interested in a good example of how to use JCA connectors on Websphere, there is a good tutorial available at: http://www-128.ibm.com/developerworks/ibm/library/i-supply1a/

    Initially I got Jackrabbit working in WebSphere by deploying it as a Resource Environment Provider in a similar manner as described here: http://epesh.blog-city.com/jackrabbit_and_glassfish_v2.htm
    Only, this is not a good way of deploying it as multiple web apps are not in fact sharing the same repository in memory in this model, and running multiple repositories against the same physical filesystem is not supported in Jackrabbit. The correct way of deploying a shared jackrabbit repository in Websphere is as a resource adapter. This provides a single shared jackrabbit instance and also provides things like connection pooling for connections to jackrabbit. This can then be accessed by looking it up via JNDI.

    I also have to admit to a certain ignorance about basic JNDI concepts, but the Sun tutorial really helped me to understand it better: http://java.sun.com/products/jndi/tutorial/

    Here is the steps I took to get it working:

    1) Edit the ra.xml in the resource adapter

    • Download the jackrabbit-jca-1.3.rar file from the jackrabbit site
    • Unzip the contents to a directory
    • Find the ra.xml file inside the META-INF directory
    • Edit it to read as follows:
    • 1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      
      <?xml version="1.0" encoding="UTF-8"?>
         <!DOCTYPE connector PUBLIC
            '-//Sun Microsystems, Inc.//DTD Connector 1.0//EN'
            'http://java.sun.com/dtd/connector_1_0.dtd'>
         <connector>
           <display-name>Jackrabbit JCR Adapter</display-name>
           <vendor-name>Apache.org</vendor-name>
           <spec-version>1.0</spec-version>
           <eis-type>JCR Adapter</eis-type>
           <version>1.0</version>
           <license>
             <description>ASF</description>
             <license-required>false</license-required>
           </license>
           <resourceadapter>
             <managedconnectionfactory-class>
                org.apache.jackrabbit.jca.JCAManagedConnectionFactory
             </managedconnectionfactory-class>
             <connectionfactory-interface>
                javax.jcr.Repository
             </connectionfactory-interface>
             <connectionfactory-impl-class>
                org.apache.jackrabbit.jca.JCARepositoryHandle
             </connectionfactory-impl-class>
             <connection-interface>
                javax.jcr.Session
             </connection-interface>
             <connection-impl-class>
                org.apache.jackrabbit.jca.JCASessionHandle
             </connection-impl-class>
             <transaction-support>NoTransaction</transaction-support>
             <config-property>
               <config-property-name>HomeDir</config-property-name>
               <config-property-type>java.lang.String</config-property-type>
             </config-property>
             <config-property>
               <config-property-name>ConfigFile</config-property-name>
               <config-property-type>java.lang.String</config-property-type>
             </config-property>
             <authentication-mechanism>
               <authentication-mechanism-type>
                  SimpleCredentials 
               </authentication-mechanism-type>
               <credential-interface>
                  javax.jcr.SimpleCredentials
               </credential-interface>
             </authentication-mechanism>
             <reauthentication-support>false</reauthentication-support>
           </resourceadapter>
         </connector>
    • Now, re-zip the directory and name it jackrabbit-jca-1.3.rar

    2) Deploy the Resource Adapter

    • To deploy your newly edited resource adapter in Websphere into the admin console:
    • Click Resources > Resource Adapters
    • Click “Install RAR”
    • Click browser and select your RAR file created above
    • Click “Next”
    • Leave all the boxes empty on the next page and click “OK”
    • If you get a ConfigServiceException at this point you may need to set some config manually – scroll down to the bottom of this entry for details on how to do this
    • Go back to Resources > Resource Adapters
    • Click “New”
    • Give your new resource a name (I used Jackrabbit)
    • Select jackrabbit-jca-1.3.rar from the archive path drop-down
    • Click “Apply”

    3) Create a connection factory

    • Scroll down and click “J2C Connection Factories”
    • Click “New”
    • Give your factory a name (I went for Jackrabbit again)
    • Type the jndi name you want to use (I went for jcr/local)
    • Select “BASIC_PASSWORD” from the authentication preference
    • Set both authentication aliases to (none)
    • Set mapping-configuration alias to DefaultPrincipalMapping
    • Click “Apply”
    • Scroll down and click “Custom Properties”
    • Set the values of HomeDir and ConfigFile to appropriate values
    • Save your changes to the master configuration.

    4) Make use of your repository

    • You should now be able to make use of your repository using code something like this:
          InitialContext ctx = new InitialContext();
          repository = (Repository) ctx.lookup("jcr/local");
          SimpleCredentials cred = new SimpleCredentials("login","password".toCharArray());
          Session session = repository.login(cred, null);
          Workspace workspace = session.getWorkspace();
    

    Potential Problems

    I thought I would mention some of the problems I had setting this up so you can avoid making similar mistakes.

    Firstly, make sure your repository.xml is correct, and especially make sure that you have the LoginModule element included – something like:

    1
    2
    3
    
    <loginmodule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
                    <param name="anonymousId" value="anonymous"/>
            </loginmodule>

    Note – the reason I had to specify ‘NoTransaction’ in the config is to work around a bug that I discovered which I have reported to the development team – more details here: http://issues.apache.org/jira/browse/JCR-861

    UPDATE: Looks like as of version 1.4 my bug has been fixed 🙂

    ConfigServiceException

    In some cases when deploying Jackrabbit on WebSphere I came across this exception:

     com.ibm.websphere.management.exception.ConfigServiceException
       at com.ibm.ws.management.configservice.WorkspaceHelper
                 .getTemplate(WorkspaceHelper.java:274)
       at com.ibm.ws.management.configservice.WorkspaceHelper
                 .getTemplate(WorkspaceHelper.java:208)
       at com.ibm.ws.management.configservice.MOFUtil.newRefObject(MOFUtil.java:78)
       at com.ibm.ws.management.configservice.MOFUtil.createRefObject(MOFUtil.java:1053)
       at com.ibm.ws.management.configservice.MOFUtil.createRefObject(MOFUtil.java:314)
       at com.ibm.ws.management.configservice.DocAccessor
                 .createRootConfigObject(DocAccessor.java:137)
      ...etc...
    

    To get over this:

    First – follow the instructions above, and when you get the error above, do the following:

    1) Create a Resource Adapter

    • In the admin console, click Resources > Resource Adapters
    • Click New
    • Give your adapter a name (e.g. jackrabbit)
    • In the Archive Path, choose to specify the path, and type:
    •     ${CONNECTOR_INSTALL_ROOT}/jackrabbit-jca-1.3.rar
      
    • Click Apply
    • Save your changes to the master repository

    2) Edit the Resource Adapter config manually

  • – Find the resources.xml file for your server instance, this should be in a path like this:
  •     [base_dir]/config/cells/[cellname]/nodes/
                [nodename]/servers/[servername]/
    
  • Open the file, and find the section that looks like this:
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    <resources.j2c:J2CResourceAdapter xmi:id="J2CResourceAdapter_1179115582274" name="jackrabbit"
           archivePath="${CONNECTOR_INSTALL_ROOT}/jackrabbit-jca-1.3.rar">
            <propertySet xmi:id="J2EEResourcePropertySet_1179115582274">
              <resourceProperties xmi:id="J2EEResourceProperty_1179115582274"
               name="TransactionResourceRegistration" type="java.lang.String" value="dynamic"
               description="Type of transaction resource registration (enlistment).  Valid values are
               either "static" (immediate) or "dynamic" (deferred)."/>
              <resourceProperties xmi:id="J2EEResourceProperty_1179115582275"
               name="InactiveConnectionSupport" type="java.lang.Boolean" value="true"
               description="Specify whether connection handles support implicit reactivation. (Smart
               Handle support). Value may be "true" or "false"."/>
            </propertySet>
          </resources.j2c:J2CResourceAdapter>
  • And change the resourceProperties elements:
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    
    <resources.j2c:J2CResourceAdapter xmi:id="J2CResourceAdapter_1179115582274" name="jackrabbit"
           archivePath="${CONNECTOR_INSTALL_ROOT}/jackrabbit-jca-1.3.rar">
            <propertySet xmi:id="J2EEResourcePropertySet_1179115582274">
              <resourceProperties xmi:id="J2EEResourceProperty_1179115582274"
               name="HomeDir" type="java.lang.String"/>
              <resourceProperties xmi:id="J2EEResourceProperty_1179115582275"
               name="ConfigFile" type="java.lang.String"/>
            </propertySet>
          </resources.j2c:J2CResourceAdapter>

    Restart WebSphere so the changes get picked up and go back to step 3 in the instructions at the start of this post.



      |  10 Comments