I am in the process of upgrading from velocity-tools 1.0 to velocity-tools 1.1 in my existing Struts 1.1-based application.
This app was working perfectly before the upgrade (just one JAR file) and now I get an NPE whenever I use the velocity-tools's LinkTool.setForward() method.
Here's the relevant part of the stack trace:
java.lang.NullPointerException
at org.apache.struts.util.RequestUtils.forwardURL(RequestUtils.java:1535)
at org.apache.velocity.tools.struts.StrutsUtils.getForwardURL(StrutsUtils.java:593)
at org.apache.velocity.tools.struts.StrutsLinkTool.setForward(StrutsLinkTool.java:82)
Line 593 of StrutsUtils.java is:
url.append(RequestUtils.forwardURL(request, fc));
I've added logging to the class and I generate this output just before the call to forwardURL is made:
2004-06-11 16:50:16,081 [TP-Processor3] DEBUG crap- [EMAIL PROTECTED], fc=ForwardConfig[name=home,path=/index.vm,redirect=false,contextRelative=false]
So, I'm passing non-null values to RequestUtils.forwardURL.
Line 1534 and 1535 of RequestUtils.java are:
ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
String forwardPattern = moduleConfig.getControllerConfig().getForwardPattern();
I've added logging to the class and I generate this output just before the call to getControllerConfig():
2004-06-11 17:18:34,609 [TP-Processor3] DEBUG crap- moduleConfig = null, controllerConfig=[doh]
Where [doh] indicates that moduleConfig is null and therefore I can't actually find out what moduleConfig.getControllerConfig() would be.
As I said, everything was working fine before the velocity-tools upgrade, but the issue seems to be either with Struts or will some configuration of Struts.
I have a very simple struts-config.xml file. I'll spare you the details, but suffice it to say that I have the following in my config file:
- 2 form-beans - 1 global-exception handler - maybe a dozen global-forwards - maybe a dozen action-mappings
That's it. I don't have any data-sources, controllers, or plug-ins defined. I'm not attempting any voodoo (that I know of) or using any weird custom anything.
I found this issue mentioned as bug 27080 (http://issues.apache.org/bugzilla/show_bug.cgi?id=27080), and it was RESOLVED INVALID, with the comment that, in order to use RequestUtils.findForward, you must first invoke a Struts action.
By running the request first through a Struts action (really an action mapping which is really a forward directly to the .vm page), I get the following debugging output:
2004-06-11 17:38:12,166 [TP-Processor3] DEBUG crap- moduleConfig = [EMAIL PROTECTED], controllerConfig=ControllerConfig[bufferSize=4096,contentType=text/html,inputForward=false,locale=true,maxFileSize=250M,memFileSize=256K,multipartClass=org.apache.struts.upload.CommonsMultipartRequestHandler,nocache=false,processorClass=org.apache.struts.action.RequestProcessor]
and the page loads correctly.
Now, the ModuleConfig displayed in the debugging output is the same one that is available in the application scope, so it seems to me that I should not have to direct my page access through a Struts action since the ModuleConfig is available through the application (rather than the request).
Am I totally off the mark, here?
I don't claim to understand the subtleties of how Struts works in more complex environments (like with multiple modules, etc.) but I would think that a reasonable course of action would be:
ModuleConfig moduleConfig = (ModuleConfig)request.getAttribute(Globals.MODULE_KEY);
if(null == moduleConfig) moduleConfig = (ModuleConfig)application.getAttribute(Globals.MODULE_KEY);
String forwardPattern = moduleConfig.getControllerConfig().getForwardPattern();
Any comments?
(and thanks for reading this insufferably long email... I just hate it when people don't do research and also don't post enough information)
-chris
signature.asc
Description: OpenPGP digital signature