On 4 Aug 2008, at 13:24, Reinhard Pötz wrote:
Reinhard Pötz wrote:Robin Wyles wrote:Hi,I have a component in my app that uses SourceResolver to create a ServletSource. When I call this component from within a pipeline, e.g. from flow or from a sitemap component all works well. However, when I call this method from a cron job I get the following NPE:java.lang.NullPointerExceptionat org.apache.cocoon.callstack.environment.CallFrameHelper.getContext (CallFrameHelper.java:75) at org.apache.cocoon.servletservice.CallStackHelper.getCurrentServletCo ntext(CallStackHelper.java:112) at org.apache.cocoon.servletservice.components.ServletSource.createServ letConnection(ServletSource.java:125)<snip/>The root problem seems to be that the CallStack is empty and so the the current ServletContext cannot be obtained using CallStackHelper.getCurrentServletContext().IMO no. From a quick glance at the code I think it needs to be more defensive in terms of catching NPEs. In the case that there is no existing call frame, null should be returned. Grzegorz, what do you think?Am I doing anything wrong?I've just committed a fix for this (revision 682356) so that *absolute* servlet URLs *should* work. (It can never work for self- referenced servlet URLs or relative servlet URLs without an existing servlet service request.)
Many thanks for committing this so quickly Reinhard... Ok, so testing with an absolute servlet URL (servlet:james-publisher+:/my/ matcher) I now get:
java.lang.IllegalArgumentException: ServletContext must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at
org.springframework.web.context.support.WebApplicationContextUtils.getWe
bApplicationContext(WebApplicationContextUtils.java:63)
at
org.springframework.web.context.support.WebApplicationContextUtils.getRe
quiredWebApplicationContext(WebApplicationContextUtils.java:93)
at org.apache.cocoon.servletservice.AbsoluteServletConnection.<init>
(AbsoluteServletConnection.java:56)
at
org.apache.cocoon.servletservice.components.ServletSource.createServletC
onnection(ServletSource.java:151)
at org.apache.cocoon.servletservice.components.ServletSource.<init>
(ServletSource.java:73)
at
org.apache.cocoon.servletservice.components.ServletSourceFactory.getSour
ce(ServletSourceFactory.java:74)
at
org.apache.cocoon.components.source.CocoonSourceResolver.resolveURI
(CocoonSourceResolver.java:153)
at
org.apache.cocoon.components.source.CocoonSourceResolver.resolveURI
(CocoonSourceResolver.java:183)
at com.jac.james.publisher.Publisher.publishFeed(Publisher.java:301)
at com.jac.james.publisher.Publisher.schedulePublishFeed
(Publisher.java:385)
at com.jac.james.publisher.Publisher.refreshPublishJobs
(Publisher.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:
276)
at
org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean
$MethodInvokingJob.executeInternal
(MethodInvokingJobDetailFactoryBean.java:260)
at org.springframework.scheduling.quartz.QuartzJobBean.execute
(QuartzJobBean.java:86)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run
(SimpleThreadPool.java:529)
Seems here that AbsoluteServletConnection tries to obtain the servlet context from CallStackHelper, which again of course relies on there being a call stack....
Any ideas?
Unfortunately I don't have a test case and currently no idea how I can provide a simple environment. This means that I'm not sure if there are other locations that have a problem if there is no existing servlet service requuest.Any ideas for a test environment?
Unfortunately not - I'm not sure how I can set up a SSF managed servlet inside a test...
Cheers, Robin
smime.p7s
Description: S/MIME cryptographic signature
