As mentioned above, the RPC API is intended to be as generic as possible so implementations can support a wide variety of transports and remote systems. However, this flexibility also puts a lot of burden on the implementer. To simplify the process, the atg.integration package includes basic implementations of the Command and CommandHandler interfaces. Rather than implementing the interfaces directly, you can just extend the BaseCommand and BaseCommandHandler classes.

The atg.integrations.BaseCommand class provides an execute() method that implements the logic described in the Command Interface section above. Classes that extend this class must provide their own implementations of the invokeRPC() method.

The atg.integrations.BaseCommandHandler class provides an executeCommand() method that implements the logic described in the CommandHandler Interface section above. Classes that extend this class can override the executeCommand() method to do their pre- or post-processing as needed. Implementing this method can be simplified by having the executeCommand() method of the subclass call the executeCommand() method of the parent class while adding pre- or post-processing of its own. For example, a CachingCommandHandler class might look like this:

Public class CachingCommandHandler extends BaseCommandHandler {
 Map sCache = new HashMap(); // Cache of method invocations.
Public CommandResult executeCommand(Command pCommand, Object pInput) {
 if (sCache.containsKey(pInput)) {
 return sCache.get(pInput);
 }
else {
 CommandResult result = super.executeCommand(pCommand, pInput);
 sCache.put(pInput, result);
 return result;
 }
}
}

For more information about BaseCommand and BaseCommandHandler, see the ATG Platform API Reference.

Exception Handling

The Command.execute(), Command.invokeRPC(), and CommandHandler.executeCommand() methods must throw exceptions of class atg.integration.CommandInvocationException. This exception is intended to wrap any underlying exceptions that might be thrown by a particular transport or remote system. This exception must wrap the underlying exception, rather than copying its message, so that stack trace printouts include the information from the underlying exception.

The CommandInvocationException class has two useful subclasses:


Copyright © 1997, 2016 Oracle and/or its affiliates. All rights reserved. Legal Notices