|
|
< Day Day Up > |
|
Debugging and LoggingTroubleshooting a JSF application can be painful. So many minor details must be just right or your application won't work. Error messages can be hard to find or nonexistent. Minor typos can give rise to an application that simply doesn't start or that seems to get stuck. The items in this section contain some tips to help you out. How do I decipher a stack trace?When you see a screen such as the one in Figure 12-17, count yourself lucky. Figure 12-17. Error Page![]() Read the first line (or the first line that seems to make some sense), and correlate it with your JSF file. In this case, there is an illegal tag (inputTaxt instead of inputText) in line 16, column 21, or hopefully somewhere near there. The error report may also indicate a problem with your code. For example,
java.lang.ClassCastException
com.corejsf.UploadRenderer.decode(UploadRenderer.java:73)
javax.faces.component.UIComponentBase.decode(UIComponentBase.java:658)
javax.faces.component.UIInput.decode(UIInput.java:464)
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:878)
javax.faces.component.UIInput.processDecodes(UIInput.java:380)
javax.faces.component.UIForm.processDecodes(UIForm.java:139)
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:873)
javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:305)
com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:79)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
com.corejsf.UploadFilter.doFilter(UploadFilter.java:68)
The remedy is straightforward. Have a look at line 73 of UploadRenderer.java and find out what caused the bad cast. TIP
Sometimes, the situation is not so rosy. Consider this report: javax.servlet.ServletException: javax.faces.el.EvaluationException: Error getting property Here, the subsystem that evaluates the expression language has wrapped an exception in the bean code inside an EvaluationException. You get to know where the EvaluationException is thrown, but that doesn't help you—you need the location of the NullPointerException that caused it. Your next step is to inspect the log files. In this case, the log contains a more detailed report: Caused by: javax.faces.el.EvaluationException: Error getting property 'password' from bean Finally, information you can use: Line 12 of UserBean.java caused the problem. Unfortunately, sometimes the stack trace gives you no useful information at all. Here is an example of a bad case.
javax.servlet.ServletException: Cannot find FacesContext
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.index_jsp._jspService(index_jsp.java:78)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
What caused this error? Misalignment of the planets? No—the problem was a bad URL: http://localhost:8080/login/index.jsp instead of http://localhost:8080/login/index.faces. How do I find the logs?The details depend on your JSF container. Tomcat 5 keeps logs in the tomcat/logs directory. The standard Tomcat log files are
Here date is a date stamp such as 2003-06-30. The catalina.out file contains all output that was sent to System.out and System.err. The localhost_log.date.log files contain the logging messages that were generated by the servlet context. NOTE
By default, Tomcat is configured to map Commons logging to the java.util.logging package. By default, that package is configured so that all messages with level INFO and higher are sent to System.out. Thus, most Tomcat messages end up in catalina.out. A much smaller number of messages are sent to the servlet context log, another logging facility that is completely unrelated to Commons logging. Therefore, you should check the localhost_log.date.log if catalina.out doesn't have the message you are looking for. The catalina.out file is specified in the startup script (catalina.sh or catalina.bat in the tomcat/bin directory). The localhost_log.date.log files are configured in tomcat/conf/server.xml. If you use the Tomcat implementation in the Java Web Services Development Pack, then the files are called launcher.server.log and jwsdp_log.date.log. How do I find out what parameters my page received?It is often helpful to know what parameters the client sent back to the server when a form was submitted. Here is a quick and dirty method for logging the request parameters. Insert this snippet of code on top of the JSF file that receives the request:
<%
java.util.Enumeration e = request.getParameterNames();
while (e.hasMoreElements())
{
String n = (String) e.nextElement();
String[] v = request.getParameterValues(n);
for (int i = 0; v != null && i < v.length; i++)
java.util.logging.Logger.global.info("name=" + n + ",value=" + v[i]);
}
%>
Then catalina.out will contain entries such as Apr 2, 2004 12:50:45 PM org.apache.jsp.welcome_jsp _jspService INFO: name=_id0,value=_id0 Apr 2, 2004 12:50:45 PM org.apache.jsp.welcome_jsp _jspService INFO: name=_id0:_id1,value=me Apr 2, 2004 12:50:45 PM org.apache.jsp.welcome_jsp _jspService INFO: name=_id0:_id2,value=secret Apr 2, 2004 12:50:45 PM org.apache.jsp.welcome_jsp _jspService INFO: name=_id0:_id3,value=Login How do I turn on logging of the JSF container?The JSF reference implementation contains copious logging statements whose output can be very helpful in tracking down problems with your applications. Here, we assume that Tomcat has been configured to use the java.util.logging library that was introduced in SDK 1.4. This is the default setting for Tomcat.
To turn off JSF container logging, simply edit tomcat/conf/logging.properties and change com.sun.faces.level to INFO. NOTE How do I replace catalina.out with rotating logs?Again, we assume that Tomcat has been configured to use the java.util.logging library that was introduced in SDK 1.4. This is the default setting for Tomcat.
How do I find the library source?You can download the library source from http://www.sun.com/software/communitysource/jsf. The library source can be very helpful for troubleshooting, and to clarify opaque points of the specification. The library code is organized in four directories:
In order to get a complete set of source files, you must run the Ant script in the jsf-tools directory.
Finally, it is sometimes useful to find configuration details of the JSF implementation, such as the names of the standard components, renderers, converters, and validators. Look inside the files jsf-ri/src/com/sun/faces/jsf-ri-config.xml and jsf-api/doc/standard-xml-renderkit.xml. |
|
|
< Day Day Up > |
|