handling java exceptions in Flex

May 7th, 2010 by Dave Turner

Gracefully handling Java Exceptions in a BlazeDS Flex App.

When a Java method throws an exception (see example)

public static boolean someMethod(boolean myVar) throws Exception
{
  if(myVar)
    throw new Exception("A Simple Exception");
  else
   return true;
}

To handle the Exception gracefully (i.e. strip out the stack trace and display just the Error message)

import mx.messaging.messages.ErrorMessage;
....
private function onDBErrorError(event:FaultEvent):void
{
  var msg:ErrorMessage = event.message as ErrorMessage;
  Alert.show(msg.rootCause.message);
}

Hope this helps..

Connecting Apache to Tomcat utilizing Mod_JK

February 21st, 2010 by Dave Turner

Mod JK is the Apache  to Tomcat Connector.  It allows one to serve Tomcat webapps from Apache Http server.

Steps to install.
Note: This is based off my machines setup Apache 2.2.14, Tomcat 6, Windows 7 64 Bit, Mod JK 1.2.28

1. Download Apache webserver, Install it and verify it is running see “http://httpd.apache.org/” for more information.

2. Download Tomcat, Install it and verify it is running. See “http://tomcat.apache.org/” for more information

3. Download the Apache Tomcat Connector and copy it to [APACHE_ROOT]/modules. See http://tomcat.apache.org/connectors-doc for more information.

I was able to download the MOD_JK here http://apache.multihomed.net/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/

4. Create a “workers.properties” file and place it at [TOMCAT_ROOT]/conf/jk

AJP13 worker is the preferred worker type that JK uses for communication between web server and Tomcat. Here is a simple implementation of the workers.properties file

worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

5. Edit the Apache Configuration file [APACHE_ROOT]/conf/httpd.conf in the following way

LoadModule jk_module /modules/mod_jk-1.2.28-httpd-2.2.3.so
Include "[PATH_TO_TOMCAT]/conf/auto/mod_jk.conf"

6. Edit Server.xml in [TOMCAT_ROOT]/conf in the following manner.

Under the <Server> node add this

<Listener className = "org.apache.jk.config.ApacheConfig"
workersConfig="conf/workers.properties"
mod_Jk="[PATH_TO_APACHE]/modules/mod_jk.so"
jkLog="logs/mod_jk.log" jkDebug="info" noRoot="false"/>

Under the <Engine> node add this

Restart Tomcat.. You should see a new file [TOMCAT_ROOT]/conf/auto/mod_jk.conf

Restart Apache.. you should be good