Thomas, the wrong XWikiContext only occurs, when I use a ScriptService Implementation to inject it. If I start the Job from inside a Macro Implementation everything is fine. Regards, Stefan. Am 21.11.2014 10:53, schrieb Stefan Bernsdorf:
Am 21.11.2014 10:20, schrieb Thomas Mortagne:
On Fri, Nov 21, 2014 at 9:54 AM, Stefan Bernsdorf <[email protected]> wrote:
Am 21.11.2014 09:11, schrieb Thomas Mortagne:
On Fri, Nov 21, 2014 at 8:42 AM, Stefan Bernsdorf <[email protected]> wrote:
Thomas, it seems it has nothing to do with my context. I tried to initialize my context with the xcontextProvider. It failed again.
Instead I checked the source code of AbstractDataMigrationManager.getXWikiContext which is shown in the stack trace and it found this:
protected XWikiContext getXWikiContext() { ExecutionContext context = execution.getContext(); return (XWikiContext) context.getProperty("xwikicontext"); }
Seems that the Context is not injected properly when it runs in a job? Again as I told you the ExecutionContext is properly initialized but the XWikiContext is something else, the Provider among other things create and set a XWikiContext when there is none. Now what is wrong is that you end up in AbstractDataMigrationManager in your thread since its supposed to be called only the first time a request is done.
When do you start your job exactly ? Are you sure the database is ready when you do (it's not before the first access to the wi trough the browser) ? You can listen to org.xwiki.bridge.event.ApplicationReadyEvent to be notified when it's ok to use the database. The job is started from a macro class. So the wiki itself should be fully initialized.
There is something very weird in your stack trace, you clearly have a XWikiContext in the ExecutionContext as otherwise you would get a nullpointer in your own code before AbstractDataMigrationManager so what you have really does not make any sense to me. Without debugging I don't have much idea. Also the stack trace you have clearly indicate that this thread has been executed with in the XWikiContext a wiki that was not initialized.
Does mycon.getDatabase() contains what you expect ?
Yes. It contains xwiki as I expect.
Am 21.11.2014 07:49, schrieb Thomas Mortagne:
On Thu, Nov 20, 2014 at 10:45 PM, Stefan Bernsdorf <[email protected]> wrote: > Thomas, > thanks. I managed to build my thread as an XWiki Job and also > managed > to > add > it to the JobExecutor. > However, my initial problem still persists. > I am not able to add an attachment to a document in this job. > Find the stack trace below. Looking at the source of > XWikiHibernateBaseStore > tells me, it has something to do with the Execution context of > the Job, > but > this should be managed by the job executor, right? > This is my code snip to add the attachment: > XWikiContext mycon = (XWikiContext) > execution.getContext().getProperty("xwikicontext"); The ExecutionContext is initialized automatically but XWikiContext is something else and you should never try to get it directly from the ExecutionContext but use the provider instead as in:
@Inject private Provider<XWikiContext> xcontextProvider;
> XWikiDocument > doc=mycon.getWiki().getDocument(m_adoc, > mycon); > XWikiAttachment att=doc.getAttachment(m_file); > if (att!=null) { > doc.deleteAttachment(att,mycon); > att=null; > } > if (att==null) { > att=doc.addAttachment(m_file,ins ,mycon); > XWikiAttachmentStoreInterface > ai=doc.getAttachmentStore(mycon); > XWikiHibernateAttachmentStore > hib=(XWikiHibernateAttachmentStore)ai; > hib.beginTransaction(mycon); > ai.saveAttachmentContent(att, mycon, true); > hib.endTransaction(mycon,true); > att.updateContentArchive(mycon); > } > > > This is the stack trace: > com.xpn.xwiki.XWikiException: Error number 3301 in 3: Exception > while > switching to database xwiki > at > > > com.xpn.xwiki.store.XWikiHibernateBaseStore.setDatabase(XWikiHibernateBaseStore.java:739) > > ~[xwiki-platform-legacy-oldcore-6.2.1.jar:na] > at > > > com.xpn.xwiki.store.XWikiHibernateBaseStore.beginTransaction(XWikiHibernateBaseStore.java:911) > > ~[xwiki-platform-legacy-oldcore-6.2.1.jar:na] > at > > > com.xpn.xwiki.store.XWikiHibernateBaseStore.beginTransaction(XWikiHibernateBaseStore.java:811) > > ~[xwiki-platform-legacy-oldcore-6.2.1.jar:na] > at > org.centauron.xwiki.help.XWikiUpload.doCommand(XWikiUpload.java:68) > ~[centauron_xwiki.jar:na] > at > org.centauron.ant.TestScript.executeExtraData(TestScript.java:208) > ~[centauron_xwiki.jar:na] > at > org.centauron.ant.TestProcess.doPost(TestProcess.java:249) > ~[centauron_xwiki.jar:na] > at org.centauron.ant.TestProcess.start(TestProcess.java:228) > ~[centauron_xwiki.jar:na] > at > org.centauron.xwiki.job.XWikiAntJob.internalCall(XWikiAntJob.java:112) > > [centauron_xwiki.jar:na] > at > org.centauron.xwiki.job.XWikiAntJob.doStart(XWikiAntJob.java:98) > [centauron_xwiki.jar:na] > at > org.centauron.xwiki.job.XWikiAntJob.run(XWikiAntJob.java:41) > [centauron_xwiki.jar:na] > at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown > Source) > [na:1.8.0_05] > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown > Source) > [na:1.8.0_05] > at java.lang.Thread.run(Unknown Source) [na:1.8.0_05] > Caused by: java.lang.NullPointerException: null > at > > > com.xpn.xwiki.store.migration.AbstractDataMigrationManager.getXWikiContext(AbstractDataMigrationManager.java:282) > > ~[xwiki-platform-legacy-oldcore-6.2.1.jar:na] > at > > > com.xpn.xwiki.store.migration.AbstractDataMigrationManager.getDataMigrationStatus(AbstractDataMigrationManager.java:406) > > ~[xwiki-platform-legacy-oldcore-6.2.1.jar:na] > at > > > com.xpn.xwiki.store.migration.AbstractDataMigrationManager.getDatabaseStatus(AbstractDataMigrationManager.java:548) > > ~[xwiki-platform-legacy-oldcore-6.2.1.jar:na] > at > > > com.xpn.xwiki.store.migration.AbstractDataMigrationManager.checkDatabase(AbstractDataMigrationManager.java:516) > > ~[xwiki-platform-legacy-oldcore-6.2.1.jar:na] > at > > > com.xpn.xwiki.store.XWikiHibernateBaseStore.setDatabase(XWikiHibernateBaseStore.java:735) > > ~[xwiki-platform-legacy-oldcore-6.2.1.jar:na] > ... 12 common frames omitted > Am 20.11.2014 10:31, schrieb Thomas Mortagne: > >> Everything in XWiki is based on JobExecutor now so I can assure >> you it >> does not wait. Maybe your job is doing something slow in >> initialize. >> >> On Thu, Nov 20, 2014 at 10:24 AM, Stefan Bernsdorf >> <[email protected]> wrote: >>> Thomas, >>> if I start a job using >>> jobExecutor.execute("antjob", req); >>> it waits until the job is finished. >>> >>> Am 20.11.2014 09:44, schrieb Thomas Mortagne: >>> >>>> As indicated in the javadoc of JobExecutor all jobs are executed >>>> asychronously. You actually need to use Job#join when you >>>> want to >>>> wait. >>>> >>>> On Thu, Nov 20, 2014 at 9:38 AM, Stefan Bernsdorf >>>> <[email protected]> wrote: >>>>> Hi, >>>>> I have seen that the jobManager is deprecated since 6.1. >>>>> But how would I schedule a job and return immediately using the >>>>> jobExecutor? >>>>> (Using the jobManager it would be something like : >>>>> Job job = jobManager.addJob("jobtype", request)) >>>>> Thanks , Stefan. >>>>> _______________________________________________ >>>>> users mailing list >>>>> [email protected] >>>>> http://lists.xwiki.org/mailman/listinfo/users >>>> >>>> >>> _______________________________________________ >>> users mailing list >>> [email protected] >>> http://lists.xwiki.org/mailman/listinfo/users >> >> > _______________________________________________ > users mailing list > [email protected] > http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users