We have a problem with Velocity 1.4 and are a little (read: a lot)
baffled by it. Could someone help out?
The error we encountered is: (Long stacktrace version, see [1])
Feb 16, 2007 1:37:04 PM CET> <Error> <HTTP> <BEA-101017>
<[ServletContext(id=22140619,name=autoportaal-web-0.4.19-SNAPSHOT,context-path=/autoportaal)]
Root cause of ServletException.
<java.lang.Exception: Template.merge() failure. The document is null, most
likely due to parsing error.
< at org.apache.velocity.Template.merge(Template.java:277)
< at
org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:450)
< at
org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:419)
< at
nl.anwb.autoportaal.web.servlet.CmsDecoratorServlet.handleRequestInternal(CmsDecoratorServlet.java:50)
Our setup is jdk 1.4.2_05 and weblogic 8.1. The template is read by our
own URLResourceLoader, see [2] for whole code:
/** [EMAIL PROTECTED] */
public synchronized InputStream getResourceStream(final String url)
throws ResourceNotFoundException {
log.info("Retrieving Resource: " + url);
try {
String template = urlGrabber.getURL(url);
if (environment != null && (environment.indexOf(DEVELOPMENT)
!= -1
|| environment.indexOf(TEST) != -1)) {
template = prefixHtmlParts("http://www.anwb.nl", template);
}
template = StringUtils.replace(template, "<!--
[[app_autogids]] -->", "$snelzoek");
template = StringUtils.replace(template, "<!--
[[app_autokoers]] -->", "$autokoers");
template = template.replaceAll("<!-- \\[\\[app.*\\]\\] -->",
"\\$app");
template = StringUtils.replace(template, "<!-- [[html_head]]
-->", "$head");
lastTimes.put(url, new Long(System.currentTimeMillis()));
// .wlnotdelete
// Due to unexplained behaviour of ANWB production machine
this statement
// is needed to deliver complete HTML pages.
log.debug("After $head" + template + "[After $head]");
// end .wlnotdelete
return new ByteArrayInputStream(template.getBytes("UTF-8"));
} catch (FileNotFoundException e) {
log.error("Error retrieving:", e);
String msg = "URLResourceLoader : " + e;
rsvc.error(msg);
throw new ResourceNotFoundException(msg);
} catch (UnsupportedEncodingException e) {
log.error("Error retrieving:", e);
String msg = "URLResourceLoader : " + e;
rsvc.error(msg);
throw new ResourceNotFoundException(msg);
}
}
Does someone has a clue in which direction we have to search?
With regards,
Nick Stolwijk
[1]
Feb 16, 2007 1:37:04 PM CET> <Error> <HTTP> <BEA-101017>
<[ServletContext(id=22140619,name=autoportaal-web-0.4.19-SNAPSHOT,context-path=/autoportaal)]
Root cause of ServletException.
<java.lang.Exception: Template.merge() failure. The document is null, most
likely due to parsing error.
< at org.apache.velocity.Template.merge(Template.java:277)
< at
org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:450)
< at
org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:419)
< at
nl.anwb.autoportaal.web.servlet.CmsDecoratorServlet.handleRequestInternal(CmsDecoratorServlet.java:50)
< at
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
< at
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45)
< at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:820)
< at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:755)
< at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
< at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
< at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
< at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
< at
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
< at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
< at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
< at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
< at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
< at
org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:97)
< at
org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
< at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
< at
org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
< at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
< at
org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:217)
< at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
< at
org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:129)
< at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
< at
org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
< at
org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:90)
< at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
< at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:72)
< at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
< at
weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:644)
< at
weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImpl.java:423)
< at
com.opensymphony.module.sitemesh.filter.PageFilter.writeDecorator(PageFilter.java:173)
< at
com.opensymphony.module.sitemesh.filter.PageFilter.applyDecorator(PageFilter.java:158)
< at
com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:62)
< at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
< at
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
< at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
< at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
< at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
< at
org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
< at
org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
< at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
< at
org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
< at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
< at
org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:217)
< at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
< at
org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:191)
< at
org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
< at
org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
< at
org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:90)
< at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
< at
org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:61)
< at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
< at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
< at
nl.anwb.autoportaal.web.filters.SessionExpireFilter.doFilter(SessionExpireFilter.java:74)
< at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27)
< at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6724)
< at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
< at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
< at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
< at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
< at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
< at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
<>
[2]
public class URLResourceLoader extends ResourceLoader {
private static final Log log =
LogFactory.getLog(URLResourceLoader.class);
public static final int MINUTES = 60 * 1000;
public static final int DEFAULT_CACHE_TIME = 30 * 60 * 1000; // 30 mins.
private int cacheTime = DEFAULT_CACHE_TIME;
private static final String DEVELOPMENT = "development";
private static final String TEST = "test";
private String environment;
private URLGrabber urlGrabber;
private Map lastTimes = new HashMap();
/** [EMAIL PROTECTED] */
public void init(final ExtendedProperties configuration) {
rsvc.info("URLResourceLoader : initialization complete.");
environment = (String) rsvc.getProperty("environment");
String configuredCacheTime = (String)
rsvc.getProperty("templateCacheTime");
if (configuredCacheTime != null) {
cacheTime = Integer.parseInt(configuredCacheTime) * MINUTES;
}
}
/** [EMAIL PROTECTED] */
public synchronized InputStream getResourceStream(final String url)
throws ResourceNotFoundException {
log.info("Retrieving Resource: " + url);
try {
String template = urlGrabber.getURL(url);
if (environment != null && (environment.indexOf(DEVELOPMENT)
!= -1
|| environment.indexOf(TEST) != -1)) {
template = prefixHtmlParts("http://www.anwb.nl", template);
}
template = StringUtils.replace(template, "<!--
[[app_autogids]] -->", "$snelzoek");
template = StringUtils.replace(template, "<!--
[[app_autokoers]] -->", "$autokoers");
template = template.replaceAll("<!-- \\[\\[app.*\\]\\] -->",
"\\$app");
template = StringUtils.replace(template, "<!-- [[html_head]]
-->", "$head");
lastTimes.put(url, new Long(System.currentTimeMillis()));
// .wlnotdelete
// Due to unexplained behaviour of ANWB production machine
this statement
// is needed to deliver complete HTML pages.
log.debug("After $head" + template + "[After $head]");
// end .wlnotdelete
return new ByteArrayInputStream(template.getBytes("UTF-8"));
} catch (FileNotFoundException e) {
log.error("Error retrieving:", e);
String msg = "URLResourceLoader : " + e;
rsvc.error(msg);
throw new ResourceNotFoundException(msg);
} catch (UnsupportedEncodingException e) {
log.error("Error retrieving:", e);
String msg = "URLResourceLoader : " + e;
rsvc.error(msg);
throw new ResourceNotFoundException(msg);
}
}
/** [EMAIL PROTECTED] */
public boolean isSourceModified(final Resource resource) {
boolean returnValue = true;
Long lastTime = (Long) lastTimes.get(resource.getName());
if (cacheTime != -1 && lastTime != null) {
returnValue = System.currentTimeMillis() >
lastTime.longValue() + cacheTime;
}
return returnValue;
}
/** [EMAIL PROTECTED] */
public long getLastModified(final Resource resource) {
return 0;
}
/**
* Is set by an aspectj aspect.
*
* @see URLResourceLoaderAspect
* @param urlGrabber
* the urlGrabber to set
*/
public void setUrlGrabber(final URLGrabber urlGrabber) {
this.urlGrabber = urlGrabber;
}
/**
* @param strPrefix
* prefix
* @param strHtml
* html
* @return prefix html
*/
private static String prefixHtmlParts(final String strPrefix,
final String strHtml) {
String strResult = strHtml;
strResult = StringFunctions.replace(strResult,
"href=\"/autoportaal",
"link_naar_autoportaal");
strResult = StringFunctions.replace(strResult, "url(/", "url("
+ strPrefix + "/");
strResult = StringFunctions.replace(strResult, "src=\"/", "src=\""
+ strPrefix + "/");
strResult = StringFunctions.replace(strResult, "src='/", "src='"
+ strPrefix + "/");
strResult = StringFunctions.replace(strResult, "href=\"/", "href=\""
+ strPrefix + "/");
strResult = StringFunctions.replace(strResult, "href='/", "href='"
+ strPrefix + "/");
strResult = StringFunctions.replace(strResult,
"<param name=\"movie\" value=\"/",
"<param name=\"movie\" value=\"" + strPrefix + "/");
strResult = StringFunctions.replace(strResult,
"link_naar_autoportaal",
"href=\"/autoportaal");
return strResult;
}
}
--
------------------------------------------------------------------------
IPROFS <http://www.iprofs.nl/>
Nick Stolwijk
Java-ontwikkelaar
Gebouw "De Houthof"
Claus Sluterweg 125
2012 WS Haarlem
M +31 (0)6 18 721 490
E [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
www.iprofs.nl <http://www.iprofs.nl/>
T +31 (0)23 547 6369
F +31 (0)23 547 6370
------------------------------------------------------------------------