Alfresco Developer Guide
上QQ阅读APP看书,第一时间看更新

Troubleshooting

There are three primary troubleshooting tools you will become intimately familiar with: Log4j, your favorite Java debugger, and the Alfresco Node Browser. There are other, less-frequently used tools and techniques that will be discussed when the time is right.

Log4j

Most of you are already familiar with this common logging tool, so not a lot of discussion is needed. For everyone else, here are the basics. The verbosity of the log output, the specific classes being logged, and other logging settings are controlled by the log4j.properties file located in WEB-INF|classes. This is one file distributed with Alfresco that is OK to touch. For example, if you are testing out some server-side JavaScript, you might want to change the JavaScript-related logger from error to debug like this:

log4j.logger.org.alfresco.repo.jscript=DEBUG

If you want to add your own logger for one of your own Java classes, add a new logger to the end of the file like this:

log4j.logger.com.someco=DEBUG

Then, within your class, call the logger's methods like this:

public class SetWebFlag extends ActionExecuterAbstractBase {
private static Logger logger = Logger.getLogger(SetWebFlag.class);
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
if (logger.isDebugEnabled()) logger.debug("Inside executeImpl");

The call to DebugEnabled() isn't required, but it may help a bit with performance.

Step-by-Step: Debugging from within Eclipse

Like Log4j, stepping through the source code of a web application with a remote debugger will be familiar to many readers. Just in case it is new to you, this section walks you through the setup when using Eclipse as your IDE and Alfresco running in a standalone Tomcat instance.

At a high level, what you are going to do is tell Tomcat to send debug information to a specific port. Then, you will tell Eclipse to listen for that information using the same port. This setup will let you set breakpoints in the source code (both yours and Alfresco's), which will get tripped when the JVM processes a statement that has a breakpoint set.

Follow these steps to set this up:

  1. Set the JPDA_TRANSPORT environment variable to dt_socket.
  2. Set the JPDA_ADDRESS environment variable to 8000.
  3. In Tomcat's startup script, change the line that invokes Catalina to include jpda. On Linux, this looks like:
     exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"
    
  4. Start Tomcat. You should see a message like "Listening for transport dt_socket at address: 8000".
  5. In Eclipse, go to the Debug Configuration dialog and create a new Remote Java Application. Browse to the project you want to debug. Take the defaults for everything else:
    Step-by-Step: Debugging from within Eclipse
  6. Click Debug.

You are now ready to debug. If you want to try this out on your own, try setting a breakpoint on something you will hit quickly such as the getUsername method in the LoginBean. You can navigate to it in Eclipse by going to the SDK AlfrescoEmbedded project, Referenced Libraries, alfresco-web-client.jar, in the org.alfresco.web.bean package. Once you've found the getUsername method in the LoginBean Java source, double-click the left margin to set a breakpoint. The checkmark that appears as part of the breakpoint indicates that this breakpoint is enabled and the class is loaded:

Step-by-Step: Debugging from within Eclipse

Now open the Alfresco web application in your browser and click the Login link. Eclipse will launch the Debugger perspective. You can then step through the source line by line using the bouncing arrow icons or click the green arrow to continue to the next breakpoint:

Step-by-Step: Debugging from within Eclipse

Node Browser

Node Browser

The Alfresco Node Browser, accessible through a link on the Administration Console, lets you navigate through the low-level representation of the repository. As you drill into each store and navigate the hierarchy of nodes stored within it, the Node Browser displays useful information about each node such as its path, unique ID, node reference, and type. Every property on the node is displayed as well as the aspects that have been applied, the permissions that have been set, and the relationships that have been established with other objects.

Besides being able to navigate the hierarchy, the Node Browser also provides a search box. If you know a node's reference, you can go right to it using the Node Browser's search tool. The search box is also handy for testing out Lucene and Xpath queries.