A way to access resources of the Confluence web application from code not run under a servlet?

XMLWordPrintable

    • Type: Suggestion
    • Resolution: Obsolete
    • None
    • Component/s: None
    • Environment:
      Standalone installation on Resin Pro 3, JDK 1.5 under Linux/i686

      Hello,

      I'm trying to export spaces to HTML in a Quartz job. However, this fails when the exporter is gathering resources (images etc.) for the export. This is because resources are being retrieved using an instance of ServletContext but this is not available since the code is not run under a servlet. Here's the stack trace:

      2006-10-09 14:54:01,523 ERROR [elma.confluence.export.ExportAllSpacesJob] doExecute Exception while exporting: java.lang.NullPointerException
      java.lang.NullPointerException
      at com.atlassian.confluence.util.ServletContextThreadLocal.getContext(ServletContextThreadLocal.java:19)
      at com.atlassian.confluence.importexport.impl.AbstractRendererExporterImpl.copyExportedResource(AbstractRendererExporterImpl.java:212)
      at com.atlassian.confluence.importexport.impl.AbstractRendererExporterImpl.copyResources(AbstractRendererExporterImpl.java:184)
      at com.atlassian.confluence.importexport.impl.HtmlExporter.copyResources(HtmlExporter.java:222)
      at com.atlassian.confluence.importexport.impl.HtmlExporter.doExportEntity(HtmlExporter.java:211)
      at com.atlassian.confluence.importexport.impl.HtmlExporter.exportPage(HtmlExporter.java:101)
      at com.atlassian.confluence.importexport.impl.HtmlExporter.exportSpace(HtmlExporter.java:114)
      at com.atlassian.confluence.importexport.impl.AbstractRendererExporterImpl.doExport(AbstractRendererExporterImpl.java:102)
      at com.atlassian.confluence.importexport.impl.HtmlExporter.doExport(HtmlExporter.java:40)
      at com.atlassian.confluence.importexport.DefaultImportExportManager.exportAs(DefaultImportExportManager.java:113)
      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.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:61)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:149)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:116)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:56)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:152)
      at $Proxy35.exportAs(Unknown Source)
      at net.elma.confluence.export.ExportAllSpacesJob.doExecute(ExportAllSpacesJob.java:47)
      at bucket.event.jobs.AbstractJob.executeInternal(AbstractJob.java:91)
      at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:66)
      at org.quartz.core.JobRunShell.run(JobRunShell.java:191)
      at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:516)

      Maybe there should be another way to access the resources which doesn't involve ServletContext?

      Locally I solved the problem using a crude hack (attached as a patch against Confluence 2.2.9): I created a servlet which is loaded on startup. It saves its context to BootstrapManager as a property. This saved servlet context is then used if one is not available otherwise.

            Assignee:
            Unassigned
            Reporter:
            Tuomas Jormola
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: