Thursday 30 July 2009

Liferay Flash Movie Hack

Currently were displaying a company movie in some journal article on our Liferay portal, but the movie isn't located on the Liferay server itself. This was all working nice and dandy, but now the server it is hosted on is being migrated and the hack we used to host the movie on it won't be available on the new server. The hack we used was to place the movie file into a custom folder inside the 'docroot' folder of a Glassfish domain.

Since the server was being migrated and it was already a hack, something had to change, preferably for the better. So we were looking into placing the movie, the movie player and the skin for the movie player, all .flv files into the Liferay document library. Well this is were we ran into the first problems:
  • File extension: .flv and .swf files can't be added to the library by default. Solution: adding dl.file.extensions=.flv,.swf,.mov,.avi,.mp4,.mp3,.m4v,.bmp,.css,.doc,.dot,.gif,.gz,.htm,.html,.jpg,.js,.lar,.odb,.odf,.odg,.odp,.ods,.odt,.pdf,.png,.ppt,.rtf,.swf,.sxc,.sxi,.sxw,.tar,.tiff,.tgz,.txt,.vsd,.xls,.xml,.zip to your portal-ext.properties and restarting the portal. We also tried dl.file.extensions=* and dl.file.extensions=.*, but both didn't work as expected.
  • File size: the movie file turned out to be to big for the document library, but this can be solved by adding dl.file.max.size=0 to your portal-ext.properties and restarting the portal.
So now we had all the necessary files present in the Liferay document library, so you would think that we would only have to switch out the URLs in our movie journal article and hey presto! But, this didn't work. The page would show up, but the movie wouldn't. So after Googling a bit and looking around the Liferay forums, we found a promising post that claims that you have to URLEncode the document URLs and then it should work. We tried this in various ways, by hand and by using a Velocity template to do the hard work in a repeatable way, but still the movie wouldn't show.

Now we were getting desperate, what other possibilities were left? A custom portlet maybe? We tried some more of the stuff mentioned in the Liferay forums, when we saw some reference to Flash content in the following path /html/js/flashutils/player.swf. We check our Liferay installation and in the /webapps/ROOT directory we found a /html directory. We created a new directory, media, beneath it, placed our three Flash files in it and referenced to them from our journal article as follows (other paths are similar):

<param name="movie" value="/html/media/movie.flv" />

We saved the article, browsed to the correct page and now the movie is shown in its full glory. Disclaimer: this is a dirty hack, we don't recommend to use it, certainly not in a structural way, but until we've found a better, working solution, this does solve our problem for now.

Tuesday 28 July 2009

Liferay theme problem

A while ago we were getting some issues reported from users that wew seeing some strange screens when accessing our Liferay portal. Although they saw most of the data we expected them to see, it wasn't presented properly, as if no theme was being applied. Looking in the logs didn't turn up anything useful and since I didn't see it with my own eyes I instructed the user that reported the error to email me a screenshot when it happened again.


So fast forward to today and I get an email with a screenshot. The screen is pretty white generally, but contains all the data, text and images, that I would expect on that given page, but it looks like no theme at all is applied. It check it for myself using Firefox, the user that reported the problem is using IE and you never know, and low and behold, I get the same fucked up page. So immediately I dive into the logs again, but still nothing.


So what could it be, maybe the portal thinks it is being accessed by a mobile device and presents a simpler theme? But that doesn't really make sense since both the user and I are using desktop browsers. Still I check the theme settings on the portal using the 'Manage Pages' part of the dock, but everything seems to be in order. So next step, check Google. And there we find something interesting, a caching problem: LPS-2834. This issue describes exactly what we are experiencing since after a few refreshes in my browser I get the correctly rendered portal page again. So it seems that something gets cached when a mobile device accesses the portal, but that this cached result is also returned when a non mobile browser requests the same content.


So we could apply the patch that is attached to the issue, but we'll probably use this issue as an excuse to do an upgrade to Liferay Portal 5.2.2 as this will solve this bug and some other problems we're having with our current Liferay Portal 5.1.1 on which I may or may not elaborate in the future.