Re: [xwiki-users] Not able to read attachments from server thread

2014-11-12 Thread Stefan Bernsdorf


Hi,

the Job Module looks promising,
however this is the stack:
CONTENT IS NUL!com.xpn.xwiki.XWikiException: Error number 3231 
in 3: Exc
eption while loading attachment myseedfile.dgn of document 
microtest_oto.Templates_Test-Stefan
at 
com.xpn.xwiki.store.XWikiHibernateAttachmentStore.loadAttachmentContent(XWikiHibernateAttachmentStore.java:233)
at 
com.xpn.xwiki.doc.XWikiDocument.loadAttachmentContent(XWikiDocument.java:4600)
at 
com.xpn.xwiki.doc.XWikiAttachment.getContentInputStream(XWikiAttachment.java:576)
at 
org.centauron.xwiki.help.XWikiAttachmentCopy.doCommand(XWikiAttachmentCopy.java:79)
at 
org.centauron.ant.TestScript.executeExtraData(TestScript.java:208)

at org.centauron.ant.TestProcess.doPre(TestProcess.java:246)
at org.centauron.ant.TestProcess.start(TestProcess.java:212)
at 
org.centauron.ant.TestProcesses.startNextProcess(TestProcesses.java:114)

at org.centauron.ant.TestProcesses.run(TestProcesses.java:54)
at java.lang.Thread.run(Unknown Source)
Caused by: 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)
at 
com.xpn.xwiki.store.XWikiHibernateBaseStore.beginTransaction(XWikiHibernateBaseStore.java:911)
at 
com.xpn.xwiki.store.XWikiHibernateBaseStore.beginTransaction(XWikiHibernateBaseStore.java:826)
at 
com.xpn.xwiki.store.XWikiHibernateAttachmentStore.loadAttachmentContent(XWikiHibernateAttachmentStore.java:207)

... 9 more
Caused by: java.lang.NullPointerException
at 
com.xpn.xwiki.store.migration.AbstractDataMigrationManager.getXWikiContext(AbstractDataMigrationManager.java:282)
at 
com.xpn.xwiki.store.migration.AbstractDataMigrationManager.getDataMigrationStatus(AbstractDataMigrationManager.java:406)
at 
com.xpn.xwiki.store.migration.AbstractDataMigrationManager.getDatabaseStatus(AbstractDataMigrationManager.java:548)
at 
com.xpn.xwiki.store.migration.AbstractDataMigrationManager.checkDatabase(AbstractDataMigrationManager.java:516)
at 
com.xpn.xwiki.store.XWikiHibernateBaseStore.setDatabase(XWikiHibernateBaseStore.java:735)

... 12 more

Am 12.11.2014 13:45, schrieb Thomas Mortagne:

Could you copy the complete error, you should have a more detailed cause.

On Wed, Nov 12, 2014 at 11:39 AM, Stefan Bernsdorf
gruener.heinr...@web.de wrote:

Hi,
I created a Macro in xwiki.
In this macro a server process is started that tries to read attachments.
For this, I created a XWikiCOntext to access the Wiki.
This is the code:
 XWikiStubContextProvider
prov=Utils.getComponent(XWikiStubContextProvider.class);
 prov.initialize(template);
 XWikiContext con=prov.createStubContext();
 con.setUser(XWiki.TestProcess, true);
 con.setVirtual(true);

Unfortunately it is not possible to access the attachment content using this
context.
The following error is thrown:
com.xpn.xwiki.XWikiException: Error number 3231 in 3: Exception while
loading attachment myseedfile.dgn of document
microtest_oto.Templates_Test-Stefan
 at
com.xpn.xwiki.store.XWikiHibernateAttachmentStore.loadAttachmentContent(XWikiHibernateAttachmentStore.java:233)
 at
com.xpn.xwiki.doc.XWikiDocument.loadAttachmentContent(XWikiDocument.java:4600)
 at
com.xpn.xwiki.doc.XWikiAttachment.getContentInputStream(XWikiAttachment.java:576)
 at
org.centauron.xwiki.help.XWikiAttachmentCopy.doCommand(XWikiAttachmentCopy.java:79)
 

