Problem with getSystemToken() returning NULL
PostPosted:Sat Nov 01, 2014 1:49 pm
I am trying to run an amended Simple Importer script (based on the one at http://wiki.openkm.com/index.php/Cronta ... e_importer).
The script runs fine when executed via the Cron screen in the web-gui via the alert/flash icon (my own debug/trace statements below cut from the log file)....
StdOut: =====AutoImport Script=====
Source folder = /media/data3/scanned/import
Token = null
Target okmPath = /okm:root/2014
Folder = com.openkm.api.OKMFolder@c9ebe22
Target path exists already
Importing /media/data3/scanned/import/2014_10_26_08_52_50.pdf --> /okm:root/2014/2014_10_26_08_52_50.pdf
Imported OK
...but fails when running automatically via the scheduler....
StdOut: =====AutoImport Script=====
Source folder = /media/data3/scanned/import
Token = null
Target okmPath = /okm:root/2014
Folder = com.openkm.api.OKMFolder@c9ebe22
Exception while testing target path
Exception in import : java.lang.NullPointerException<br>
...with the line in question being a call to createSimple() as below...
The script runs fine when executed via the Cron screen in the web-gui via the alert/flash icon (my own debug/trace statements below cut from the log file)....
StdOut: =====AutoImport Script=====
Source folder = /media/data3/scanned/import
Token = null
Target okmPath = /okm:root/2014
Folder = com.openkm.api.OKMFolder@c9ebe22
Target path exists already
Importing /media/data3/scanned/import/2014_10_26_08_52_50.pdf --> /okm:root/2014/2014_10_26_08_52_50.pdf
Imported OK
...but fails when running automatically via the scheduler....
StdOut: =====AutoImport Script=====
Source folder = /media/data3/scanned/import
Token = null
Target okmPath = /okm:root/2014
Folder = com.openkm.api.OKMFolder@c9ebe22
Exception while testing target path
Exception in import : java.lang.NullPointerException<br>
...with the line in question being a call to createSimple() as below...
Code: Select all
The script up to that point is....try {
print( "Folder = " + folder.toString() ) ;
folder.createSimple( token, okmPath ) ;
print( "Target path created" ) ;
}Code: Select all
I'm surprised that "Token" is always NULL...? Is this to be expected ? Why would there be a difference in behaviour between a manual execute of the script and an automatic one ?import com.openkm.core.*;
import com.openkm.api.*;
import java.io.*;
import com.openkm.module.db.stuff.DbSessionManager;
String token = DbSessionManager.getInstance().getSystemToken();
OKMDocument document = OKMDocument.getInstance();
OKMFolder folder = OKMFolder.getInstance();
public void autoImport(String okmRoot, File fldpath) {
String token = null ;
try {
print("=====AutoImport Script=====");
print("Source folder = " + fldpath.toString() );
print("Token = " + token ) ;
// construct target path and create if needed
Calendar now = Calendar.getInstance();
String year = String.valueOf(now.get(Calendar.YEAR));
okmPath = okmRoot + "/" + year ;
print( "Target okmPath = " + okmPath ) ;
try {
print( "Folder = " + folder.toString() ) ;
folder.createSimple( token, okmPath ) ;
print( "Target path created" ) ;
}
}
}