I re-ghosted a Windows box today, so I decided to set up Macromedia Flex with Apache Tomcat. Shooting from the hip, I just unzipped the Flex samples.war file into Tomcat's webapps directory with all the other web applications. Initially excited to see if everything would just work right out of the box with no further configurations, I launched the Flex Samples Explorer application. The application compiled, and the main Explorer interface loaded. However, the Hello World mini-app, which is the first one to load by default, threw a pop-up alert for:


HTTPService Fault
Internal Server Error

A quick look at {Tomcat}/webapps/samples/WEB-INF/flex/logs/flex.log revealed a somewhat unhelpful message in the log because Flex debugging features were not enabled. The message, repeated once for every time I clicked on a mini-app in the Explorer, was:


ERROR %%500%%Internal Server Error


Well, I needed more to go on than that, so I stopped Tomcat, and edited the flex-config.xml file to turn all debugging features on, such as keep-generated-swfs, keep-generated-as, etc..., and I changed the log levels from INFO to DEBUG. Restarting Tomcat and requesting the Flex Explorer app had no effect on the initial problem, and of course I was again presented with the HTTPService Fault.


Another examination of the flex.log revealed a great deal of very useful information. Specifically, this message:


ERROR -- GET status: 500, reason: Internal Server Error, target: http://localhost:8080/samples/explorer/formatsource.jsp?url=quicktour/Hello.mxml


Ok, so the Explorer Hello World mini-app was trying to load the example source file in the source tab, and it was trying to use an HTTP call to a jsp to get that source. I copied the URL from the log and entered it in the browser. With all the debugging features turned on in flex-config.xml, I was presented with a very helpful error message and a stack trace. The error message went so far as to tell me *exactly* what the problem was, and *exactly* how to solve it. It turns out that Tomcat couldn't find a compiler for the jsp file, as shown in this Flex error message:


Requested page cannot be displayed

An unexpected error occurred that prevented /samples/explorer/formatsource.jsp from being displayed.

Unable to compile class for JSP No Java compiler was found to compile the generated source for the JSP. This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK to the common/lib directory of the Tomcat server, followed by a Tomcat restart. If using an alternate Java compiler, please check its installation and access path.

Technical Information: HTTP Status Code: 500 Exception Type: class org.apache.jasper.JasperException Servlet Name: jsp

Exception org.apache.jasper.JasperException Unable to compile class for JSP

No Java compiler was found to compile the generated source for the JSP. This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK to the common/lib directory of the Tomcat server, followed by a Tomcat restart. If using an alternate Java compiler, please check its installation and access path.


Following the instructions in the error message, I copied my {JAVA_HOME}/lib/tools.jar to {Tomcat}/common/lib/tools.jar. I restarted Tomcat, requested the Flex Examples application again, and voila everything worked like a champ. These verbose, debug error messages from Flex are going to make working with a J2EE application a whole lot easier!!


With the Flex Samples Explorer working now, an examination of flex.log showed great debug information about the GET request and response. Here's the complete GET request/response pair from Hello.mxml that was outputted to flex.log while flex-config.xml was configured for maximal debugging:


04/01 21:54:52 INFO -- GET status: 200, reason: OK, target: http://localhost:8080/samples/explorer/formatsource.jsp?url=quicktour/Hello.mxml
04/01 21:55:17 INFO -- GET : http://localhost:8080/samples/explorer/formatsource.jsp?url=data/WebServiceDemo.mxml
04/01 21:55:17 INFO -- Cookie in request: domain = localhost path = /samples name = JSESSIONID value = 57E43E5F8AF069706E5B3CD9FDE4B20E
04/01 21:55:17 INFO -- Header in request: accept : */*
04/01 21:55:17 INFO -- Header in request: x-flash-version : 7,0,19,0 04/01 21:55:17 INFO -- Header in request: content-type : application/x-www-form-urlencoded
04/01 21:55:17 INFO -- Header in request: flex-http-service : true
04/01 21:55:17 INFO -- Header in request: user-agent : Mozilla/4.0
04/01 21:55:17 INFO -- Header in request: connection : Keep-Alive
04/01 21:55:17 INFO -- Header in request: cache-control : no-cache
04/01 21:55:18 INFO -- Cookie in response: domain = localhost path = /samples name = JSESSIONID value = 57E43E5F8AF069706E5B3CD9FDE4B20E
04/01 21:55:18 INFO -- Header in response: Content-Type : text/html;charset=utf-8
04/01 21:55:18 INFO -- Header in response: Date : Fri, 02 Apr 2004 02:55:18 GMT
04/01 21:55:18 INFO -- Header in response: Server : Apache-Coyote/1.1
04/01 21:55:18 INFO -- Begin GET response --
04/01 21:55:18 INFO
{snip}The Hello.mxml source was here in the log{/snip}
04/01 21:55:19 DEBUG keep generated SWFs = true
04/01 21:55:19 INFO -- End GET response --


The Flex troubleshooting process is significantly facilitated by the wide range and depth of debug settings built into Flex.


Flex Debugging Resources: