• Problem with getSystemToken() returning NULL

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #30413  by abiggin
 
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...
Code: Select all
try {
  print( "Folder = " + folder.toString() ) ;
  folder.createSimple( token, okmPath ) ;
  print( "Target path created" ) ;
}
The script up to that point is....
Code: Select all
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" ) ;
		}
	}
}
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 ?
 #30418  by jllort
 
Look your code:
Code: Select all
String token = DbSessionManager.getInstance().getSystemToken();
OKMDocument document = OKMDocument.getInstance();
OKMFolder folder = OKMFolder.getInstance();

public void autoImport(String okmRoot, File fldpath){

String token = null ;
First you initialize with systemToken and then you set as null, remove the last String token=null.
 #30443  by abiggin
 
I have removed that, and now see a valid token string, but still the NULL ptr exception now happens on both a manual run, and a scheduled run... (before at least the manual run via the Execute button was working...)....

StdOut: =====AutoImport Script=====
Source folder = /media/data3/scanned/import
Token = 8740f900-99a1-4f87-90f6-f97d210c1f43
Target okmPath = /okm:root/2014
Folder = com.openkm.api.OKMFolder@c9ebe22
Exception while testing target path
Exception in import : java.lang.NullPointerException<br>

Code is...
Code: Select all
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){

	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" ) ;
		}
		catch( ItemExistsException iee )
		{
			print( "Target path exists already" ) ;	
		}
		catch( Exception ex ) 
		{
			print( "Exception while testing target path" ) ;
			throw( ex ) ;
		}
 #30473  by jllort
 
Better if we see the complete stack trace error in catalina.log
I do not see anything strange now in the code, seems right.
I suggest test if path exist or not before creation (OKMRepository.getInstance().hasNode(XXXXX))
 #30486  by abiggin
 
Here's the log output from the moment I manually execute the script from the Admin console using the "flash" (lightening) icon....
Code: Select all
abiggin@ubuntu:/opt/tomcat-7.0.27/logs$ tail -0lf catalina.log
2014-11-08 12:53:14,598 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - ***************************
2014-11-08 12:53:14,598 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - ***************************
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - com.openkm.module.db.stuff.SecurityHelper -> checkRead (SecurityHelper.java:104)
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - com.openkm.dao.NodeFolderDAO -> findByPk (NodeFolderDAO.java:195)
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - com.openkm.module.db.DbFolderModule -> create (DbFolderModule.java:85)
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - com.openkm.api.OKMFolder -> createSimple (OKMFolder.java:74)
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - com.openkm.util.ExecutionUtils -> runScript (ExecutionUtils.java:112)
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - com.openkm.core.Cron$RunnerBsh -> run (Cron.java:103)
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - com.openkm.servlet.admin.CronTabServlet -> execute (CronTabServlet.java:227)
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - com.openkm.servlet.admin.CronTabServlet -> doGet (CronTabServlet.java:115)
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - com.openkm.servlet.admin.CronTabServlet -> service (CronTabServlet.java:71)
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - ***************************
2014-11-08 12:53:14,599 [http-bio-0.0.0.0-8050-exec-4] INFO  com.openkm.module.db.stuff.DbSimpleAccessManager - ***************************
2014-11-08 12:53:14,603 [http-bio-0.0.0.0-8050-exec-4] WARN  com.openkm.core.Cron - Crontab task mail content is empty: Return: null
StdOut: =====AutoImport Script=====
Source folder = /media/data3/scanned/import
Token = 8740f900-99a1-4f87-90f6-f97d210c1f43
Target okmPath = /okm:root/2014
Folder = com.openkm.api.OKMFolder@c9ebe22
Exception while testing target path
Exception in import : java.lang.NullPointerException<br>

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.