Friday, July 9, 2010

Problem with Red5 - SLF4JLogFactory does not implement LogFactory

I'm currently working on a team of more at least 16 developers -- the largest team I worked with on a very complicated project.

The setup is a central J2EE application that runs on JBoss, web application that written in PHP (powered by Apache web server), and a rich internet application written in ActionScript (yep, a Flash application). This Flash application communicates to Red5 server which runs on Tomcat.

If that's not complicated enough for you, continue reading.

The Flash application is a sub-application of the PHP web application. Both the PHP and Flash applications communicates to J2EE application. The PHP uses WSDL and the Flash uses Axis.

The PHP application gives data to the Flash application to let the Red5 server communicate with the J2EE application-- again, via Axis.

To make matters worse, the JBoss, Apache, and Tomcat servers are running on three different machines.

Now, when something in the process broke, it's up to the lead developers to debug it.

As I am the lead on the Flash application that communicates on Red5 server, I am oblige to find the solution.

How on Earth are you going to debug which caused which bug?

Well, the good thing in this complicated project is that it uses free and open source software and open data -- except for Adobe Flash specifics, that is. (For the record, I'm using the open source Flex SDK with FlashDevelop -- it's the Flash' SharedObject-thingy that Red5 uses I'm worried about not being open format/data)

Step-by-step, it boiled down to Red5 and Axis.

Another good thing is, a good person with a good heart by the name Jim O'Halloran, blogged about his same experience, six months earlier.

It turns out that Axis uses commons-logging.jar, which contains same classes (but not same version) of what Red5 uses. This makes the error that Red5 kept whining about:
Caused by: org.apache.commons.discovery.DiscoveryException: Class org.apache.commons.logging.impl.SLF4JLogFactory does not implement org.apache.commons.logging.LogFactory

As O'Halloran suggested, removing the JAR file for commons-logging then restarting Red5 will solve the problem. And it did!

If this helped you too, thank Jim O'Halloran. Send him beer or pizza if you could. ^^

Saturday, July 3, 2010

Using PHP with Red5

The default installation of Red5 doesn't include support for PHP. And since Red5 is ran by Tomcat, this means we need Tomcat to handle PHP.

I found a tutorial that requires you to recompile Tomcat with PHP-handling. Tedious task for a simple need of enabling PHP. Good thing, there's Quercus -- a 100% Java implementation of PHP 5. This means that it can be used with Tomcat.

What I did was, download Quercus 4.0.3 binary, then extracted file to a temporary location.

Now move the following files from the Quercus' temporary location,
  • /WEB-INF/lib/inject-16.jar
  • /WEB-INF/lib/javamail-141.jar
  • /WEB-INF/lib/resin.jar

to your Red5 installation's /webapps/root/WEB-INF/lib/{here}. Create the /lib directory on Red5's /root/WEB-INF if needed.

Now, here's the part where you need to be cautious.

From Red5's /webapps/root/WEB-INF/ location, then open web.xml.

Add the following before the </web-app> tag.
<servlet>
  <servlet-name>Quercus Servlet</servlet-name>
    <servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>Quercus Servlet</servlet-name>
    <url-pattern>*.php</url-pattern>
</servlet-mapping>

<welcome-file-list>
  <welcome-file>index.php</welcome-file>
</welcome-file-list>



Now, try creating a helloworld.php to test Quercus.

Make sure to restart your Red5.