Any help would be appreciated.
Regards, Stefan.

___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users






___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


[xwiki-users] How to get The jobExecutor

2014-11-15 Thread Stefan Bernsdorf

Hi,
I wanted to use the snip from page 
http://extensions.xwiki.org/xwiki/bin/view/Extension/Job+Module



   Request jobRequest = new DefaultRequest();

   // Indicate an id to allow you to access the status of this
   unique task, the id is required to save/retrieve the status of
   the job
   jobRequest.setId(taskid);
   // Allow the job to ask questions during its executing (false by
   default)
   jobRequest.setInteractive(true);
   // [since 5.4] Indicate if the job should log informations about
   what is going on (to display it during the process for example,
   true by default)
   jobRequest.setVerbose(true);
   // Put some custom configuration
   jobRequest.setProperty(some custom jobtype related parameter,
   value);

   // Lookup and execute Job with role hint jobtype and wait for
   it to be finished
   jobManager.executeJob(jobtype, request)

   // Lookup and add Job with role hint jobtype to the queue
   queue and return right away
   Job job = jobManager.addJob(jobtype, request)

   // Wait until the job is finished
   job.join()

..
to be able to create my own job and job request. But how is the 
jobManager injected? When I use the snip, the

the jobManager is null.
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


[xwiki-users] JobManager vs JobExecutor

2014-11-20 Thread Stefan Bernsdorf

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
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] JobManager vs JobExecutor

2014-11-20 Thread Stefan Bernsdorf


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
gruener.heinr...@web.de 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
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users






___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] JobManager vs JobExecutor

2014-11-20 Thread Stefan Bernsdorf


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);

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
gruener.heinr...@web.de 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
gruener.heinr...@web.de 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
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users





___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users






___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] JobManager vs JobExecutor

2014-11-20 Thread Stefan Bernsdorf

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?


Am 21.11.2014 07:49, schrieb Thomas Mortagne:

On Thu, Nov 20, 2014 at 10:45 PM, Stefan Bernsdorf
gruener.heinr...@web.de 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 ProviderXWikiContext 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
gruener.heinr...@web.de 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

Re: [xwiki-users] JobManager vs JobExecutor

2014-11-21 Thread Stefan Bernsdorf


Am 21.11.2014 09:11, schrieb Thomas Mortagne:

On Fri, Nov 21, 2014 at 8:42 AM, Stefan Bernsdorf
gruener.heinr...@web.de 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.






Am 21.11.2014 07:49, schrieb Thomas Mortagne:


On Thu, Nov 20, 2014 at 10:45 PM, Stefan Bernsdorf
gruener.heinr...@web.de 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 ProviderXWikiContext 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

Re: [xwiki-users] JobManager vs JobExecutor

2014-11-21 Thread Stefan Bernsdorf


Am 21.11.2014 10:20, schrieb Thomas Mortagne:

On Fri, Nov 21, 2014 at 9:54 AM, Stefan Bernsdorf
gruener.heinr...@web.de wrote:

Am 21.11.2014 09:11, schrieb Thomas Mortagne:

On Fri, Nov 21, 2014 at 8:42 AM, Stefan Bernsdorf
gruener.heinr...@web.de 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
gruener.heinr...@web.de 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 ProviderXWikiContext 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

Re: [xwiki-users] JobManager vs JobExecutor

2014-11-22 Thread Stefan Bernsdorf


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
gruener.heinr...@web.de wrote:

Am 21.11.2014 09:11, schrieb Thomas Mortagne:

On Fri, Nov 21, 2014 at 8:42 AM, Stefan Bernsdorf
gruener.heinr...@web.de 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
gruener.heinr...@web.de 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 ProviderXWikiContext 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

Re: [xwiki-users] JobManager vs JobExecutor

2014-11-22 Thread Stefan Bernsdorf


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
gruener.heinr...@web.de wrote:

Am 21.11.2014 09:11, schrieb Thomas Mortagne:

On Fri, Nov 21, 2014 at 8:42 AM, Stefan Bernsdorf
gruener.heinr...@web.de 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
gruener.heinr...@web.de 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 ProviderXWikiContext 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